init.c 106 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655
  1. /* $XFree86$ */
  2. /* $XdotOrg$ */
  3. /*
  4. * Mode initializing code (CRT1 section) for
  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 Volari 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. #include "init.h"
  59. #ifdef CONFIG_FB_SIS_300
  60. #include "300vtbl.h"
  61. #endif
  62. #ifdef CONFIG_FB_SIS_315
  63. #include "310vtbl.h"
  64. #endif
  65. #if defined(ALLOC_PRAGMA)
  66. #pragma alloc_text(PAGE,SiSSetMode)
  67. #endif
  68. /*********************************************/
  69. /* POINTER INITIALIZATION */
  70. /*********************************************/
  71. #if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315)
  72. static void
  73. InitCommonPointer(struct SiS_Private *SiS_Pr)
  74. {
  75. SiS_Pr->SiS_SModeIDTable = SiS_SModeIDTable;
  76. SiS_Pr->SiS_StResInfo = SiS_StResInfo;
  77. SiS_Pr->SiS_ModeResInfo = SiS_ModeResInfo;
  78. SiS_Pr->SiS_StandTable = SiS_StandTable;
  79. SiS_Pr->SiS_NTSCTiming = SiS_NTSCTiming;
  80. SiS_Pr->SiS_PALTiming = SiS_PALTiming;
  81. SiS_Pr->SiS_HiTVSt1Timing = SiS_HiTVSt1Timing;
  82. SiS_Pr->SiS_HiTVSt2Timing = SiS_HiTVSt2Timing;
  83. SiS_Pr->SiS_HiTVExtTiming = SiS_HiTVExtTiming;
  84. SiS_Pr->SiS_HiTVGroup3Data = SiS_HiTVGroup3Data;
  85. SiS_Pr->SiS_HiTVGroup3Simu = SiS_HiTVGroup3Simu;
  86. #if 0
  87. SiS_Pr->SiS_HiTVTextTiming = SiS_HiTVTextTiming;
  88. SiS_Pr->SiS_HiTVGroup3Text = SiS_HiTVGroup3Text;
  89. #endif
  90. SiS_Pr->SiS_StPALData = SiS_StPALData;
  91. SiS_Pr->SiS_ExtPALData = SiS_ExtPALData;
  92. SiS_Pr->SiS_StNTSCData = SiS_StNTSCData;
  93. SiS_Pr->SiS_ExtNTSCData = SiS_ExtNTSCData;
  94. SiS_Pr->SiS_St1HiTVData = SiS_StHiTVData;
  95. SiS_Pr->SiS_St2HiTVData = SiS_St2HiTVData;
  96. SiS_Pr->SiS_ExtHiTVData = SiS_ExtHiTVData;
  97. SiS_Pr->SiS_St525iData = SiS_StNTSCData;
  98. SiS_Pr->SiS_St525pData = SiS_St525pData;
  99. SiS_Pr->SiS_St750pData = SiS_St750pData;
  100. SiS_Pr->SiS_Ext525iData = SiS_ExtNTSCData;
  101. SiS_Pr->SiS_Ext525pData = SiS_ExtNTSCData;
  102. SiS_Pr->SiS_Ext750pData = SiS_Ext750pData;
  103. SiS_Pr->pSiS_OutputSelect = &SiS_OutputSelect;
  104. SiS_Pr->pSiS_SoftSetting = &SiS_SoftSetting;
  105. SiS_Pr->SiS_LCD1280x720Data = SiS_LCD1280x720Data;
  106. SiS_Pr->SiS_StLCD1280x768_2Data = SiS_StLCD1280x768_2Data;
  107. SiS_Pr->SiS_ExtLCD1280x768_2Data = SiS_ExtLCD1280x768_2Data;
  108. SiS_Pr->SiS_LCD1280x800Data = SiS_LCD1280x800Data;
  109. SiS_Pr->SiS_LCD1280x800_2Data = SiS_LCD1280x800_2Data;
  110. SiS_Pr->SiS_LCD1280x854Data = SiS_LCD1280x854Data;
  111. SiS_Pr->SiS_LCD1280x960Data = SiS_LCD1280x960Data;
  112. SiS_Pr->SiS_StLCD1400x1050Data = SiS_StLCD1400x1050Data;
  113. SiS_Pr->SiS_ExtLCD1400x1050Data = SiS_ExtLCD1400x1050Data;
  114. SiS_Pr->SiS_LCD1680x1050Data = SiS_LCD1680x1050Data;
  115. SiS_Pr->SiS_StLCD1600x1200Data = SiS_StLCD1600x1200Data;
  116. SiS_Pr->SiS_ExtLCD1600x1200Data = SiS_ExtLCD1600x1200Data;
  117. SiS_Pr->SiS_NoScaleData = SiS_NoScaleData;
  118. SiS_Pr->SiS_LVDS320x240Data_1 = SiS_LVDS320x240Data_1;
  119. SiS_Pr->SiS_LVDS320x240Data_2 = SiS_LVDS320x240Data_2;
  120. SiS_Pr->SiS_LVDS640x480Data_1 = SiS_LVDS640x480Data_1;
  121. SiS_Pr->SiS_LVDS800x600Data_1 = SiS_LVDS800x600Data_1;
  122. SiS_Pr->SiS_LVDS1024x600Data_1 = SiS_LVDS1024x600Data_1;
  123. SiS_Pr->SiS_LVDS1024x768Data_1 = SiS_LVDS1024x768Data_1;
  124. SiS_Pr->SiS_LVDSCRT1320x240_1 = SiS_LVDSCRT1320x240_1;
  125. SiS_Pr->SiS_LVDSCRT1320x240_2 = SiS_LVDSCRT1320x240_2;
  126. SiS_Pr->SiS_LVDSCRT1320x240_2_H = SiS_LVDSCRT1320x240_2_H;
  127. SiS_Pr->SiS_LVDSCRT1320x240_3 = SiS_LVDSCRT1320x240_3;
  128. SiS_Pr->SiS_LVDSCRT1320x240_3_H = SiS_LVDSCRT1320x240_3_H;
  129. SiS_Pr->SiS_LVDSCRT1640x480_1 = SiS_LVDSCRT1640x480_1;
  130. SiS_Pr->SiS_LVDSCRT1640x480_1_H = SiS_LVDSCRT1640x480_1_H;
  131. #if 0
  132. SiS_Pr->SiS_LVDSCRT11024x600_1 = SiS_LVDSCRT11024x600_1;
  133. SiS_Pr->SiS_LVDSCRT11024x600_1_H = SiS_LVDSCRT11024x600_1_H;
  134. SiS_Pr->SiS_LVDSCRT11024x600_2 = SiS_LVDSCRT11024x600_2;
  135. SiS_Pr->SiS_LVDSCRT11024x600_2_H = SiS_LVDSCRT11024x600_2_H;
  136. #endif
  137. SiS_Pr->SiS_CHTVUNTSCData = SiS_CHTVUNTSCData;
  138. SiS_Pr->SiS_CHTVONTSCData = SiS_CHTVONTSCData;
  139. SiS_Pr->SiS_PanelMinLVDS = Panel_800x600; /* lowest value LVDS/LCDA */
  140. SiS_Pr->SiS_PanelMin301 = Panel_1024x768; /* lowest value 301 */
  141. }
  142. #endif
  143. #ifdef CONFIG_FB_SIS_300
  144. static void
  145. InitTo300Pointer(struct SiS_Private *SiS_Pr)
  146. {
  147. InitCommonPointer(SiS_Pr);
  148. SiS_Pr->SiS_VBModeIDTable = SiS300_VBModeIDTable;
  149. SiS_Pr->SiS_EModeIDTable = SiS300_EModeIDTable;
  150. SiS_Pr->SiS_RefIndex = SiS300_RefIndex;
  151. SiS_Pr->SiS_CRT1Table = SiS300_CRT1Table;
  152. if(SiS_Pr->ChipType == SIS_300) {
  153. SiS_Pr->SiS_MCLKData_0 = SiS300_MCLKData_300; /* 300 */
  154. } else {
  155. SiS_Pr->SiS_MCLKData_0 = SiS300_MCLKData_630; /* 630, 730 */
  156. }
  157. SiS_Pr->SiS_VCLKData = SiS300_VCLKData;
  158. SiS_Pr->SiS_VBVCLKData = (struct SiS_VBVCLKData *)SiS300_VCLKData;
  159. SiS_Pr->SiS_SR15 = SiS300_SR15;
  160. SiS_Pr->SiS_PanelDelayTbl = SiS300_PanelDelayTbl;
  161. SiS_Pr->SiS_PanelDelayTblLVDS = SiS300_PanelDelayTbl;
  162. SiS_Pr->SiS_ExtLCD1024x768Data = SiS300_ExtLCD1024x768Data;
  163. SiS_Pr->SiS_St2LCD1024x768Data = SiS300_St2LCD1024x768Data;
  164. SiS_Pr->SiS_ExtLCD1280x1024Data = SiS300_ExtLCD1280x1024Data;
  165. SiS_Pr->SiS_St2LCD1280x1024Data = SiS300_St2LCD1280x1024Data;
  166. SiS_Pr->SiS_CRT2Part2_1024x768_1 = SiS300_CRT2Part2_1024x768_1;
  167. SiS_Pr->SiS_CRT2Part2_1024x768_2 = SiS300_CRT2Part2_1024x768_2;
  168. SiS_Pr->SiS_CRT2Part2_1024x768_3 = SiS300_CRT2Part2_1024x768_3;
  169. SiS_Pr->SiS_CHTVUPALData = SiS300_CHTVUPALData;
  170. SiS_Pr->SiS_CHTVOPALData = SiS300_CHTVOPALData;
  171. SiS_Pr->SiS_CHTVUPALMData = SiS_CHTVUNTSCData; /* not supported on 300 series */
  172. SiS_Pr->SiS_CHTVOPALMData = SiS_CHTVONTSCData; /* not supported on 300 series */
  173. SiS_Pr->SiS_CHTVUPALNData = SiS300_CHTVUPALData; /* not supported on 300 series */
  174. SiS_Pr->SiS_CHTVOPALNData = SiS300_CHTVOPALData; /* not supported on 300 series */
  175. SiS_Pr->SiS_CHTVSOPALData = SiS300_CHTVSOPALData;
  176. SiS_Pr->SiS_LVDS848x480Data_1 = SiS300_LVDS848x480Data_1;
  177. SiS_Pr->SiS_LVDS848x480Data_2 = SiS300_LVDS848x480Data_2;
  178. SiS_Pr->SiS_LVDSBARCO1024Data_1 = SiS300_LVDSBARCO1024Data_1;
  179. SiS_Pr->SiS_LVDSBARCO1366Data_1 = SiS300_LVDSBARCO1366Data_1;
  180. SiS_Pr->SiS_LVDSBARCO1366Data_2 = SiS300_LVDSBARCO1366Data_2;
  181. SiS_Pr->SiS_PanelType04_1a = SiS300_PanelType04_1a;
  182. SiS_Pr->SiS_PanelType04_2a = SiS300_PanelType04_2a;
  183. SiS_Pr->SiS_PanelType04_1b = SiS300_PanelType04_1b;
  184. SiS_Pr->SiS_PanelType04_2b = SiS300_PanelType04_2b;
  185. SiS_Pr->SiS_CHTVCRT1UNTSC = SiS300_CHTVCRT1UNTSC;
  186. SiS_Pr->SiS_CHTVCRT1ONTSC = SiS300_CHTVCRT1ONTSC;
  187. SiS_Pr->SiS_CHTVCRT1UPAL = SiS300_CHTVCRT1UPAL;
  188. SiS_Pr->SiS_CHTVCRT1OPAL = SiS300_CHTVCRT1OPAL;
  189. SiS_Pr->SiS_CHTVCRT1SOPAL = SiS300_CHTVCRT1SOPAL;
  190. SiS_Pr->SiS_CHTVReg_UNTSC = SiS300_CHTVReg_UNTSC;
  191. SiS_Pr->SiS_CHTVReg_ONTSC = SiS300_CHTVReg_ONTSC;
  192. SiS_Pr->SiS_CHTVReg_UPAL = SiS300_CHTVReg_UPAL;
  193. SiS_Pr->SiS_CHTVReg_OPAL = SiS300_CHTVReg_OPAL;
  194. SiS_Pr->SiS_CHTVReg_UPALM = SiS300_CHTVReg_UNTSC; /* not supported on 300 series */
  195. SiS_Pr->SiS_CHTVReg_OPALM = SiS300_CHTVReg_ONTSC; /* not supported on 300 series */
  196. SiS_Pr->SiS_CHTVReg_UPALN = SiS300_CHTVReg_UPAL; /* not supported on 300 series */
  197. SiS_Pr->SiS_CHTVReg_OPALN = SiS300_CHTVReg_OPAL; /* not supported on 300 series */
  198. SiS_Pr->SiS_CHTVReg_SOPAL = SiS300_CHTVReg_SOPAL;
  199. SiS_Pr->SiS_CHTVVCLKUNTSC = SiS300_CHTVVCLKUNTSC;
  200. SiS_Pr->SiS_CHTVVCLKONTSC = SiS300_CHTVVCLKONTSC;
  201. SiS_Pr->SiS_CHTVVCLKUPAL = SiS300_CHTVVCLKUPAL;
  202. SiS_Pr->SiS_CHTVVCLKOPAL = SiS300_CHTVVCLKOPAL;
  203. SiS_Pr->SiS_CHTVVCLKUPALM = SiS300_CHTVVCLKUNTSC; /* not supported on 300 series */
  204. SiS_Pr->SiS_CHTVVCLKOPALM = SiS300_CHTVVCLKONTSC; /* not supported on 300 series */
  205. SiS_Pr->SiS_CHTVVCLKUPALN = SiS300_CHTVVCLKUPAL; /* not supported on 300 series */
  206. SiS_Pr->SiS_CHTVVCLKOPALN = SiS300_CHTVVCLKOPAL; /* not supported on 300 series */
  207. SiS_Pr->SiS_CHTVVCLKSOPAL = SiS300_CHTVVCLKSOPAL;
  208. }
  209. #endif
  210. #ifdef CONFIG_FB_SIS_315
  211. static void
  212. InitTo310Pointer(struct SiS_Private *SiS_Pr)
  213. {
  214. InitCommonPointer(SiS_Pr);
  215. SiS_Pr->SiS_EModeIDTable = SiS310_EModeIDTable;
  216. SiS_Pr->SiS_RefIndex = SiS310_RefIndex;
  217. SiS_Pr->SiS_CRT1Table = SiS310_CRT1Table;
  218. if(SiS_Pr->ChipType >= SIS_340) {
  219. SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_340; /* 340 + XGI */
  220. } else if(SiS_Pr->ChipType >= SIS_761) {
  221. SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_761; /* 761 - preliminary */
  222. } else if(SiS_Pr->ChipType >= SIS_760) {
  223. SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_760; /* 760 */
  224. } else if(SiS_Pr->ChipType >= SIS_661) {
  225. SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_660; /* 661/741 */
  226. } else if(SiS_Pr->ChipType == SIS_330) {
  227. SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_330; /* 330 */
  228. } else if(SiS_Pr->ChipType > SIS_315PRO) {
  229. SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_650; /* 550, 650, 740 */
  230. } else {
  231. SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_315; /* 315 */
  232. }
  233. if(SiS_Pr->ChipType >= SIS_340) {
  234. SiS_Pr->SiS_MCLKData_1 = SiS310_MCLKData_1_340;
  235. } else {
  236. SiS_Pr->SiS_MCLKData_1 = SiS310_MCLKData_1;
  237. }
  238. SiS_Pr->SiS_VCLKData = SiS310_VCLKData;
  239. SiS_Pr->SiS_VBVCLKData = SiS310_VBVCLKData;
  240. SiS_Pr->SiS_SR15 = SiS310_SR15;
  241. SiS_Pr->SiS_PanelDelayTbl = SiS310_PanelDelayTbl;
  242. SiS_Pr->SiS_PanelDelayTblLVDS = SiS310_PanelDelayTblLVDS;
  243. SiS_Pr->SiS_St2LCD1024x768Data = SiS310_St2LCD1024x768Data;
  244. SiS_Pr->SiS_ExtLCD1024x768Data = SiS310_ExtLCD1024x768Data;
  245. SiS_Pr->SiS_St2LCD1280x1024Data = SiS310_St2LCD1280x1024Data;
  246. SiS_Pr->SiS_ExtLCD1280x1024Data = SiS310_ExtLCD1280x1024Data;
  247. SiS_Pr->SiS_CRT2Part2_1024x768_1 = SiS310_CRT2Part2_1024x768_1;
  248. SiS_Pr->SiS_CHTVUPALData = SiS310_CHTVUPALData;
  249. SiS_Pr->SiS_CHTVOPALData = SiS310_CHTVOPALData;
  250. SiS_Pr->SiS_CHTVUPALMData = SiS310_CHTVUPALMData;
  251. SiS_Pr->SiS_CHTVOPALMData = SiS310_CHTVOPALMData;
  252. SiS_Pr->SiS_CHTVUPALNData = SiS310_CHTVUPALNData;
  253. SiS_Pr->SiS_CHTVOPALNData = SiS310_CHTVOPALNData;
  254. SiS_Pr->SiS_CHTVSOPALData = SiS310_CHTVSOPALData;
  255. SiS_Pr->SiS_CHTVCRT1UNTSC = SiS310_CHTVCRT1UNTSC;
  256. SiS_Pr->SiS_CHTVCRT1ONTSC = SiS310_CHTVCRT1ONTSC;
  257. SiS_Pr->SiS_CHTVCRT1UPAL = SiS310_CHTVCRT1UPAL;
  258. SiS_Pr->SiS_CHTVCRT1OPAL = SiS310_CHTVCRT1OPAL;
  259. SiS_Pr->SiS_CHTVCRT1SOPAL = SiS310_CHTVCRT1OPAL;
  260. SiS_Pr->SiS_CHTVReg_UNTSC = SiS310_CHTVReg_UNTSC;
  261. SiS_Pr->SiS_CHTVReg_ONTSC = SiS310_CHTVReg_ONTSC;
  262. SiS_Pr->SiS_CHTVReg_UPAL = SiS310_CHTVReg_UPAL;
  263. SiS_Pr->SiS_CHTVReg_OPAL = SiS310_CHTVReg_OPAL;
  264. SiS_Pr->SiS_CHTVReg_UPALM = SiS310_CHTVReg_UPALM;
  265. SiS_Pr->SiS_CHTVReg_OPALM = SiS310_CHTVReg_OPALM;
  266. SiS_Pr->SiS_CHTVReg_UPALN = SiS310_CHTVReg_UPALN;
  267. SiS_Pr->SiS_CHTVReg_OPALN = SiS310_CHTVReg_OPALN;
  268. SiS_Pr->SiS_CHTVReg_SOPAL = SiS310_CHTVReg_OPAL;
  269. SiS_Pr->SiS_CHTVVCLKUNTSC = SiS310_CHTVVCLKUNTSC;
  270. SiS_Pr->SiS_CHTVVCLKONTSC = SiS310_CHTVVCLKONTSC;
  271. SiS_Pr->SiS_CHTVVCLKUPAL = SiS310_CHTVVCLKUPAL;
  272. SiS_Pr->SiS_CHTVVCLKOPAL = SiS310_CHTVVCLKOPAL;
  273. SiS_Pr->SiS_CHTVVCLKUPALM = SiS310_CHTVVCLKUPALM;
  274. SiS_Pr->SiS_CHTVVCLKOPALM = SiS310_CHTVVCLKOPALM;
  275. SiS_Pr->SiS_CHTVVCLKUPALN = SiS310_CHTVVCLKUPALN;
  276. SiS_Pr->SiS_CHTVVCLKOPALN = SiS310_CHTVVCLKOPALN;
  277. SiS_Pr->SiS_CHTVVCLKSOPAL = SiS310_CHTVVCLKOPAL;
  278. }
  279. #endif
  280. bool
  281. SiSInitPtr(struct SiS_Private *SiS_Pr)
  282. {
  283. if(SiS_Pr->ChipType < SIS_315H) {
  284. #ifdef CONFIG_FB_SIS_300
  285. InitTo300Pointer(SiS_Pr);
  286. #else
  287. return false;
  288. #endif
  289. } else {
  290. #ifdef CONFIG_FB_SIS_315
  291. InitTo310Pointer(SiS_Pr);
  292. #else
  293. return false;
  294. #endif
  295. }
  296. return true;
  297. }
  298. /*********************************************/
  299. /* HELPER: Get ModeID */
  300. /*********************************************/
  301. static
  302. unsigned short
  303. SiS_GetModeID(int VGAEngine, unsigned int VBFlags, int HDisplay, int VDisplay,
  304. int Depth, bool FSTN, int LCDwidth, int LCDheight)
  305. {
  306. unsigned short ModeIndex = 0;
  307. switch(HDisplay)
  308. {
  309. case 320:
  310. if(VDisplay == 200) ModeIndex = ModeIndex_320x200[Depth];
  311. else if(VDisplay == 240) {
  312. if((VBFlags & CRT2_LCD) && (FSTN))
  313. ModeIndex = ModeIndex_320x240_FSTN[Depth];
  314. else
  315. ModeIndex = ModeIndex_320x240[Depth];
  316. }
  317. break;
  318. case 400:
  319. if((!(VBFlags & CRT1_LCDA)) || ((LCDwidth >= 800) && (LCDwidth >= 600))) {
  320. if(VDisplay == 300) ModeIndex = ModeIndex_400x300[Depth];
  321. }
  322. break;
  323. case 512:
  324. if((!(VBFlags & CRT1_LCDA)) || ((LCDwidth >= 1024) && (LCDwidth >= 768))) {
  325. if(VDisplay == 384) ModeIndex = ModeIndex_512x384[Depth];
  326. }
  327. break;
  328. case 640:
  329. if(VDisplay == 480) ModeIndex = ModeIndex_640x480[Depth];
  330. else if(VDisplay == 400) ModeIndex = ModeIndex_640x400[Depth];
  331. break;
  332. case 720:
  333. if(VDisplay == 480) ModeIndex = ModeIndex_720x480[Depth];
  334. else if(VDisplay == 576) ModeIndex = ModeIndex_720x576[Depth];
  335. break;
  336. case 768:
  337. if(VDisplay == 576) ModeIndex = ModeIndex_768x576[Depth];
  338. break;
  339. case 800:
  340. if(VDisplay == 600) ModeIndex = ModeIndex_800x600[Depth];
  341. else if(VDisplay == 480) ModeIndex = ModeIndex_800x480[Depth];
  342. break;
  343. case 848:
  344. if(VDisplay == 480) ModeIndex = ModeIndex_848x480[Depth];
  345. break;
  346. case 856:
  347. if(VDisplay == 480) ModeIndex = ModeIndex_856x480[Depth];
  348. break;
  349. case 960:
  350. if(VGAEngine == SIS_315_VGA) {
  351. if(VDisplay == 540) ModeIndex = ModeIndex_960x540[Depth];
  352. else if(VDisplay == 600) ModeIndex = ModeIndex_960x600[Depth];
  353. }
  354. break;
  355. case 1024:
  356. if(VDisplay == 576) ModeIndex = ModeIndex_1024x576[Depth];
  357. else if(VDisplay == 768) ModeIndex = ModeIndex_1024x768[Depth];
  358. else if(VGAEngine == SIS_300_VGA) {
  359. if(VDisplay == 600) ModeIndex = ModeIndex_1024x600[Depth];
  360. }
  361. break;
  362. case 1152:
  363. if(VDisplay == 864) ModeIndex = ModeIndex_1152x864[Depth];
  364. if(VGAEngine == SIS_300_VGA) {
  365. if(VDisplay == 768) ModeIndex = ModeIndex_1152x768[Depth];
  366. }
  367. break;
  368. case 1280:
  369. switch(VDisplay) {
  370. case 720:
  371. ModeIndex = ModeIndex_1280x720[Depth];
  372. break;
  373. case 768:
  374. if(VGAEngine == SIS_300_VGA) {
  375. ModeIndex = ModeIndex_300_1280x768[Depth];
  376. } else {
  377. ModeIndex = ModeIndex_310_1280x768[Depth];
  378. }
  379. break;
  380. case 800:
  381. if(VGAEngine == SIS_315_VGA) {
  382. ModeIndex = ModeIndex_1280x800[Depth];
  383. }
  384. break;
  385. case 854:
  386. if(VGAEngine == SIS_315_VGA) {
  387. ModeIndex = ModeIndex_1280x854[Depth];
  388. }
  389. break;
  390. case 960:
  391. ModeIndex = ModeIndex_1280x960[Depth];
  392. break;
  393. case 1024:
  394. ModeIndex = ModeIndex_1280x1024[Depth];
  395. break;
  396. }
  397. break;
  398. case 1360:
  399. if(VDisplay == 768) ModeIndex = ModeIndex_1360x768[Depth];
  400. if(VGAEngine == SIS_300_VGA) {
  401. if(VDisplay == 1024) ModeIndex = ModeIndex_300_1360x1024[Depth];
  402. }
  403. break;
  404. case 1400:
  405. if(VGAEngine == SIS_315_VGA) {
  406. if(VDisplay == 1050) {
  407. ModeIndex = ModeIndex_1400x1050[Depth];
  408. }
  409. }
  410. break;
  411. case 1600:
  412. if(VDisplay == 1200) ModeIndex = ModeIndex_1600x1200[Depth];
  413. break;
  414. case 1680:
  415. if(VGAEngine == SIS_315_VGA) {
  416. if(VDisplay == 1050) ModeIndex = ModeIndex_1680x1050[Depth];
  417. }
  418. break;
  419. case 1920:
  420. if(VDisplay == 1440) ModeIndex = ModeIndex_1920x1440[Depth];
  421. else if(VGAEngine == SIS_315_VGA) {
  422. if(VDisplay == 1080) ModeIndex = ModeIndex_1920x1080[Depth];
  423. }
  424. break;
  425. case 2048:
  426. if(VDisplay == 1536) {
  427. if(VGAEngine == SIS_300_VGA) {
  428. ModeIndex = ModeIndex_300_2048x1536[Depth];
  429. } else {
  430. ModeIndex = ModeIndex_310_2048x1536[Depth];
  431. }
  432. }
  433. break;
  434. }
  435. return ModeIndex;
  436. }
  437. unsigned short
  438. SiS_GetModeID_LCD(int VGAEngine, unsigned int VBFlags, int HDisplay, int VDisplay,
  439. int Depth, bool FSTN, unsigned short CustomT, int LCDwidth, int LCDheight,
  440. unsigned int VBFlags2)
  441. {
  442. unsigned short ModeIndex = 0;
  443. if(VBFlags2 & (VB2_LVDS | VB2_30xBDH)) {
  444. switch(HDisplay)
  445. {
  446. case 320:
  447. if((CustomT != CUT_PANEL848) && (CustomT != CUT_PANEL856)) {
  448. if(VDisplay == 200) {
  449. if(!FSTN) ModeIndex = ModeIndex_320x200[Depth];
  450. } else if(VDisplay == 240) {
  451. if(!FSTN) ModeIndex = ModeIndex_320x240[Depth];
  452. else if(VGAEngine == SIS_315_VGA) {
  453. ModeIndex = ModeIndex_320x240_FSTN[Depth];
  454. }
  455. }
  456. }
  457. break;
  458. case 400:
  459. if((CustomT != CUT_PANEL848) && (CustomT != CUT_PANEL856)) {
  460. if(!((VGAEngine == SIS_300_VGA) && (VBFlags2 & VB2_TRUMPION))) {
  461. if(VDisplay == 300) ModeIndex = ModeIndex_400x300[Depth];
  462. }
  463. }
  464. break;
  465. case 512:
  466. if((CustomT != CUT_PANEL848) && (CustomT != CUT_PANEL856)) {
  467. if(!((VGAEngine == SIS_300_VGA) && (VBFlags2 & VB2_TRUMPION))) {
  468. if(LCDwidth >= 1024 && LCDwidth != 1152 && LCDheight >= 768) {
  469. if(VDisplay == 384) {
  470. ModeIndex = ModeIndex_512x384[Depth];
  471. }
  472. }
  473. }
  474. }
  475. break;
  476. case 640:
  477. if(VDisplay == 480) ModeIndex = ModeIndex_640x480[Depth];
  478. else if(VDisplay == 400) {
  479. if((CustomT != CUT_PANEL848) && (CustomT != CUT_PANEL856))
  480. ModeIndex = ModeIndex_640x400[Depth];
  481. }
  482. break;
  483. case 800:
  484. if(VDisplay == 600) ModeIndex = ModeIndex_800x600[Depth];
  485. break;
  486. case 848:
  487. if(CustomT == CUT_PANEL848) {
  488. if(VDisplay == 480) ModeIndex = ModeIndex_848x480[Depth];
  489. }
  490. break;
  491. case 856:
  492. if(CustomT == CUT_PANEL856) {
  493. if(VDisplay == 480) ModeIndex = ModeIndex_856x480[Depth];
  494. }
  495. break;
  496. case 1024:
  497. if(VDisplay == 768) ModeIndex = ModeIndex_1024x768[Depth];
  498. else if(VGAEngine == SIS_300_VGA) {
  499. if((VDisplay == 600) && (LCDheight == 600)) {
  500. ModeIndex = ModeIndex_1024x600[Depth];
  501. }
  502. }
  503. break;
  504. case 1152:
  505. if(VGAEngine == SIS_300_VGA) {
  506. if((VDisplay == 768) && (LCDheight == 768)) {
  507. ModeIndex = ModeIndex_1152x768[Depth];
  508. }
  509. }
  510. break;
  511. case 1280:
  512. if(VDisplay == 1024) ModeIndex = ModeIndex_1280x1024[Depth];
  513. else if(VGAEngine == SIS_315_VGA) {
  514. if((VDisplay == 768) && (LCDheight == 768)) {
  515. ModeIndex = ModeIndex_310_1280x768[Depth];
  516. }
  517. }
  518. break;
  519. case 1360:
  520. if(VGAEngine == SIS_300_VGA) {
  521. if(CustomT == CUT_BARCO1366) {
  522. if(VDisplay == 1024) ModeIndex = ModeIndex_300_1360x1024[Depth];
  523. }
  524. }
  525. if(CustomT == CUT_PANEL848) {
  526. if(VDisplay == 768) ModeIndex = ModeIndex_1360x768[Depth];
  527. }
  528. break;
  529. case 1400:
  530. if(VGAEngine == SIS_315_VGA) {
  531. if(VDisplay == 1050) ModeIndex = ModeIndex_1400x1050[Depth];
  532. }
  533. break;
  534. case 1600:
  535. if(VGAEngine == SIS_315_VGA) {
  536. if(VDisplay == 1200) ModeIndex = ModeIndex_1600x1200[Depth];
  537. }
  538. break;
  539. }
  540. } else if(VBFlags2 & VB2_SISBRIDGE) {
  541. switch(HDisplay)
  542. {
  543. case 320:
  544. if(VDisplay == 200) ModeIndex = ModeIndex_320x200[Depth];
  545. else if(VDisplay == 240) ModeIndex = ModeIndex_320x240[Depth];
  546. break;
  547. case 400:
  548. if(LCDwidth >= 800 && LCDheight >= 600) {
  549. if(VDisplay == 300) ModeIndex = ModeIndex_400x300[Depth];
  550. }
  551. break;
  552. case 512:
  553. if(LCDwidth >= 1024 && LCDheight >= 768 && LCDwidth != 1152) {
  554. if(VDisplay == 384) ModeIndex = ModeIndex_512x384[Depth];
  555. }
  556. break;
  557. case 640:
  558. if(VDisplay == 480) ModeIndex = ModeIndex_640x480[Depth];
  559. else if(VDisplay == 400) ModeIndex = ModeIndex_640x400[Depth];
  560. break;
  561. case 720:
  562. if(VGAEngine == SIS_315_VGA) {
  563. if(VDisplay == 480) ModeIndex = ModeIndex_720x480[Depth];
  564. else if(VDisplay == 576) ModeIndex = ModeIndex_720x576[Depth];
  565. }
  566. break;
  567. case 768:
  568. if(VGAEngine == SIS_315_VGA) {
  569. if(VDisplay == 576) ModeIndex = ModeIndex_768x576[Depth];
  570. }
  571. break;
  572. case 800:
  573. if(VDisplay == 600) ModeIndex = ModeIndex_800x600[Depth];
  574. if(VGAEngine == SIS_315_VGA) {
  575. if(VDisplay == 480) ModeIndex = ModeIndex_800x480[Depth];
  576. }
  577. break;
  578. case 848:
  579. if(VGAEngine == SIS_315_VGA) {
  580. if(VDisplay == 480) ModeIndex = ModeIndex_848x480[Depth];
  581. }
  582. break;
  583. case 856:
  584. if(VGAEngine == SIS_315_VGA) {
  585. if(VDisplay == 480) ModeIndex = ModeIndex_856x480[Depth];
  586. }
  587. break;
  588. case 960:
  589. if(VGAEngine == SIS_315_VGA) {
  590. if(VDisplay == 540) ModeIndex = ModeIndex_960x540[Depth];
  591. else if(VDisplay == 600) ModeIndex = ModeIndex_960x600[Depth];
  592. }
  593. break;
  594. case 1024:
  595. if(VDisplay == 768) ModeIndex = ModeIndex_1024x768[Depth];
  596. if(VGAEngine == SIS_315_VGA) {
  597. if(VDisplay == 576) ModeIndex = ModeIndex_1024x576[Depth];
  598. }
  599. break;
  600. case 1152:
  601. if(VGAEngine == SIS_315_VGA) {
  602. if(VDisplay == 864) ModeIndex = ModeIndex_1152x864[Depth];
  603. }
  604. break;
  605. case 1280:
  606. switch(VDisplay) {
  607. case 720:
  608. ModeIndex = ModeIndex_1280x720[Depth];
  609. case 768:
  610. if(VGAEngine == SIS_300_VGA) {
  611. ModeIndex = ModeIndex_300_1280x768[Depth];
  612. } else {
  613. ModeIndex = ModeIndex_310_1280x768[Depth];
  614. }
  615. break;
  616. case 800:
  617. if(VGAEngine == SIS_315_VGA) {
  618. ModeIndex = ModeIndex_1280x800[Depth];
  619. }
  620. break;
  621. case 854:
  622. if(VGAEngine == SIS_315_VGA) {
  623. ModeIndex = ModeIndex_1280x854[Depth];
  624. }
  625. break;
  626. case 960:
  627. ModeIndex = ModeIndex_1280x960[Depth];
  628. break;
  629. case 1024:
  630. ModeIndex = ModeIndex_1280x1024[Depth];
  631. break;
  632. }
  633. break;
  634. case 1360:
  635. if(VGAEngine == SIS_315_VGA) { /* OVER1280 only? */
  636. if(VDisplay == 768) ModeIndex = ModeIndex_1360x768[Depth];
  637. }
  638. break;
  639. case 1400:
  640. if(VGAEngine == SIS_315_VGA) {
  641. if(VBFlags2 & VB2_LCDOVER1280BRIDGE) {
  642. if(VDisplay == 1050) ModeIndex = ModeIndex_1400x1050[Depth];
  643. }
  644. }
  645. break;
  646. case 1600:
  647. if(VGAEngine == SIS_315_VGA) {
  648. if(VBFlags2 & VB2_LCDOVER1280BRIDGE) {
  649. if(VDisplay == 1200) ModeIndex = ModeIndex_1600x1200[Depth];
  650. }
  651. }
  652. break;
  653. #ifndef VB_FORBID_CRT2LCD_OVER_1600
  654. case 1680:
  655. if(VGAEngine == SIS_315_VGA) {
  656. if(VBFlags2 & VB2_LCDOVER1280BRIDGE) {
  657. if(VDisplay == 1050) ModeIndex = ModeIndex_1680x1050[Depth];
  658. }
  659. }
  660. break;
  661. case 1920:
  662. if(VGAEngine == SIS_315_VGA) {
  663. if(VBFlags2 & VB2_LCDOVER1600BRIDGE) {
  664. if(VDisplay == 1440) ModeIndex = ModeIndex_1920x1440[Depth];
  665. }
  666. }
  667. break;
  668. case 2048:
  669. if(VGAEngine == SIS_315_VGA) {
  670. if(VBFlags2 & VB2_LCDOVER1600BRIDGE) {
  671. if(VDisplay == 1536) ModeIndex = ModeIndex_310_2048x1536[Depth];
  672. }
  673. }
  674. break;
  675. #endif
  676. }
  677. }
  678. return ModeIndex;
  679. }
  680. unsigned short
  681. SiS_GetModeID_TV(int VGAEngine, unsigned int VBFlags, int HDisplay, int VDisplay, int Depth,
  682. unsigned int VBFlags2)
  683. {
  684. unsigned short ModeIndex = 0;
  685. if(VBFlags2 & VB2_CHRONTEL) {
  686. switch(HDisplay)
  687. {
  688. case 512:
  689. if(VGAEngine == SIS_315_VGA) {
  690. if(VDisplay == 384) ModeIndex = ModeIndex_512x384[Depth];
  691. }
  692. break;
  693. case 640:
  694. if(VDisplay == 480) ModeIndex = ModeIndex_640x480[Depth];
  695. else if(VDisplay == 400) ModeIndex = ModeIndex_640x400[Depth];
  696. break;
  697. case 800:
  698. if(VDisplay == 600) ModeIndex = ModeIndex_800x600[Depth];
  699. break;
  700. case 1024:
  701. if(VGAEngine == SIS_315_VGA) {
  702. if(VDisplay == 768) ModeIndex = ModeIndex_1024x768[Depth];
  703. }
  704. break;
  705. }
  706. } else if(VBFlags2 & VB2_SISTVBRIDGE) {
  707. switch(HDisplay)
  708. {
  709. case 320:
  710. if(VDisplay == 200) ModeIndex = ModeIndex_320x200[Depth];
  711. else if(VDisplay == 240) ModeIndex = ModeIndex_320x240[Depth];
  712. break;
  713. case 400:
  714. if(VDisplay == 300) ModeIndex = ModeIndex_400x300[Depth];
  715. break;
  716. case 512:
  717. if( ((VBFlags & TV_YPBPR) && (VBFlags & (TV_YPBPR750P | TV_YPBPR1080I))) ||
  718. (VBFlags & TV_HIVISION) ||
  719. ((!(VBFlags & (TV_YPBPR | TV_PALM))) && (VBFlags & TV_PAL)) ) {
  720. if(VDisplay == 384) ModeIndex = ModeIndex_512x384[Depth];
  721. }
  722. break;
  723. case 640:
  724. if(VDisplay == 480) ModeIndex = ModeIndex_640x480[Depth];
  725. else if(VDisplay == 400) ModeIndex = ModeIndex_640x400[Depth];
  726. break;
  727. case 720:
  728. if((!(VBFlags & TV_HIVISION)) && (!((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR1080I)))) {
  729. if(VDisplay == 480) {
  730. ModeIndex = ModeIndex_720x480[Depth];
  731. } else if(VDisplay == 576) {
  732. if( ((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR750P)) ||
  733. ((!(VBFlags & (TV_YPBPR | TV_PALM))) && (VBFlags & TV_PAL)) )
  734. ModeIndex = ModeIndex_720x576[Depth];
  735. }
  736. }
  737. break;
  738. case 768:
  739. if((!(VBFlags & TV_HIVISION)) && (!((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR1080I)))) {
  740. if( ((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR750P)) ||
  741. ((!(VBFlags & (TV_YPBPR | TV_PALM))) && (VBFlags & TV_PAL)) ) {
  742. if(VDisplay == 576) ModeIndex = ModeIndex_768x576[Depth];
  743. }
  744. }
  745. break;
  746. case 800:
  747. if(VDisplay == 600) ModeIndex = ModeIndex_800x600[Depth];
  748. else if(VDisplay == 480) {
  749. if(!((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR750P))) {
  750. ModeIndex = ModeIndex_800x480[Depth];
  751. }
  752. }
  753. break;
  754. case 960:
  755. if(VGAEngine == SIS_315_VGA) {
  756. if(VDisplay == 600) {
  757. if((VBFlags & TV_HIVISION) || ((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR1080I))) {
  758. ModeIndex = ModeIndex_960x600[Depth];
  759. }
  760. }
  761. }
  762. break;
  763. case 1024:
  764. if(VDisplay == 768) {
  765. if(VBFlags2 & VB2_30xBLV) {
  766. ModeIndex = ModeIndex_1024x768[Depth];
  767. }
  768. } else if(VDisplay == 576) {
  769. if( (VBFlags & TV_HIVISION) ||
  770. ((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR1080I)) ||
  771. ((VBFlags2 & VB2_30xBLV) &&
  772. ((!(VBFlags & (TV_YPBPR | TV_PALM))) && (VBFlags & TV_PAL))) ) {
  773. ModeIndex = ModeIndex_1024x576[Depth];
  774. }
  775. }
  776. break;
  777. case 1280:
  778. if(VDisplay == 720) {
  779. if((VBFlags & TV_HIVISION) ||
  780. ((VBFlags & TV_YPBPR) && (VBFlags & (TV_YPBPR1080I | TV_YPBPR750P)))) {
  781. ModeIndex = ModeIndex_1280x720[Depth];
  782. }
  783. } else if(VDisplay == 1024) {
  784. if((VBFlags & TV_HIVISION) ||
  785. ((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR1080I))) {
  786. ModeIndex = ModeIndex_1280x1024[Depth];
  787. }
  788. }
  789. break;
  790. }
  791. }
  792. return ModeIndex;
  793. }
  794. unsigned short
  795. SiS_GetModeID_VGA2(int VGAEngine, unsigned int VBFlags, int HDisplay, int VDisplay, int Depth,
  796. unsigned int VBFlags2)
  797. {
  798. if(!(VBFlags2 & VB2_SISVGA2BRIDGE)) return 0;
  799. if(HDisplay >= 1920) return 0;
  800. switch(HDisplay)
  801. {
  802. case 1600:
  803. if(VDisplay == 1200) {
  804. if(VGAEngine != SIS_315_VGA) return 0;
  805. if(!(VBFlags2 & VB2_30xB)) return 0;
  806. }
  807. break;
  808. case 1680:
  809. if(VDisplay == 1050) {
  810. if(VGAEngine != SIS_315_VGA) return 0;
  811. if(!(VBFlags2 & VB2_30xB)) return 0;
  812. }
  813. break;
  814. }
  815. return SiS_GetModeID(VGAEngine, 0, HDisplay, VDisplay, Depth, false, 0, 0);
  816. }
  817. /*********************************************/
  818. /* HELPER: SetReg, GetReg */
  819. /*********************************************/
  820. void
  821. SiS_SetReg(SISIOADDRESS port, u8 index, u8 data)
  822. {
  823. outb(index, port);
  824. outb(data, port + 1);
  825. }
  826. void
  827. SiS_SetRegByte(SISIOADDRESS port, u8 data)
  828. {
  829. outb(data, port);
  830. }
  831. void
  832. SiS_SetRegShort(SISIOADDRESS port, u16 data)
  833. {
  834. outw(data, port);
  835. }
  836. void
  837. SiS_SetRegLong(SISIOADDRESS port, u32 data)
  838. {
  839. outl(data, port);
  840. }
  841. u8
  842. SiS_GetReg(SISIOADDRESS port, u8 index)
  843. {
  844. outb(index, port);
  845. return inb(port + 1);
  846. }
  847. u8
  848. SiS_GetRegByte(SISIOADDRESS port)
  849. {
  850. return inb(port);
  851. }
  852. u16
  853. SiS_GetRegShort(SISIOADDRESS port)
  854. {
  855. return inw(port);
  856. }
  857. u32
  858. SiS_GetRegLong(SISIOADDRESS port)
  859. {
  860. return inl(port);
  861. }
  862. void
  863. SiS_SetRegANDOR(SISIOADDRESS Port, u8 Index, u8 DataAND, u8 DataOR)
  864. {
  865. u8 temp;
  866. temp = SiS_GetReg(Port, Index);
  867. temp = (temp & (DataAND)) | DataOR;
  868. SiS_SetReg(Port, Index, temp);
  869. }
  870. void
  871. SiS_SetRegAND(SISIOADDRESS Port, u8 Index, u8 DataAND)
  872. {
  873. u8 temp;
  874. temp = SiS_GetReg(Port, Index);
  875. temp &= DataAND;
  876. SiS_SetReg(Port, Index, temp);
  877. }
  878. void
  879. SiS_SetRegOR(SISIOADDRESS Port, u8 Index, u8 DataOR)
  880. {
  881. u8 temp;
  882. temp = SiS_GetReg(Port, Index);
  883. temp |= DataOR;
  884. SiS_SetReg(Port, Index, temp);
  885. }
  886. /*********************************************/
  887. /* HELPER: DisplayOn, DisplayOff */
  888. /*********************************************/
  889. void
  890. SiS_DisplayOn(struct SiS_Private *SiS_Pr)
  891. {
  892. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x01,0xDF);
  893. }
  894. void
  895. SiS_DisplayOff(struct SiS_Private *SiS_Pr)
  896. {
  897. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x01,0x20);
  898. }
  899. /*********************************************/
  900. /* HELPER: Init Port Addresses */
  901. /*********************************************/
  902. void
  903. SiSRegInit(struct SiS_Private *SiS_Pr, SISIOADDRESS BaseAddr)
  904. {
  905. SiS_Pr->SiS_P3c4 = BaseAddr + 0x14;
  906. SiS_Pr->SiS_P3d4 = BaseAddr + 0x24;
  907. SiS_Pr->SiS_P3c0 = BaseAddr + 0x10;
  908. SiS_Pr->SiS_P3ce = BaseAddr + 0x1e;
  909. SiS_Pr->SiS_P3c2 = BaseAddr + 0x12;
  910. SiS_Pr->SiS_P3ca = BaseAddr + 0x1a;
  911. SiS_Pr->SiS_P3c6 = BaseAddr + 0x16;
  912. SiS_Pr->SiS_P3c7 = BaseAddr + 0x17;
  913. SiS_Pr->SiS_P3c8 = BaseAddr + 0x18;
  914. SiS_Pr->SiS_P3c9 = BaseAddr + 0x19;
  915. SiS_Pr->SiS_P3cb = BaseAddr + 0x1b;
  916. SiS_Pr->SiS_P3cc = BaseAddr + 0x1c;
  917. SiS_Pr->SiS_P3cd = BaseAddr + 0x1d;
  918. SiS_Pr->SiS_P3da = BaseAddr + 0x2a;
  919. SiS_Pr->SiS_Part1Port = BaseAddr + SIS_CRT2_PORT_04;
  920. SiS_Pr->SiS_Part2Port = BaseAddr + SIS_CRT2_PORT_10;
  921. SiS_Pr->SiS_Part3Port = BaseAddr + SIS_CRT2_PORT_12;
  922. SiS_Pr->SiS_Part4Port = BaseAddr + SIS_CRT2_PORT_14;
  923. SiS_Pr->SiS_Part5Port = BaseAddr + SIS_CRT2_PORT_14 + 2;
  924. SiS_Pr->SiS_DDC_Port = BaseAddr + 0x14;
  925. SiS_Pr->SiS_VidCapt = BaseAddr + SIS_VIDEO_CAPTURE;
  926. SiS_Pr->SiS_VidPlay = BaseAddr + SIS_VIDEO_PLAYBACK;
  927. }
  928. /*********************************************/
  929. /* HELPER: GetSysFlags */
  930. /*********************************************/
  931. static void
  932. SiS_GetSysFlags(struct SiS_Private *SiS_Pr)
  933. {
  934. unsigned char cr5f, temp1, temp2;
  935. /* 661 and newer: NEVER write non-zero to SR11[7:4] */
  936. /* (SR11 is used for DDC and in enable/disablebridge) */
  937. SiS_Pr->SiS_SensibleSR11 = false;
  938. SiS_Pr->SiS_MyCR63 = 0x63;
  939. if(SiS_Pr->ChipType >= SIS_330) {
  940. SiS_Pr->SiS_MyCR63 = 0x53;
  941. if(SiS_Pr->ChipType >= SIS_661) {
  942. SiS_Pr->SiS_SensibleSR11 = true;
  943. }
  944. }
  945. /* You should use the macros, not these flags directly */
  946. SiS_Pr->SiS_SysFlags = 0;
  947. if(SiS_Pr->ChipType == SIS_650) {
  948. cr5f = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xf0;
  949. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x5c,0x07);
  950. temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5c) & 0xf8;
  951. SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x5c,0xf8);
  952. temp2 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5c) & 0xf8;
  953. if((!temp1) || (temp2)) {
  954. switch(cr5f) {
  955. case 0x80:
  956. case 0x90:
  957. case 0xc0:
  958. SiS_Pr->SiS_SysFlags |= SF_IsM650;
  959. break;
  960. case 0xa0:
  961. case 0xb0:
  962. case 0xe0:
  963. SiS_Pr->SiS_SysFlags |= SF_Is651;
  964. break;
  965. }
  966. } else {
  967. switch(cr5f) {
  968. case 0x90:
  969. temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5c) & 0xf8;
  970. switch(temp1) {
  971. case 0x00: SiS_Pr->SiS_SysFlags |= SF_IsM652; break;
  972. case 0x40: SiS_Pr->SiS_SysFlags |= SF_IsM653; break;
  973. default: SiS_Pr->SiS_SysFlags |= SF_IsM650; break;
  974. }
  975. break;
  976. case 0xb0:
  977. SiS_Pr->SiS_SysFlags |= SF_Is652;
  978. break;
  979. default:
  980. SiS_Pr->SiS_SysFlags |= SF_IsM650;
  981. break;
  982. }
  983. }
  984. }
  985. if(SiS_Pr->ChipType >= SIS_760 && SiS_Pr->ChipType <= SIS_761) {
  986. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x78) & 0x30) {
  987. SiS_Pr->SiS_SysFlags |= SF_760LFB;
  988. }
  989. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x79) & 0xf0) {
  990. SiS_Pr->SiS_SysFlags |= SF_760UMA;
  991. }
  992. }
  993. }
  994. /*********************************************/
  995. /* HELPER: Init PCI & Engines */
  996. /*********************************************/
  997. static void
  998. SiSInitPCIetc(struct SiS_Private *SiS_Pr)
  999. {
  1000. switch(SiS_Pr->ChipType) {
  1001. #ifdef CONFIG_FB_SIS_300
  1002. case SIS_300:
  1003. case SIS_540:
  1004. case SIS_630:
  1005. case SIS_730:
  1006. /* Set - PCI LINEAR ADDRESSING ENABLE (0x80)
  1007. * - RELOCATED VGA IO ENABLED (0x20)
  1008. * - MMIO ENABLED (0x01)
  1009. * Leave other bits untouched.
  1010. */
  1011. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x20,0xa1);
  1012. /* - Enable 2D (0x40)
  1013. * - Enable 3D (0x02)
  1014. * - Enable 3D Vertex command fetch (0x10) ?
  1015. * - Enable 3D command parser (0x08) ?
  1016. */
  1017. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x5A);
  1018. break;
  1019. #endif
  1020. #ifdef CONFIG_FB_SIS_315
  1021. case SIS_315H:
  1022. case SIS_315:
  1023. case SIS_315PRO:
  1024. case SIS_650:
  1025. case SIS_740:
  1026. case SIS_330:
  1027. case SIS_661:
  1028. case SIS_741:
  1029. case SIS_660:
  1030. case SIS_760:
  1031. case SIS_761:
  1032. case SIS_340:
  1033. case XGI_40:
  1034. /* See above */
  1035. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x20,0xa1);
  1036. /* - Enable 3D G/L transformation engine (0x80)
  1037. * - Enable 2D (0x40)
  1038. * - Enable 3D vertex command fetch (0x10)
  1039. * - Enable 3D command parser (0x08)
  1040. * - Enable 3D (0x02)
  1041. */
  1042. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0xDA);
  1043. break;
  1044. case XGI_20:
  1045. case SIS_550:
  1046. /* See above */
  1047. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x20,0xa1);
  1048. /* No 3D engine ! */
  1049. /* - Enable 2D (0x40)
  1050. * - disable 3D
  1051. */
  1052. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x1E,0x60,0x40);
  1053. break;
  1054. #endif
  1055. default:
  1056. break;
  1057. }
  1058. }
  1059. /*********************************************/
  1060. /* HELPER: SetLVDSetc */
  1061. /*********************************************/
  1062. static
  1063. void
  1064. SiSSetLVDSetc(struct SiS_Private *SiS_Pr)
  1065. {
  1066. unsigned short temp;
  1067. SiS_Pr->SiS_IF_DEF_LVDS = 0;
  1068. SiS_Pr->SiS_IF_DEF_TRUMPION = 0;
  1069. SiS_Pr->SiS_IF_DEF_CH70xx = 0;
  1070. SiS_Pr->SiS_IF_DEF_CONEX = 0;
  1071. SiS_Pr->SiS_ChrontelInit = 0;
  1072. if(SiS_Pr->ChipType == XGI_20) return;
  1073. /* Check for SiS30x first */
  1074. temp = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x00);
  1075. if((temp == 1) || (temp == 2)) return;
  1076. switch(SiS_Pr->ChipType) {
  1077. #ifdef CONFIG_FB_SIS_300
  1078. case SIS_540:
  1079. case SIS_630:
  1080. case SIS_730:
  1081. temp = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x37) & 0x0e) >> 1;
  1082. if((temp >= 2) && (temp <= 5)) SiS_Pr->SiS_IF_DEF_LVDS = 1;
  1083. if(temp == 3) SiS_Pr->SiS_IF_DEF_TRUMPION = 1;
  1084. if((temp == 4) || (temp == 5)) {
  1085. /* Save power status (and error check) - UNUSED */
  1086. SiS_Pr->SiS_Backup70xx = SiS_GetCH700x(SiS_Pr, 0x0e);
  1087. SiS_Pr->SiS_IF_DEF_CH70xx = 1;
  1088. }
  1089. break;
  1090. #endif
  1091. #ifdef CONFIG_FB_SIS_315
  1092. case SIS_550:
  1093. case SIS_650:
  1094. case SIS_740:
  1095. case SIS_330:
  1096. temp = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x37) & 0x0e) >> 1;
  1097. if((temp >= 2) && (temp <= 3)) SiS_Pr->SiS_IF_DEF_LVDS = 1;
  1098. if(temp == 3) SiS_Pr->SiS_IF_DEF_CH70xx = 2;
  1099. break;
  1100. case SIS_661:
  1101. case SIS_741:
  1102. case SIS_660:
  1103. case SIS_760:
  1104. case SIS_761:
  1105. case SIS_340:
  1106. case XGI_20:
  1107. case XGI_40:
  1108. temp = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & 0xe0) >> 5;
  1109. if((temp >= 2) && (temp <= 3)) SiS_Pr->SiS_IF_DEF_LVDS = 1;
  1110. if(temp == 3) SiS_Pr->SiS_IF_DEF_CH70xx = 2;
  1111. if(temp == 4) SiS_Pr->SiS_IF_DEF_CONEX = 1; /* Not yet supported */
  1112. break;
  1113. #endif
  1114. default:
  1115. break;
  1116. }
  1117. }
  1118. /*********************************************/
  1119. /* HELPER: Enable DSTN/FSTN */
  1120. /*********************************************/
  1121. void
  1122. SiS_SetEnableDstn(struct SiS_Private *SiS_Pr, int enable)
  1123. {
  1124. SiS_Pr->SiS_IF_DEF_DSTN = enable ? 1 : 0;
  1125. }
  1126. void
  1127. SiS_SetEnableFstn(struct SiS_Private *SiS_Pr, int enable)
  1128. {
  1129. SiS_Pr->SiS_IF_DEF_FSTN = enable ? 1 : 0;
  1130. }
  1131. /*********************************************/
  1132. /* HELPER: Get modeflag */
  1133. /*********************************************/
  1134. unsigned short
  1135. SiS_GetModeFlag(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  1136. unsigned short ModeIdIndex)
  1137. {
  1138. if(SiS_Pr->UseCustomMode) {
  1139. return SiS_Pr->CModeFlag;
  1140. } else if(ModeNo <= 0x13) {
  1141. return SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  1142. } else {
  1143. return SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  1144. }
  1145. }
  1146. /*********************************************/
  1147. /* HELPER: Determine ROM usage */
  1148. /*********************************************/
  1149. bool
  1150. SiSDetermineROMLayout661(struct SiS_Private *SiS_Pr)
  1151. {
  1152. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  1153. unsigned short romversoffs, romvmaj = 1, romvmin = 0;
  1154. if(SiS_Pr->ChipType >= XGI_20) {
  1155. /* XGI ROMs don't qualify */
  1156. return false;
  1157. } else if(SiS_Pr->ChipType >= SIS_761) {
  1158. /* I very much assume 761, 340 and newer will use new layout */
  1159. return true;
  1160. } else if(SiS_Pr->ChipType >= SIS_661) {
  1161. if((ROMAddr[0x1a] == 'N') &&
  1162. (ROMAddr[0x1b] == 'e') &&
  1163. (ROMAddr[0x1c] == 'w') &&
  1164. (ROMAddr[0x1d] == 'V')) {
  1165. return true;
  1166. }
  1167. romversoffs = ROMAddr[0x16] | (ROMAddr[0x17] << 8);
  1168. if(romversoffs) {
  1169. if((ROMAddr[romversoffs+1] == '.') || (ROMAddr[romversoffs+4] == '.')) {
  1170. romvmaj = ROMAddr[romversoffs] - '0';
  1171. romvmin = ((ROMAddr[romversoffs+2] -'0') * 10) + (ROMAddr[romversoffs+3] - '0');
  1172. }
  1173. }
  1174. if((romvmaj != 0) || (romvmin >= 92)) {
  1175. return true;
  1176. }
  1177. } else if(IS_SIS650740) {
  1178. if((ROMAddr[0x1a] == 'N') &&
  1179. (ROMAddr[0x1b] == 'e') &&
  1180. (ROMAddr[0x1c] == 'w') &&
  1181. (ROMAddr[0x1d] == 'V')) {
  1182. return true;
  1183. }
  1184. }
  1185. return false;
  1186. }
  1187. static void
  1188. SiSDetermineROMUsage(struct SiS_Private *SiS_Pr)
  1189. {
  1190. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  1191. unsigned short romptr = 0;
  1192. SiS_Pr->SiS_UseROM = false;
  1193. SiS_Pr->SiS_ROMNew = false;
  1194. SiS_Pr->SiS_PWDOffset = 0;
  1195. if(SiS_Pr->ChipType >= XGI_20) return;
  1196. if((ROMAddr) && (SiS_Pr->UseROM)) {
  1197. if(SiS_Pr->ChipType == SIS_300) {
  1198. /* 300: We check if the code starts below 0x220 by
  1199. * checking the jmp instruction at the beginning
  1200. * of the BIOS image.
  1201. */
  1202. if((ROMAddr[3] == 0xe9) && ((ROMAddr[5] << 8) | ROMAddr[4]) > 0x21a)
  1203. SiS_Pr->SiS_UseROM = true;
  1204. } else if(SiS_Pr->ChipType < SIS_315H) {
  1205. /* Sony's VAIO BIOS 1.09 follows the standard, so perhaps
  1206. * the others do as well
  1207. */
  1208. SiS_Pr->SiS_UseROM = true;
  1209. } else {
  1210. /* 315/330 series stick to the standard(s) */
  1211. SiS_Pr->SiS_UseROM = true;
  1212. if((SiS_Pr->SiS_ROMNew = SiSDetermineROMLayout661(SiS_Pr))) {
  1213. SiS_Pr->SiS_EMIOffset = 14;
  1214. SiS_Pr->SiS_PWDOffset = 17;
  1215. SiS_Pr->SiS661LCD2TableSize = 36;
  1216. /* Find out about LCD data table entry size */
  1217. if((romptr = SISGETROMW(0x0102))) {
  1218. if(ROMAddr[romptr + (32 * 16)] == 0xff)
  1219. SiS_Pr->SiS661LCD2TableSize = 32;
  1220. else if(ROMAddr[romptr + (34 * 16)] == 0xff)
  1221. SiS_Pr->SiS661LCD2TableSize = 34;
  1222. else if(ROMAddr[romptr + (36 * 16)] == 0xff) /* 0.94, 2.05.00+ */
  1223. SiS_Pr->SiS661LCD2TableSize = 36;
  1224. else if( (ROMAddr[romptr + (38 * 16)] == 0xff) || /* 2.00.00 - 2.02.00 */
  1225. (ROMAddr[0x6F] & 0x01) ) { /* 2.03.00 - <2.05.00 */
  1226. SiS_Pr->SiS661LCD2TableSize = 38; /* UMC data layout abandoned at 2.05.00 */
  1227. SiS_Pr->SiS_EMIOffset = 16;
  1228. SiS_Pr->SiS_PWDOffset = 19;
  1229. }
  1230. }
  1231. }
  1232. }
  1233. }
  1234. }
  1235. /*********************************************/
  1236. /* HELPER: SET SEGMENT REGISTERS */
  1237. /*********************************************/
  1238. static void
  1239. SiS_SetSegRegLower(struct SiS_Private *SiS_Pr, unsigned short value)
  1240. {
  1241. unsigned short temp;
  1242. value &= 0x00ff;
  1243. temp = SiS_GetRegByte(SiS_Pr->SiS_P3cb) & 0xf0;
  1244. temp |= (value >> 4);
  1245. SiS_SetRegByte(SiS_Pr->SiS_P3cb, temp);
  1246. temp = SiS_GetRegByte(SiS_Pr->SiS_P3cd) & 0xf0;
  1247. temp |= (value & 0x0f);
  1248. SiS_SetRegByte(SiS_Pr->SiS_P3cd, temp);
  1249. }
  1250. static void
  1251. SiS_SetSegRegUpper(struct SiS_Private *SiS_Pr, unsigned short value)
  1252. {
  1253. unsigned short temp;
  1254. value &= 0x00ff;
  1255. temp = SiS_GetRegByte(SiS_Pr->SiS_P3cb) & 0x0f;
  1256. temp |= (value & 0xf0);
  1257. SiS_SetRegByte(SiS_Pr->SiS_P3cb, temp);
  1258. temp = SiS_GetRegByte(SiS_Pr->SiS_P3cd) & 0x0f;
  1259. temp |= (value << 4);
  1260. SiS_SetRegByte(SiS_Pr->SiS_P3cd, temp);
  1261. }
  1262. static void
  1263. SiS_SetSegmentReg(struct SiS_Private *SiS_Pr, unsigned short value)
  1264. {
  1265. SiS_SetSegRegLower(SiS_Pr, value);
  1266. SiS_SetSegRegUpper(SiS_Pr, value);
  1267. }
  1268. static void
  1269. SiS_ResetSegmentReg(struct SiS_Private *SiS_Pr)
  1270. {
  1271. SiS_SetSegmentReg(SiS_Pr, 0);
  1272. }
  1273. static void
  1274. SiS_SetSegmentRegOver(struct SiS_Private *SiS_Pr, unsigned short value)
  1275. {
  1276. unsigned short temp = value >> 8;
  1277. temp &= 0x07;
  1278. temp |= (temp << 4);
  1279. SiS_SetReg(SiS_Pr->SiS_P3c4,0x1d,temp);
  1280. SiS_SetSegmentReg(SiS_Pr, value);
  1281. }
  1282. static void
  1283. SiS_ResetSegmentRegOver(struct SiS_Private *SiS_Pr)
  1284. {
  1285. SiS_SetSegmentRegOver(SiS_Pr, 0);
  1286. }
  1287. static void
  1288. SiS_ResetSegmentRegisters(struct SiS_Private *SiS_Pr)
  1289. {
  1290. if((IS_SIS65x) || (SiS_Pr->ChipType >= SIS_661)) {
  1291. SiS_ResetSegmentReg(SiS_Pr);
  1292. SiS_ResetSegmentRegOver(SiS_Pr);
  1293. }
  1294. }
  1295. /*********************************************/
  1296. /* HELPER: GetVBType */
  1297. /*********************************************/
  1298. static
  1299. void
  1300. SiS_GetVBType(struct SiS_Private *SiS_Pr)
  1301. {
  1302. unsigned short flag = 0, rev = 0, nolcd = 0;
  1303. unsigned short p4_0f, p4_25, p4_27;
  1304. SiS_Pr->SiS_VBType = 0;
  1305. if((SiS_Pr->SiS_IF_DEF_LVDS) || (SiS_Pr->SiS_IF_DEF_CONEX))
  1306. return;
  1307. if(SiS_Pr->ChipType == XGI_20)
  1308. return;
  1309. flag = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x00);
  1310. if(flag > 3)
  1311. return;
  1312. rev = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x01);
  1313. if(flag >= 2) {
  1314. SiS_Pr->SiS_VBType = VB_SIS302B;
  1315. } else if(flag == 1) {
  1316. if(rev >= 0xC0) {
  1317. SiS_Pr->SiS_VBType = VB_SIS301C;
  1318. } else if(rev >= 0xB0) {
  1319. SiS_Pr->SiS_VBType = VB_SIS301B;
  1320. /* Check if 30xB DH version (no LCD support, use Panel Link instead) */
  1321. nolcd = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x23);
  1322. if(!(nolcd & 0x02)) SiS_Pr->SiS_VBType |= VB_NoLCD;
  1323. } else {
  1324. SiS_Pr->SiS_VBType = VB_SIS301;
  1325. }
  1326. }
  1327. if(SiS_Pr->SiS_VBType & (VB_SIS301B | VB_SIS301C | VB_SIS302B)) {
  1328. if(rev >= 0xE0) {
  1329. flag = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x39);
  1330. if(flag == 0xff) SiS_Pr->SiS_VBType = VB_SIS302LV;
  1331. else SiS_Pr->SiS_VBType = VB_SIS301C; /* VB_SIS302ELV; */
  1332. } else if(rev >= 0xD0) {
  1333. SiS_Pr->SiS_VBType = VB_SIS301LV;
  1334. }
  1335. }
  1336. if(SiS_Pr->SiS_VBType & (VB_SIS301C | VB_SIS301LV | VB_SIS302LV | VB_SIS302ELV)) {
  1337. p4_0f = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x0f);
  1338. p4_25 = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x25);
  1339. p4_27 = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x27);
  1340. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x0f,0x7f);
  1341. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x25,0x08);
  1342. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x27,0xfd);
  1343. if(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x26) & 0x08) {
  1344. SiS_Pr->SiS_VBType |= VB_UMC;
  1345. }
  1346. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x27,p4_27);
  1347. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x25,p4_25);
  1348. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0f,p4_0f);
  1349. }
  1350. }
  1351. /*********************************************/
  1352. /* HELPER: Check RAM size */
  1353. /*********************************************/
  1354. static bool
  1355. SiS_CheckMemorySize(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  1356. unsigned short ModeIdIndex)
  1357. {
  1358. unsigned short AdapterMemSize = SiS_Pr->VideoMemorySize / (1024*1024);
  1359. unsigned short modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
  1360. unsigned short memorysize = ((modeflag & MemoryInfoFlag) >> MemorySizeShift) + 1;
  1361. if(!AdapterMemSize) return true;
  1362. if(AdapterMemSize < memorysize) return false;
  1363. return true;
  1364. }
  1365. /*********************************************/
  1366. /* HELPER: Get DRAM type */
  1367. /*********************************************/
  1368. #ifdef CONFIG_FB_SIS_315
  1369. static unsigned char
  1370. SiS_Get310DRAMType(struct SiS_Private *SiS_Pr)
  1371. {
  1372. unsigned char data;
  1373. if((*SiS_Pr->pSiS_SoftSetting) & SoftDRAMType) {
  1374. data = (*SiS_Pr->pSiS_SoftSetting) & 0x03;
  1375. } else {
  1376. if(SiS_Pr->ChipType >= XGI_20) {
  1377. /* Do I need this? SR17 seems to be zero anyway... */
  1378. data = 0;
  1379. } else if(SiS_Pr->ChipType >= SIS_340) {
  1380. /* TODO */
  1381. data = 0;
  1382. } if(SiS_Pr->ChipType >= SIS_661) {
  1383. if(SiS_Pr->SiS_ROMNew) {
  1384. data = ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x78) & 0xc0) >> 6);
  1385. } else {
  1386. data = SiS_GetReg(SiS_Pr->SiS_P3d4,0x78) & 0x07;
  1387. }
  1388. } else if(IS_SIS550650740) {
  1389. data = SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x07;
  1390. } else { /* 315, 330 */
  1391. data = SiS_GetReg(SiS_Pr->SiS_P3c4,0x3a) & 0x03;
  1392. if(SiS_Pr->ChipType == SIS_330) {
  1393. if(data > 1) {
  1394. switch(SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0x30) {
  1395. case 0x00: data = 1; break;
  1396. case 0x10: data = 3; break;
  1397. case 0x20: data = 3; break;
  1398. case 0x30: data = 2; break;
  1399. }
  1400. } else {
  1401. data = 0;
  1402. }
  1403. }
  1404. }
  1405. }
  1406. return data;
  1407. }
  1408. static unsigned short
  1409. SiS_GetMCLK(struct SiS_Private *SiS_Pr)
  1410. {
  1411. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  1412. unsigned short index;
  1413. index = SiS_Get310DRAMType(SiS_Pr);
  1414. if(SiS_Pr->ChipType >= SIS_661) {
  1415. if(SiS_Pr->SiS_ROMNew) {
  1416. return((unsigned short)(SISGETROMW((0x90 + (index * 5) + 3))));
  1417. }
  1418. return(SiS_Pr->SiS_MCLKData_0[index].CLOCK);
  1419. } else if(index >= 4) {
  1420. return(SiS_Pr->SiS_MCLKData_1[index - 4].CLOCK);
  1421. } else {
  1422. return(SiS_Pr->SiS_MCLKData_0[index].CLOCK);
  1423. }
  1424. }
  1425. #endif
  1426. /*********************************************/
  1427. /* HELPER: ClearBuffer */
  1428. /*********************************************/
  1429. static void
  1430. SiS_ClearBuffer(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  1431. {
  1432. unsigned char SISIOMEMTYPE *memaddr = SiS_Pr->VideoMemoryAddress;
  1433. unsigned int memsize = SiS_Pr->VideoMemorySize;
  1434. unsigned short SISIOMEMTYPE *pBuffer;
  1435. int i;
  1436. if(!memaddr || !memsize) return;
  1437. if(SiS_Pr->SiS_ModeType >= ModeEGA) {
  1438. if(ModeNo > 0x13) {
  1439. memset_io(memaddr, 0, memsize);
  1440. } else {
  1441. pBuffer = (unsigned short SISIOMEMTYPE *)memaddr;
  1442. for(i = 0; i < 0x4000; i++) writew(0x0000, &pBuffer[i]);
  1443. }
  1444. } else if(SiS_Pr->SiS_ModeType < ModeCGA) {
  1445. pBuffer = (unsigned short SISIOMEMTYPE *)memaddr;
  1446. for(i = 0; i < 0x4000; i++) writew(0x0720, &pBuffer[i]);
  1447. } else {
  1448. memset_io(memaddr, 0, 0x8000);
  1449. }
  1450. }
  1451. /*********************************************/
  1452. /* HELPER: SearchModeID */
  1453. /*********************************************/
  1454. bool
  1455. SiS_SearchModeID(struct SiS_Private *SiS_Pr, unsigned short *ModeNo,
  1456. unsigned short *ModeIdIndex)
  1457. {
  1458. unsigned char VGAINFO = SiS_Pr->SiS_VGAINFO;
  1459. if((*ModeNo) <= 0x13) {
  1460. if((*ModeNo) <= 0x05) (*ModeNo) |= 0x01;
  1461. for((*ModeIdIndex) = 0; ;(*ModeIdIndex)++) {
  1462. if(SiS_Pr->SiS_SModeIDTable[(*ModeIdIndex)].St_ModeID == (*ModeNo)) break;
  1463. if(SiS_Pr->SiS_SModeIDTable[(*ModeIdIndex)].St_ModeID == 0xFF) return false;
  1464. }
  1465. if((*ModeNo) == 0x07) {
  1466. if(VGAINFO & 0x10) (*ModeIdIndex)++; /* 400 lines */
  1467. /* else 350 lines */
  1468. }
  1469. if((*ModeNo) <= 0x03) {
  1470. if(!(VGAINFO & 0x80)) (*ModeIdIndex)++;
  1471. if(VGAINFO & 0x10) (*ModeIdIndex)++; /* 400 lines */
  1472. /* else 350 lines */
  1473. }
  1474. /* else 200 lines */
  1475. } else {
  1476. for((*ModeIdIndex) = 0; ;(*ModeIdIndex)++) {
  1477. if(SiS_Pr->SiS_EModeIDTable[(*ModeIdIndex)].Ext_ModeID == (*ModeNo)) break;
  1478. if(SiS_Pr->SiS_EModeIDTable[(*ModeIdIndex)].Ext_ModeID == 0xFF) return false;
  1479. }
  1480. }
  1481. return true;
  1482. }
  1483. /*********************************************/
  1484. /* HELPER: GetModePtr */
  1485. /*********************************************/
  1486. unsigned short
  1487. SiS_GetModePtr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  1488. {
  1489. unsigned short index;
  1490. if(ModeNo <= 0x13) {
  1491. index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_StTableIndex;
  1492. } else {
  1493. if(SiS_Pr->SiS_ModeType <= ModeEGA) index = 0x1B;
  1494. else index = 0x0F;
  1495. }
  1496. return index;
  1497. }
  1498. /*********************************************/
  1499. /* HELPERS: Get some indices */
  1500. /*********************************************/
  1501. unsigned short
  1502. SiS_GetRefCRTVCLK(struct SiS_Private *SiS_Pr, unsigned short Index, int UseWide)
  1503. {
  1504. if(SiS_Pr->SiS_RefIndex[Index].Ext_InfoFlag & HaveWideTiming) {
  1505. if(UseWide == 1) {
  1506. return SiS_Pr->SiS_RefIndex[Index].Ext_CRTVCLK_WIDE;
  1507. } else {
  1508. return SiS_Pr->SiS_RefIndex[Index].Ext_CRTVCLK_NORM;
  1509. }
  1510. } else {
  1511. return SiS_Pr->SiS_RefIndex[Index].Ext_CRTVCLK;
  1512. }
  1513. }
  1514. unsigned short
  1515. SiS_GetRefCRT1CRTC(struct SiS_Private *SiS_Pr, unsigned short Index, int UseWide)
  1516. {
  1517. if(SiS_Pr->SiS_RefIndex[Index].Ext_InfoFlag & HaveWideTiming) {
  1518. if(UseWide == 1) {
  1519. return SiS_Pr->SiS_RefIndex[Index].Ext_CRT1CRTC_WIDE;
  1520. } else {
  1521. return SiS_Pr->SiS_RefIndex[Index].Ext_CRT1CRTC_NORM;
  1522. }
  1523. } else {
  1524. return SiS_Pr->SiS_RefIndex[Index].Ext_CRT1CRTC;
  1525. }
  1526. }
  1527. /*********************************************/
  1528. /* HELPER: LowModeTests */
  1529. /*********************************************/
  1530. static bool
  1531. SiS_DoLowModeTest(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  1532. {
  1533. unsigned short temp, temp1, temp2;
  1534. if((ModeNo != 0x03) && (ModeNo != 0x10) && (ModeNo != 0x12))
  1535. return true;
  1536. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x11);
  1537. SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x11,0x80);
  1538. temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x00);
  1539. SiS_SetReg(SiS_Pr->SiS_P3d4,0x00,0x55);
  1540. temp2 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x00);
  1541. SiS_SetReg(SiS_Pr->SiS_P3d4,0x00,temp1);
  1542. SiS_SetReg(SiS_Pr->SiS_P3d4,0x11,temp);
  1543. if((SiS_Pr->ChipType >= SIS_315H) ||
  1544. (SiS_Pr->ChipType == SIS_300)) {
  1545. if(temp2 == 0x55) return false;
  1546. else return true;
  1547. } else {
  1548. if(temp2 != 0x55) return true;
  1549. else {
  1550. SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x35,0x01);
  1551. return false;
  1552. }
  1553. }
  1554. }
  1555. static void
  1556. SiS_SetLowModeTest(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  1557. {
  1558. if(SiS_DoLowModeTest(SiS_Pr, ModeNo)) {
  1559. SiS_Pr->SiS_SetFlag |= LowModeTests;
  1560. }
  1561. }
  1562. /*********************************************/
  1563. /* HELPER: OPEN/CLOSE CRT1 CRTC */
  1564. /*********************************************/
  1565. static void
  1566. SiS_OpenCRTC(struct SiS_Private *SiS_Pr)
  1567. {
  1568. if(IS_SIS650) {
  1569. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x51,0x1f);
  1570. if(IS_SIS651) SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x51,0x20);
  1571. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x56,0xe7);
  1572. } else if(IS_SIS661741660760) {
  1573. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x61,0xf7);
  1574. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x51,0x1f);
  1575. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x56,0xe7);
  1576. if(!SiS_Pr->SiS_ROMNew) {
  1577. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x3a,0xef);
  1578. }
  1579. }
  1580. }
  1581. static void
  1582. SiS_CloseCRTC(struct SiS_Private *SiS_Pr)
  1583. {
  1584. #if 0 /* This locks some CRTC registers. We don't want that. */
  1585. unsigned short temp1 = 0, temp2 = 0;
  1586. if(IS_SIS661741660760) {
  1587. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  1588. temp1 = 0xa0; temp2 = 0x08;
  1589. }
  1590. SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x51,0x1f,temp1);
  1591. SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x56,0xe7,temp2);
  1592. }
  1593. #endif
  1594. }
  1595. static void
  1596. SiS_HandleCRT1(struct SiS_Private *SiS_Pr)
  1597. {
  1598. /* Enable CRT1 gating */
  1599. SiS_SetRegAND(SiS_Pr->SiS_P3d4,SiS_Pr->SiS_MyCR63,0xbf);
  1600. #if 0
  1601. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x15) & 0x01)) {
  1602. if((SiS_GetReg(SiS_Pr->SiS_P3c4,0x15) & 0x0a) ||
  1603. (SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x01)) {
  1604. SiS_SetRegOR(SiS_Pr->SiS_P3d4,SiS_Pr->SiS_MyCR63,0x40);
  1605. }
  1606. }
  1607. #endif
  1608. }
  1609. /*********************************************/
  1610. /* HELPER: GetColorDepth */
  1611. /*********************************************/
  1612. unsigned short
  1613. SiS_GetColorDepth(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  1614. unsigned short ModeIdIndex)
  1615. {
  1616. static const unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
  1617. unsigned short modeflag;
  1618. short index;
  1619. /* Do NOT check UseCustomMode, will skrew up FIFO */
  1620. if(ModeNo == 0xfe) {
  1621. modeflag = SiS_Pr->CModeFlag;
  1622. } else if(ModeNo <= 0x13) {
  1623. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  1624. } else {
  1625. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  1626. }
  1627. index = (modeflag & ModeTypeMask) - ModeEGA;
  1628. if(index < 0) index = 0;
  1629. return ColorDepth[index];
  1630. }
  1631. /*********************************************/
  1632. /* HELPER: GetOffset */
  1633. /*********************************************/
  1634. unsigned short
  1635. SiS_GetOffset(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  1636. unsigned short ModeIdIndex, unsigned short RRTI)
  1637. {
  1638. unsigned short xres, temp, colordepth, infoflag;
  1639. if(SiS_Pr->UseCustomMode) {
  1640. infoflag = SiS_Pr->CInfoFlag;
  1641. xres = SiS_Pr->CHDisplay;
  1642. } else {
  1643. infoflag = SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag;
  1644. xres = SiS_Pr->SiS_RefIndex[RRTI].XRes;
  1645. }
  1646. colordepth = SiS_GetColorDepth(SiS_Pr, ModeNo, ModeIdIndex);
  1647. temp = xres / 16;
  1648. if(infoflag & InterlaceMode) temp <<= 1;
  1649. temp *= colordepth;
  1650. if(xres % 16) temp += (colordepth >> 1);
  1651. return temp;
  1652. }
  1653. /*********************************************/
  1654. /* SEQ */
  1655. /*********************************************/
  1656. static void
  1657. SiS_SetSeqRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex)
  1658. {
  1659. unsigned char SRdata;
  1660. int i;
  1661. SiS_SetReg(SiS_Pr->SiS_P3c4,0x00,0x03);
  1662. /* or "display off" */
  1663. SRdata = SiS_Pr->SiS_StandTable[StandTableIndex].SR[0] | 0x20;
  1664. /* determine whether to force x8 dotclock */
  1665. if((SiS_Pr->SiS_VBType & VB_SISVB) || (SiS_Pr->SiS_IF_DEF_LVDS)) {
  1666. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
  1667. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) SRdata |= 0x01;
  1668. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) SRdata |= 0x01;
  1669. }
  1670. SiS_SetReg(SiS_Pr->SiS_P3c4,0x01,SRdata);
  1671. for(i = 2; i <= 4; i++) {
  1672. SRdata = SiS_Pr->SiS_StandTable[StandTableIndex].SR[i - 1];
  1673. SiS_SetReg(SiS_Pr->SiS_P3c4,i,SRdata);
  1674. }
  1675. }
  1676. /*********************************************/
  1677. /* MISC */
  1678. /*********************************************/
  1679. static void
  1680. SiS_SetMiscRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex)
  1681. {
  1682. unsigned char Miscdata;
  1683. Miscdata = SiS_Pr->SiS_StandTable[StandTableIndex].MISC;
  1684. if(SiS_Pr->ChipType < SIS_661) {
  1685. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  1686. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  1687. Miscdata |= 0x0C;
  1688. }
  1689. }
  1690. }
  1691. SiS_SetRegByte(SiS_Pr->SiS_P3c2,Miscdata);
  1692. }
  1693. /*********************************************/
  1694. /* CRTC */
  1695. /*********************************************/
  1696. static void
  1697. SiS_SetCRTCRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex)
  1698. {
  1699. unsigned char CRTCdata;
  1700. unsigned short i;
  1701. /* Unlock CRTC */
  1702. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x11,0x7f);
  1703. for(i = 0; i <= 0x18; i++) {
  1704. CRTCdata = SiS_Pr->SiS_StandTable[StandTableIndex].CRTC[i];
  1705. SiS_SetReg(SiS_Pr->SiS_P3d4,i,CRTCdata);
  1706. }
  1707. if(SiS_Pr->ChipType >= SIS_661) {
  1708. SiS_OpenCRTC(SiS_Pr);
  1709. for(i = 0x13; i <= 0x14; i++) {
  1710. CRTCdata = SiS_Pr->SiS_StandTable[StandTableIndex].CRTC[i];
  1711. SiS_SetReg(SiS_Pr->SiS_P3d4,i,CRTCdata);
  1712. }
  1713. } else if( ( (SiS_Pr->ChipType == SIS_630) ||
  1714. (SiS_Pr->ChipType == SIS_730) ) &&
  1715. (SiS_Pr->ChipRevision >= 0x30) ) {
  1716. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  1717. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
  1718. SiS_SetReg(SiS_Pr->SiS_P3d4,0x18,0xFE);
  1719. }
  1720. }
  1721. }
  1722. }
  1723. /*********************************************/
  1724. /* ATT */
  1725. /*********************************************/
  1726. static void
  1727. SiS_SetATTRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex)
  1728. {
  1729. unsigned char ARdata;
  1730. unsigned short i;
  1731. for(i = 0; i <= 0x13; i++) {
  1732. ARdata = SiS_Pr->SiS_StandTable[StandTableIndex].ATTR[i];
  1733. if(i == 0x13) {
  1734. /* Pixel shift. If screen on LCD or TV is shifted left or right,
  1735. * this might be the cause.
  1736. */
  1737. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  1738. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) ARdata = 0;
  1739. }
  1740. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  1741. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  1742. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  1743. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) ARdata = 0;
  1744. }
  1745. }
  1746. }
  1747. if(SiS_Pr->ChipType >= SIS_661) {
  1748. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToTV | SetCRT2ToLCD)) {
  1749. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) ARdata = 0;
  1750. }
  1751. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  1752. if(SiS_Pr->ChipType >= SIS_315H) {
  1753. if(IS_SIS550650740660) {
  1754. /* 315, 330 don't do this */
  1755. if(SiS_Pr->SiS_VBType & VB_SIS30xB) {
  1756. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) ARdata = 0;
  1757. } else {
  1758. ARdata = 0;
  1759. }
  1760. }
  1761. } else {
  1762. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) ARdata = 0;
  1763. }
  1764. }
  1765. }
  1766. SiS_GetRegByte(SiS_Pr->SiS_P3da); /* reset 3da */
  1767. SiS_SetRegByte(SiS_Pr->SiS_P3c0,i); /* set index */
  1768. SiS_SetRegByte(SiS_Pr->SiS_P3c0,ARdata); /* set data */
  1769. }
  1770. SiS_GetRegByte(SiS_Pr->SiS_P3da); /* reset 3da */
  1771. SiS_SetRegByte(SiS_Pr->SiS_P3c0,0x14); /* set index */
  1772. SiS_SetRegByte(SiS_Pr->SiS_P3c0,0x00); /* set data */
  1773. SiS_GetRegByte(SiS_Pr->SiS_P3da);
  1774. SiS_SetRegByte(SiS_Pr->SiS_P3c0,0x20); /* Enable Attribute */
  1775. SiS_GetRegByte(SiS_Pr->SiS_P3da);
  1776. }
  1777. /*********************************************/
  1778. /* GRC */
  1779. /*********************************************/
  1780. static void
  1781. SiS_SetGRCRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex)
  1782. {
  1783. unsigned char GRdata;
  1784. unsigned short i;
  1785. for(i = 0; i <= 0x08; i++) {
  1786. GRdata = SiS_Pr->SiS_StandTable[StandTableIndex].GRC[i];
  1787. SiS_SetReg(SiS_Pr->SiS_P3ce,i,GRdata);
  1788. }
  1789. if(SiS_Pr->SiS_ModeType > ModeVGA) {
  1790. /* 256 color disable */
  1791. SiS_SetRegAND(SiS_Pr->SiS_P3ce,0x05,0xBF);
  1792. }
  1793. }
  1794. /*********************************************/
  1795. /* CLEAR EXTENDED REGISTERS */
  1796. /*********************************************/
  1797. static void
  1798. SiS_ClearExt1Regs(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  1799. {
  1800. unsigned short i;
  1801. for(i = 0x0A; i <= 0x0E; i++) {
  1802. SiS_SetReg(SiS_Pr->SiS_P3c4,i,0x00);
  1803. }
  1804. if(SiS_Pr->ChipType >= SIS_315H) {
  1805. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x37,0xFE);
  1806. if(ModeNo <= 0x13) {
  1807. if(ModeNo == 0x06 || ModeNo >= 0x0e) {
  1808. SiS_SetReg(SiS_Pr->SiS_P3c4,0x0e,0x20);
  1809. }
  1810. }
  1811. }
  1812. }
  1813. /*********************************************/
  1814. /* RESET VCLK */
  1815. /*********************************************/
  1816. static void
  1817. SiS_ResetCRT1VCLK(struct SiS_Private *SiS_Pr)
  1818. {
  1819. if(SiS_Pr->ChipType >= SIS_315H) {
  1820. if(SiS_Pr->ChipType < SIS_661) {
  1821. if(SiS_Pr->SiS_IF_DEF_LVDS == 0) return;
  1822. }
  1823. } else {
  1824. if((SiS_Pr->SiS_IF_DEF_LVDS == 0) &&
  1825. (!(SiS_Pr->SiS_VBType & VB_SIS30xBLV)) ) {
  1826. return;
  1827. }
  1828. }
  1829. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x31,0xcf,0x20);
  1830. SiS_SetReg(SiS_Pr->SiS_P3c4,0x2B,SiS_Pr->SiS_VCLKData[1].SR2B);
  1831. SiS_SetReg(SiS_Pr->SiS_P3c4,0x2C,SiS_Pr->SiS_VCLKData[1].SR2C);
  1832. SiS_SetReg(SiS_Pr->SiS_P3c4,0x2D,0x80);
  1833. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x31,0xcf,0x10);
  1834. SiS_SetReg(SiS_Pr->SiS_P3c4,0x2B,SiS_Pr->SiS_VCLKData[0].SR2B);
  1835. SiS_SetReg(SiS_Pr->SiS_P3c4,0x2C,SiS_Pr->SiS_VCLKData[0].SR2C);
  1836. SiS_SetReg(SiS_Pr->SiS_P3c4,0x2D,0x80);
  1837. }
  1838. /*********************************************/
  1839. /* SYNC */
  1840. /*********************************************/
  1841. static void
  1842. SiS_SetCRT1Sync(struct SiS_Private *SiS_Pr, unsigned short RRTI)
  1843. {
  1844. unsigned short sync;
  1845. if(SiS_Pr->UseCustomMode) {
  1846. sync = SiS_Pr->CInfoFlag >> 8;
  1847. } else {
  1848. sync = SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag >> 8;
  1849. }
  1850. sync &= 0xC0;
  1851. sync |= 0x2f;
  1852. SiS_SetRegByte(SiS_Pr->SiS_P3c2,sync);
  1853. }
  1854. /*********************************************/
  1855. /* CRTC/2 */
  1856. /*********************************************/
  1857. static void
  1858. SiS_SetCRT1CRTC(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  1859. unsigned short ModeIdIndex, unsigned short RRTI)
  1860. {
  1861. unsigned short temp, i, j, modeflag;
  1862. unsigned char *crt1data = NULL;
  1863. modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
  1864. if(SiS_Pr->UseCustomMode) {
  1865. crt1data = &SiS_Pr->CCRT1CRTC[0];
  1866. } else {
  1867. temp = SiS_GetRefCRT1CRTC(SiS_Pr, RRTI, SiS_Pr->SiS_UseWide);
  1868. /* Alternate for 1600x1200 LCDA */
  1869. if((temp == 0x20) && (SiS_Pr->Alternate1600x1200)) temp = 0x57;
  1870. crt1data = (unsigned char *)&SiS_Pr->SiS_CRT1Table[temp].CR[0];
  1871. }
  1872. /* unlock cr0-7 */
  1873. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x11,0x7f);
  1874. for(i = 0, j = 0; i <= 7; i++, j++) {
  1875. SiS_SetReg(SiS_Pr->SiS_P3d4,j,crt1data[i]);
  1876. }
  1877. for(j = 0x10; i <= 10; i++, j++) {
  1878. SiS_SetReg(SiS_Pr->SiS_P3d4,j,crt1data[i]);
  1879. }
  1880. for(j = 0x15; i <= 12; i++, j++) {
  1881. SiS_SetReg(SiS_Pr->SiS_P3d4,j,crt1data[i]);
  1882. }
  1883. for(j = 0x0A; i <= 15; i++, j++) {
  1884. SiS_SetReg(SiS_Pr->SiS_P3c4,j,crt1data[i]);
  1885. }
  1886. SiS_SetReg(SiS_Pr->SiS_P3c4,0x0E,crt1data[16] & 0xE0);
  1887. temp = (crt1data[16] & 0x01) << 5;
  1888. if(modeflag & DoubleScanMode) temp |= 0x80;
  1889. SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x09,0x5F,temp);
  1890. if(SiS_Pr->SiS_ModeType > ModeVGA) {
  1891. SiS_SetReg(SiS_Pr->SiS_P3d4,0x14,0x4F);
  1892. }
  1893. #ifdef CONFIG_FB_SIS_315
  1894. if(SiS_Pr->ChipType == XGI_20) {
  1895. SiS_SetReg(SiS_Pr->SiS_P3d4,0x04,crt1data[4] - 1);
  1896. if(!(temp = crt1data[5] & 0x1f)) {
  1897. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x0c,0xfb);
  1898. }
  1899. SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x05,0xe0,((temp - 1) & 0x1f));
  1900. temp = (crt1data[16] >> 5) + 3;
  1901. if(temp > 7) temp -= 7;
  1902. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0e,0x1f,(temp << 5));
  1903. }
  1904. #endif
  1905. }
  1906. /*********************************************/
  1907. /* OFFSET & PITCH */
  1908. /*********************************************/
  1909. /* (partly overruled by SetPitch() in XF86) */
  1910. /*********************************************/
  1911. static void
  1912. SiS_SetCRT1Offset(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  1913. unsigned short ModeIdIndex, unsigned short RRTI)
  1914. {
  1915. unsigned short temp, DisplayUnit, infoflag;
  1916. if(SiS_Pr->UseCustomMode) {
  1917. infoflag = SiS_Pr->CInfoFlag;
  1918. } else {
  1919. infoflag = SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag;
  1920. }
  1921. DisplayUnit = SiS_GetOffset(SiS_Pr, ModeNo, ModeIdIndex, RRTI);
  1922. temp = (DisplayUnit >> 8) & 0x0f;
  1923. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0E,0xF0,temp);
  1924. SiS_SetReg(SiS_Pr->SiS_P3d4,0x13,DisplayUnit & 0xFF);
  1925. if(infoflag & InterlaceMode) DisplayUnit >>= 1;
  1926. DisplayUnit <<= 5;
  1927. temp = (DisplayUnit >> 8) + 1;
  1928. if(DisplayUnit & 0xff) temp++;
  1929. if(SiS_Pr->ChipType == XGI_20) {
  1930. if(ModeNo == 0x4a || ModeNo == 0x49) temp--;
  1931. }
  1932. SiS_SetReg(SiS_Pr->SiS_P3c4,0x10,temp);
  1933. }
  1934. /*********************************************/
  1935. /* VCLK */
  1936. /*********************************************/
  1937. static void
  1938. SiS_SetCRT1VCLK(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  1939. unsigned short ModeIdIndex, unsigned short RRTI)
  1940. {
  1941. unsigned short index = 0, clka, clkb;
  1942. if(SiS_Pr->UseCustomMode) {
  1943. clka = SiS_Pr->CSR2B;
  1944. clkb = SiS_Pr->CSR2C;
  1945. } else {
  1946. index = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RRTI);
  1947. if((SiS_Pr->SiS_VBType & VB_SIS30xBLV) &&
  1948. (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  1949. /* Alternate for 1600x1200 LCDA */
  1950. if((index == 0x21) && (SiS_Pr->Alternate1600x1200)) index = 0x72;
  1951. clka = SiS_Pr->SiS_VBVCLKData[index].Part4_A;
  1952. clkb = SiS_Pr->SiS_VBVCLKData[index].Part4_B;
  1953. } else {
  1954. clka = SiS_Pr->SiS_VCLKData[index].SR2B;
  1955. clkb = SiS_Pr->SiS_VCLKData[index].SR2C;
  1956. }
  1957. }
  1958. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x31,0xCF);
  1959. SiS_SetReg(SiS_Pr->SiS_P3c4,0x2b,clka);
  1960. SiS_SetReg(SiS_Pr->SiS_P3c4,0x2c,clkb);
  1961. if(SiS_Pr->ChipType >= SIS_315H) {
  1962. #ifdef CONFIG_FB_SIS_315
  1963. SiS_SetReg(SiS_Pr->SiS_P3c4,0x2D,0x01);
  1964. if(SiS_Pr->ChipType == XGI_20) {
  1965. unsigned short mf = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
  1966. if(mf & HalfDCLK) {
  1967. SiS_SetReg(SiS_Pr->SiS_P3c4,0x2b,SiS_GetReg(SiS_Pr->SiS_P3c4,0x2b));
  1968. clkb = SiS_GetReg(SiS_Pr->SiS_P3c4,0x2c);
  1969. clkb = (((clkb & 0x1f) << 1) + 1) | (clkb & 0xe0);
  1970. SiS_SetReg(SiS_Pr->SiS_P3c4,0x2c,clkb);
  1971. }
  1972. }
  1973. #endif
  1974. } else {
  1975. SiS_SetReg(SiS_Pr->SiS_P3c4,0x2D,0x80);
  1976. }
  1977. }
  1978. /*********************************************/
  1979. /* FIFO */
  1980. /*********************************************/
  1981. #ifdef CONFIG_FB_SIS_300
  1982. void
  1983. SiS_GetFIFOThresholdIndex300(struct SiS_Private *SiS_Pr, unsigned short *idx1,
  1984. unsigned short *idx2)
  1985. {
  1986. unsigned short temp1, temp2;
  1987. static const unsigned char ThTiming[8] = {
  1988. 1, 2, 2, 3, 0, 1, 1, 2
  1989. };
  1990. temp1 = temp2 = (SiS_GetReg(SiS_Pr->SiS_P3c4,0x18) & 0x62) >> 1;
  1991. (*idx2) = (unsigned short)(ThTiming[((temp2 >> 3) | temp1) & 0x07]);
  1992. (*idx1) = (unsigned short)(SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) >> 6) & 0x03;
  1993. (*idx1) |= (unsigned short)(((SiS_GetReg(SiS_Pr->SiS_P3c4,0x14) >> 4) & 0x0c));
  1994. (*idx1) <<= 1;
  1995. }
  1996. static unsigned short
  1997. SiS_GetFIFOThresholdA300(unsigned short idx1, unsigned short idx2)
  1998. {
  1999. static const unsigned char ThLowA[8 * 3] = {
  2000. 61, 3,52, 5,68, 7,100,11,
  2001. 43, 3,42, 5,54, 7, 78,11,
  2002. 34, 3,37, 5,47, 7, 67,11
  2003. };
  2004. return (unsigned short)((ThLowA[idx1 + 1] * idx2) + ThLowA[idx1]);
  2005. }
  2006. unsigned short
  2007. SiS_GetFIFOThresholdB300(unsigned short idx1, unsigned short idx2)
  2008. {
  2009. static const unsigned char ThLowB[8 * 3] = {
  2010. 81, 4,72, 6,88, 8,120,12,
  2011. 55, 4,54, 6,66, 8, 90,12,
  2012. 42, 4,45, 6,55, 8, 75,12
  2013. };
  2014. return (unsigned short)((ThLowB[idx1 + 1] * idx2) + ThLowB[idx1]);
  2015. }
  2016. static unsigned short
  2017. SiS_DoCalcDelay(struct SiS_Private *SiS_Pr, unsigned short MCLK, unsigned short VCLK,
  2018. unsigned short colordepth, unsigned short key)
  2019. {
  2020. unsigned short idx1, idx2;
  2021. unsigned int longtemp = VCLK * colordepth;
  2022. SiS_GetFIFOThresholdIndex300(SiS_Pr, &idx1, &idx2);
  2023. if(key == 0) {
  2024. longtemp *= SiS_GetFIFOThresholdA300(idx1, idx2);
  2025. } else {
  2026. longtemp *= SiS_GetFIFOThresholdB300(idx1, idx2);
  2027. }
  2028. idx1 = longtemp % (MCLK * 16);
  2029. longtemp /= (MCLK * 16);
  2030. if(idx1) longtemp++;
  2031. return (unsigned short)longtemp;
  2032. }
  2033. static unsigned short
  2034. SiS_CalcDelay(struct SiS_Private *SiS_Pr, unsigned short VCLK,
  2035. unsigned short colordepth, unsigned short MCLK)
  2036. {
  2037. unsigned short temp1, temp2;
  2038. temp2 = SiS_DoCalcDelay(SiS_Pr, MCLK, VCLK, colordepth, 0);
  2039. temp1 = SiS_DoCalcDelay(SiS_Pr, MCLK, VCLK, colordepth, 1);
  2040. if(temp1 < 4) temp1 = 4;
  2041. temp1 -= 4;
  2042. if(temp2 < temp1) temp2 = temp1;
  2043. return temp2;
  2044. }
  2045. static void
  2046. SiS_SetCRT1FIFO_300(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  2047. unsigned short RefreshRateTableIndex)
  2048. {
  2049. unsigned short ThresholdLow = 0;
  2050. unsigned short temp, index, VCLK, MCLK, colorth;
  2051. static const unsigned short colortharray[6] = { 1, 1, 2, 2, 3, 4 };
  2052. if(ModeNo > 0x13) {
  2053. /* Get VCLK */
  2054. if(SiS_Pr->UseCustomMode) {
  2055. VCLK = SiS_Pr->CSRClock;
  2056. } else {
  2057. index = SiS_GetRefCRTVCLK(SiS_Pr, RefreshRateTableIndex, SiS_Pr->SiS_UseWide);
  2058. VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK;
  2059. }
  2060. /* Get half colordepth */
  2061. colorth = colortharray[(SiS_Pr->SiS_ModeType - ModeEGA)];
  2062. /* Get MCLK */
  2063. index = SiS_GetReg(SiS_Pr->SiS_P3c4,0x3A) & 0x07;
  2064. MCLK = SiS_Pr->SiS_MCLKData_0[index].CLOCK;
  2065. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35) & 0xc3;
  2066. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x16,0x3c,temp);
  2067. do {
  2068. ThresholdLow = SiS_CalcDelay(SiS_Pr, VCLK, colorth, MCLK) + 1;
  2069. if(ThresholdLow < 0x13) break;
  2070. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x16,0xfc);
  2071. ThresholdLow = 0x13;
  2072. temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) >> 6;
  2073. if(!temp) break;
  2074. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x16,0x3f,((temp - 1) << 6));
  2075. } while(0);
  2076. } else ThresholdLow = 2;
  2077. /* Write CRT/CPU threshold low, CRT/Engine threshold high */
  2078. temp = (ThresholdLow << 4) | 0x0f;
  2079. SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,temp);
  2080. temp = (ThresholdLow & 0x10) << 1;
  2081. if(ModeNo > 0x13) temp |= 0x40;
  2082. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0f,0x9f,temp);
  2083. /* What is this? */
  2084. SiS_SetReg(SiS_Pr->SiS_P3c4,0x3B,0x09);
  2085. /* Write CRT/CPU threshold high */
  2086. temp = ThresholdLow + 3;
  2087. if(temp > 0x0f) temp = 0x0f;
  2088. SiS_SetReg(SiS_Pr->SiS_P3c4,0x09,temp);
  2089. }
  2090. unsigned short
  2091. SiS_GetLatencyFactor630(struct SiS_Private *SiS_Pr, unsigned short index)
  2092. {
  2093. static const unsigned char LatencyFactor[] = {
  2094. 97, 88, 86, 79, 77, 0, /* 64 bit BQ=2 */
  2095. 0, 87, 85, 78, 76, 54, /* 64 bit BQ=1 */
  2096. 97, 88, 86, 79, 77, 0, /* 128 bit BQ=2 */
  2097. 0, 79, 77, 70, 68, 48, /* 128 bit BQ=1 */
  2098. 80, 72, 69, 63, 61, 0, /* 64 bit BQ=2 */
  2099. 0, 70, 68, 61, 59, 37, /* 64 bit BQ=1 */
  2100. 86, 77, 75, 68, 66, 0, /* 128 bit BQ=2 */
  2101. 0, 68, 66, 59, 57, 37 /* 128 bit BQ=1 */
  2102. };
  2103. static const unsigned char LatencyFactor730[] = {
  2104. 69, 63, 61,
  2105. 86, 79, 77,
  2106. 103, 96, 94,
  2107. 120,113,111,
  2108. 137,130,128
  2109. };
  2110. if(SiS_Pr->ChipType == SIS_730) {
  2111. return (unsigned short)LatencyFactor730[index];
  2112. } else {
  2113. return (unsigned short)LatencyFactor[index];
  2114. }
  2115. }
  2116. static unsigned short
  2117. SiS_CalcDelay2(struct SiS_Private *SiS_Pr, unsigned char key)
  2118. {
  2119. unsigned short index;
  2120. if(SiS_Pr->ChipType == SIS_730) {
  2121. index = ((key & 0x0f) * 3) + ((key & 0xc0) >> 6);
  2122. } else {
  2123. index = (key & 0xe0) >> 5;
  2124. if(key & 0x10) index += 6;
  2125. if(!(key & 0x01)) index += 24;
  2126. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x14) & 0x80) index += 12;
  2127. }
  2128. return SiS_GetLatencyFactor630(SiS_Pr, index);
  2129. }
  2130. static void
  2131. SiS_SetCRT1FIFO_630(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  2132. unsigned short RefreshRateTableIndex)
  2133. {
  2134. unsigned short ThresholdLow = 0;
  2135. unsigned short i, data, VCLK, MCLK16, colorth = 0;
  2136. unsigned int templ, datal;
  2137. const unsigned char *queuedata = NULL;
  2138. static const unsigned char FQBQData[21] = {
  2139. 0x01,0x21,0x41,0x61,0x81,
  2140. 0x31,0x51,0x71,0x91,0xb1,
  2141. 0x00,0x20,0x40,0x60,0x80,
  2142. 0x30,0x50,0x70,0x90,0xb0,
  2143. 0xff
  2144. };
  2145. static const unsigned char FQBQData730[16] = {
  2146. 0x34,0x74,0xb4,
  2147. 0x23,0x63,0xa3,
  2148. 0x12,0x52,0x92,
  2149. 0x01,0x41,0x81,
  2150. 0x00,0x40,0x80,
  2151. 0xff
  2152. };
  2153. static const unsigned short colortharray[6] = {
  2154. 1, 1, 2, 2, 3, 4
  2155. };
  2156. i = 0;
  2157. if(ModeNo > 0x13) {
  2158. /* Get VCLK */
  2159. if(SiS_Pr->UseCustomMode) {
  2160. VCLK = SiS_Pr->CSRClock;
  2161. } else {
  2162. data = SiS_GetRefCRTVCLK(SiS_Pr, RefreshRateTableIndex, SiS_Pr->SiS_UseWide);
  2163. VCLK = SiS_Pr->SiS_VCLKData[data].CLOCK;
  2164. }
  2165. /* Get MCLK * 16 */
  2166. data = SiS_GetReg(SiS_Pr->SiS_P3c4,0x1A) & 0x07;
  2167. MCLK16 = SiS_Pr->SiS_MCLKData_0[data].CLOCK * 16;
  2168. /* Get half colordepth */
  2169. colorth = colortharray[(SiS_Pr->SiS_ModeType - ModeEGA)];
  2170. if(SiS_Pr->ChipType == SIS_730) {
  2171. queuedata = &FQBQData730[0];
  2172. } else {
  2173. queuedata = &FQBQData[0];
  2174. }
  2175. do {
  2176. templ = SiS_CalcDelay2(SiS_Pr, queuedata[i]) * VCLK * colorth;
  2177. datal = templ % MCLK16;
  2178. templ = (templ / MCLK16) + 1;
  2179. if(datal) templ++;
  2180. if(templ > 0x13) {
  2181. if(queuedata[i + 1] == 0xFF) {
  2182. ThresholdLow = 0x13;
  2183. break;
  2184. }
  2185. i++;
  2186. } else {
  2187. ThresholdLow = templ;
  2188. break;
  2189. }
  2190. } while(queuedata[i] != 0xFF);
  2191. } else {
  2192. if(SiS_Pr->ChipType != SIS_730) i = 9;
  2193. ThresholdLow = 0x02;
  2194. }
  2195. /* Write CRT/CPU threshold low, CRT/Engine threshold high */
  2196. data = ((ThresholdLow & 0x0f) << 4) | 0x0f;
  2197. SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,data);
  2198. data = (ThresholdLow & 0x10) << 1;
  2199. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0F,0xDF,data);
  2200. /* What is this? */
  2201. SiS_SetReg(SiS_Pr->SiS_P3c4,0x3B,0x09);
  2202. /* Write CRT/CPU threshold high (gap = 3) */
  2203. data = ThresholdLow + 3;
  2204. if(data > 0x0f) data = 0x0f;
  2205. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x09,0x80,data);
  2206. /* Write foreground and background queue */
  2207. templ = sisfb_read_nbridge_pci_dword(SiS_Pr, 0x50);
  2208. if(SiS_Pr->ChipType == SIS_730) {
  2209. templ &= 0xfffff9ff;
  2210. templ |= ((queuedata[i] & 0xc0) << 3);
  2211. } else {
  2212. templ &= 0xf0ffffff;
  2213. if( (ModeNo <= 0x13) &&
  2214. (SiS_Pr->ChipType == SIS_630) &&
  2215. (SiS_Pr->ChipRevision >= 0x30) ) {
  2216. templ |= 0x0b000000;
  2217. } else {
  2218. templ |= ((queuedata[i] & 0xf0) << 20);
  2219. }
  2220. }
  2221. sisfb_write_nbridge_pci_dword(SiS_Pr, 0x50, templ);
  2222. templ = sisfb_read_nbridge_pci_dword(SiS_Pr, 0xA0);
  2223. /* GUI grant timer (PCI config 0xA3) */
  2224. if(SiS_Pr->ChipType == SIS_730) {
  2225. templ &= 0x00ffffff;
  2226. datal = queuedata[i] << 8;
  2227. templ |= (((datal & 0x0f00) | ((datal & 0x3000) >> 8)) << 20);
  2228. } else {
  2229. templ &= 0xf0ffffff;
  2230. templ |= ((queuedata[i] & 0x0f) << 24);
  2231. }
  2232. sisfb_write_nbridge_pci_dword(SiS_Pr, 0xA0, templ);
  2233. }
  2234. #endif /* CONFIG_FB_SIS_300 */
  2235. #ifdef CONFIG_FB_SIS_315
  2236. static void
  2237. SiS_SetCRT1FIFO_310(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  2238. {
  2239. unsigned short modeflag;
  2240. /* disable auto-threshold */
  2241. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x3D,0xFE);
  2242. modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
  2243. SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,0xAE);
  2244. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x09,0xF0);
  2245. if(ModeNo > 0x13) {
  2246. if(SiS_Pr->ChipType >= XGI_20) {
  2247. SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,0x34);
  2248. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x3D,0x01);
  2249. } else if(SiS_Pr->ChipType >= SIS_661) {
  2250. if(!(modeflag & HalfDCLK)) {
  2251. SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,0x34);
  2252. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x3D,0x01);
  2253. }
  2254. } else {
  2255. if((!(modeflag & DoubleScanMode)) || (!(modeflag & HalfDCLK))) {
  2256. SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,0x34);
  2257. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x3D,0x01);
  2258. }
  2259. }
  2260. }
  2261. }
  2262. #endif
  2263. /*********************************************/
  2264. /* MODE REGISTERS */
  2265. /*********************************************/
  2266. static void
  2267. SiS_SetVCLKState(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  2268. unsigned short RefreshRateTableIndex, unsigned short ModeIdIndex)
  2269. {
  2270. unsigned short data = 0, VCLK = 0, index = 0;
  2271. if(ModeNo > 0x13) {
  2272. if(SiS_Pr->UseCustomMode) {
  2273. VCLK = SiS_Pr->CSRClock;
  2274. } else {
  2275. index = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  2276. VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK;
  2277. }
  2278. }
  2279. if(SiS_Pr->ChipType < SIS_315H) {
  2280. #ifdef CONFIG_FB_SIS_300
  2281. if(VCLK > 150) data |= 0x80;
  2282. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x07,0x7B,data);
  2283. data = 0x00;
  2284. if(VCLK >= 150) data |= 0x08;
  2285. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x32,0xF7,data);
  2286. #endif
  2287. } else if(SiS_Pr->ChipType < XGI_20) {
  2288. #ifdef CONFIG_FB_SIS_315
  2289. if(VCLK >= 166) data |= 0x0c;
  2290. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x32,0xf3,data);
  2291. if(VCLK >= 166) {
  2292. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1f,0xe7);
  2293. }
  2294. #endif
  2295. } else {
  2296. #ifdef CONFIG_FB_SIS_315
  2297. if(VCLK >= 200) data |= 0x0c;
  2298. if(SiS_Pr->ChipType == XGI_20) data &= ~0x04;
  2299. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x32,0xf3,data);
  2300. if(SiS_Pr->ChipType != XGI_20) {
  2301. data = SiS_GetReg(SiS_Pr->SiS_P3c4,0x1f) & 0xe7;
  2302. if(VCLK < 200) data |= 0x10;
  2303. SiS_SetReg(SiS_Pr->SiS_P3c4,0x1f,data);
  2304. }
  2305. #endif
  2306. }
  2307. /* DAC speed */
  2308. if(SiS_Pr->ChipType >= SIS_661) {
  2309. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x07,0xE8,0x10);
  2310. } else {
  2311. data = 0x03;
  2312. if(VCLK >= 260) data = 0x00;
  2313. else if(VCLK >= 160) data = 0x01;
  2314. else if(VCLK >= 135) data = 0x02;
  2315. if(SiS_Pr->ChipType == SIS_540) {
  2316. if((VCLK == 203) || (VCLK < 234)) data = 0x02;
  2317. }
  2318. if(SiS_Pr->ChipType < SIS_315H) {
  2319. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x07,0xFC,data);
  2320. } else {
  2321. if(SiS_Pr->ChipType > SIS_315PRO) {
  2322. if(ModeNo > 0x13) data &= 0xfc;
  2323. }
  2324. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x07,0xF8,data);
  2325. }
  2326. }
  2327. }
  2328. static void
  2329. SiS_SetCRT1ModeRegs(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  2330. unsigned short ModeIdIndex, unsigned short RRTI)
  2331. {
  2332. unsigned short data, infoflag = 0, modeflag, resindex;
  2333. #ifdef CONFIG_FB_SIS_315
  2334. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  2335. unsigned short data2, data3;
  2336. #endif
  2337. modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
  2338. if(SiS_Pr->UseCustomMode) {
  2339. infoflag = SiS_Pr->CInfoFlag;
  2340. } else {
  2341. resindex = SiS_GetResInfo(SiS_Pr, ModeNo, ModeIdIndex);
  2342. if(ModeNo > 0x13) {
  2343. infoflag = SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag;
  2344. }
  2345. }
  2346. /* Disable DPMS */
  2347. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1F,0x3F);
  2348. data = 0;
  2349. if(ModeNo > 0x13) {
  2350. if(SiS_Pr->SiS_ModeType > ModeEGA) {
  2351. data |= 0x02;
  2352. data |= ((SiS_Pr->SiS_ModeType - ModeVGA) << 2);
  2353. }
  2354. if(infoflag & InterlaceMode) data |= 0x20;
  2355. }
  2356. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x06,0xC0,data);
  2357. if(SiS_Pr->ChipType != SIS_300) {
  2358. data = 0;
  2359. if(infoflag & InterlaceMode) {
  2360. /* data = (Hsync / 8) - ((Htotal / 8) / 2) + 3 */
  2361. int hrs = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x04) |
  2362. ((SiS_GetReg(SiS_Pr->SiS_P3c4,0x0b) & 0xc0) << 2)) - 3;
  2363. int hto = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x00) |
  2364. ((SiS_GetReg(SiS_Pr->SiS_P3c4,0x0b) & 0x03) << 8)) + 5;
  2365. data = hrs - (hto >> 1) + 3;
  2366. }
  2367. SiS_SetReg(SiS_Pr->SiS_P3d4,0x19,data);
  2368. SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x1a,0xFC,((data >> 8) & 0x03));
  2369. }
  2370. if(modeflag & HalfDCLK) {
  2371. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x01,0x08);
  2372. }
  2373. data = 0;
  2374. if(modeflag & LineCompareOff) data = 0x08;
  2375. if(SiS_Pr->ChipType == SIS_300) {
  2376. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0F,0xF7,data);
  2377. } else {
  2378. if(SiS_Pr->ChipType >= XGI_20) data |= 0x20;
  2379. if(SiS_Pr->SiS_ModeType == ModeEGA) {
  2380. if(ModeNo > 0x13) {
  2381. data |= 0x40;
  2382. }
  2383. }
  2384. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0F,0xB7,data);
  2385. }
  2386. #ifdef CONFIG_FB_SIS_315
  2387. if(SiS_Pr->ChipType >= SIS_315H) {
  2388. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x31,0xfb);
  2389. }
  2390. if(SiS_Pr->ChipType == SIS_315PRO) {
  2391. data = SiS_Pr->SiS_SR15[(2 * 4) + SiS_Get310DRAMType(SiS_Pr)];
  2392. if(SiS_Pr->SiS_ModeType == ModeText) {
  2393. data &= 0xc7;
  2394. } else {
  2395. data2 = SiS_GetOffset(SiS_Pr, ModeNo, ModeIdIndex, RRTI) >> 1;
  2396. if(infoflag & InterlaceMode) data2 >>= 1;
  2397. data3 = SiS_GetColorDepth(SiS_Pr, ModeNo, ModeIdIndex) >> 1;
  2398. if(data3) data2 /= data3;
  2399. if(data2 >= 0x50) {
  2400. data &= 0x0f;
  2401. data |= 0x50;
  2402. }
  2403. }
  2404. SiS_SetReg(SiS_Pr->SiS_P3c4,0x17,data);
  2405. } else if((SiS_Pr->ChipType == SIS_330) || (SiS_Pr->SiS_SysFlags & SF_760LFB)) {
  2406. data = SiS_Get310DRAMType(SiS_Pr);
  2407. if(SiS_Pr->ChipType == SIS_330) {
  2408. data = SiS_Pr->SiS_SR15[(2 * 4) + data];
  2409. } else {
  2410. if(SiS_Pr->SiS_ROMNew) data = ROMAddr[0xf6];
  2411. else if(SiS_Pr->SiS_UseROM) data = ROMAddr[0x100 + data];
  2412. else data = 0xba;
  2413. }
  2414. if(SiS_Pr->SiS_ModeType <= ModeEGA) {
  2415. data &= 0xc7;
  2416. } else {
  2417. if(SiS_Pr->UseCustomMode) {
  2418. data2 = SiS_Pr->CSRClock;
  2419. } else {
  2420. data2 = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RRTI);
  2421. data2 = SiS_Pr->SiS_VCLKData[data2].CLOCK;
  2422. }
  2423. data3 = SiS_GetColorDepth(SiS_Pr, ModeNo, ModeIdIndex) >> 1;
  2424. if(data3) data2 *= data3;
  2425. data2 = ((unsigned int)(SiS_GetMCLK(SiS_Pr) * 1024)) / data2;
  2426. if(SiS_Pr->ChipType == SIS_330) {
  2427. if(SiS_Pr->SiS_ModeType != Mode16Bpp) {
  2428. if (data2 >= 0x19c) data = 0xba;
  2429. else if(data2 >= 0x140) data = 0x7a;
  2430. else if(data2 >= 0x101) data = 0x3a;
  2431. else if(data2 >= 0xf5) data = 0x32;
  2432. else if(data2 >= 0xe2) data = 0x2a;
  2433. else if(data2 >= 0xc4) data = 0x22;
  2434. else if(data2 >= 0xac) data = 0x1a;
  2435. else if(data2 >= 0x9e) data = 0x12;
  2436. else if(data2 >= 0x8e) data = 0x0a;
  2437. else data = 0x02;
  2438. } else {
  2439. if(data2 >= 0x127) data = 0xba;
  2440. else data = 0x7a;
  2441. }
  2442. } else { /* 76x+LFB */
  2443. if (data2 >= 0x190) data = 0xba;
  2444. else if(data2 >= 0xff) data = 0x7a;
  2445. else if(data2 >= 0xd3) data = 0x3a;
  2446. else if(data2 >= 0xa9) data = 0x1a;
  2447. else if(data2 >= 0x93) data = 0x0a;
  2448. else data = 0x02;
  2449. }
  2450. }
  2451. SiS_SetReg(SiS_Pr->SiS_P3c4,0x17,data);
  2452. }
  2453. /* XGI: Nothing. */
  2454. /* TODO: Check SiS340 */
  2455. #endif
  2456. data = 0x60;
  2457. if(SiS_Pr->SiS_ModeType != ModeText) {
  2458. data ^= 0x60;
  2459. if(SiS_Pr->SiS_ModeType != ModeEGA) {
  2460. data ^= 0xA0;
  2461. }
  2462. }
  2463. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x21,0x1F,data);
  2464. SiS_SetVCLKState(SiS_Pr, ModeNo, RRTI, ModeIdIndex);
  2465. #ifdef CONFIG_FB_SIS_315
  2466. if(((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->ChipType < SIS_661)) ||
  2467. (SiS_Pr->ChipType == XGI_40)) {
  2468. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40) {
  2469. SiS_SetReg(SiS_Pr->SiS_P3d4,0x52,0x2c);
  2470. } else {
  2471. SiS_SetReg(SiS_Pr->SiS_P3d4,0x52,0x6c);
  2472. }
  2473. } else if(SiS_Pr->ChipType == XGI_20) {
  2474. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40) {
  2475. SiS_SetReg(SiS_Pr->SiS_P3d4,0x52,0x33);
  2476. } else {
  2477. SiS_SetReg(SiS_Pr->SiS_P3d4,0x52,0x73);
  2478. }
  2479. SiS_SetReg(SiS_Pr->SiS_P3d4,0x51,0x02);
  2480. }
  2481. #endif
  2482. }
  2483. #ifdef CONFIG_FB_SIS_315
  2484. static void
  2485. SiS_SetupDualChip(struct SiS_Private *SiS_Pr)
  2486. {
  2487. #if 0
  2488. /* TODO: Find out about IOAddress2 */
  2489. SISIOADDRESS P2_3c2 = SiS_Pr->IOAddress2 + 0x12;
  2490. SISIOADDRESS P2_3c4 = SiS_Pr->IOAddress2 + 0x14;
  2491. SISIOADDRESS P2_3ce = SiS_Pr->IOAddress2 + 0x1e;
  2492. int i;
  2493. if((SiS_Pr->ChipRevision != 0) ||
  2494. (!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x3a) & 0x04)))
  2495. return;
  2496. for(i = 0; i <= 4; i++) { /* SR00 - SR04 */
  2497. SiS_SetReg(P2_3c4,i,SiS_GetReg(SiS_Pr->SiS_P3c4,i));
  2498. }
  2499. for(i = 0; i <= 8; i++) { /* GR00 - GR08 */
  2500. SiS_SetReg(P2_3ce,i,SiS_GetReg(SiS_Pr->SiS_P3ce,i));
  2501. }
  2502. SiS_SetReg(P2_3c4,0x05,0x86);
  2503. SiS_SetReg(P2_3c4,0x06,SiS_GetReg(SiS_Pr->SiS_P3c4,0x06)); /* SR06 */
  2504. SiS_SetReg(P2_3c4,0x21,SiS_GetReg(SiS_Pr->SiS_P3c4,0x21)); /* SR21 */
  2505. SiS_SetRegByte(P2_3c2,SiS_GetRegByte(SiS_Pr->SiS_P3cc)); /* MISC */
  2506. SiS_SetReg(P2_3c4,0x05,0x00);
  2507. #endif
  2508. }
  2509. #endif
  2510. /*********************************************/
  2511. /* LOAD DAC */
  2512. /*********************************************/
  2513. static void
  2514. SiS_WriteDAC(struct SiS_Private *SiS_Pr, SISIOADDRESS DACData, unsigned short shiftflag,
  2515. unsigned short dl, unsigned short ah, unsigned short al, unsigned short dh)
  2516. {
  2517. unsigned short d1, d2, d3;
  2518. switch(dl) {
  2519. case 0: d1 = dh; d2 = ah; d3 = al; break;
  2520. case 1: d1 = ah; d2 = al; d3 = dh; break;
  2521. default: d1 = al; d2 = dh; d3 = ah;
  2522. }
  2523. SiS_SetRegByte(DACData, (d1 << shiftflag));
  2524. SiS_SetRegByte(DACData, (d2 << shiftflag));
  2525. SiS_SetRegByte(DACData, (d3 << shiftflag));
  2526. }
  2527. void
  2528. SiS_LoadDAC(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  2529. {
  2530. unsigned short data, data2, time, i, j, k, m, n, o;
  2531. unsigned short si, di, bx, sf;
  2532. SISIOADDRESS DACAddr, DACData;
  2533. const unsigned char *table = NULL;
  2534. data = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex) & DACInfoFlag;
  2535. j = time = 64;
  2536. if(data == 0x00) table = SiS_MDA_DAC;
  2537. else if(data == 0x08) table = SiS_CGA_DAC;
  2538. else if(data == 0x10) table = SiS_EGA_DAC;
  2539. else if(data == 0x18) {
  2540. j = 16;
  2541. time = 256;
  2542. table = SiS_VGA_DAC;
  2543. }
  2544. if( ( (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && /* 301B-DH LCD */
  2545. (SiS_Pr->SiS_VBType & VB_NoLCD) ) ||
  2546. (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) || /* LCDA */
  2547. (!(SiS_Pr->SiS_SetFlag & ProgrammingCRT2)) ) { /* Programming CRT1 */
  2548. SiS_SetRegByte(SiS_Pr->SiS_P3c6,0xFF);
  2549. DACAddr = SiS_Pr->SiS_P3c8;
  2550. DACData = SiS_Pr->SiS_P3c9;
  2551. sf = 0;
  2552. } else {
  2553. DACAddr = SiS_Pr->SiS_Part5Port;
  2554. DACData = SiS_Pr->SiS_Part5Port + 1;
  2555. sf = 2;
  2556. }
  2557. SiS_SetRegByte(DACAddr,0x00);
  2558. for(i = 0; i < j; i++) {
  2559. data = table[i];
  2560. for(k = 0; k < 3; k++) {
  2561. data2 = 0;
  2562. if(data & 0x01) data2 += 0x2A;
  2563. if(data & 0x02) data2 += 0x15;
  2564. SiS_SetRegByte(DACData, (data2 << sf));
  2565. data >>= 2;
  2566. }
  2567. }
  2568. if(time == 256) {
  2569. for(i = 16; i < 32; i++) {
  2570. data = table[i] << sf;
  2571. for(k = 0; k < 3; k++) SiS_SetRegByte(DACData, data);
  2572. }
  2573. si = 32;
  2574. for(m = 0; m < 9; m++) {
  2575. di = si;
  2576. bx = si + 4;
  2577. for(n = 0; n < 3; n++) {
  2578. for(o = 0; o < 5; o++) {
  2579. SiS_WriteDAC(SiS_Pr, DACData, sf, n, table[di], table[bx], table[si]);
  2580. si++;
  2581. }
  2582. si -= 2;
  2583. for(o = 0; o < 3; o++) {
  2584. SiS_WriteDAC(SiS_Pr, DACData, sf, n, table[di], table[si], table[bx]);
  2585. si--;
  2586. }
  2587. } /* for n < 3 */
  2588. si += 5;
  2589. } /* for m < 9 */
  2590. }
  2591. }
  2592. /*********************************************/
  2593. /* SET CRT1 REGISTER GROUP */
  2594. /*********************************************/
  2595. static void
  2596. SiS_SetCRT1Group(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  2597. {
  2598. unsigned short StandTableIndex, RefreshRateTableIndex;
  2599. SiS_Pr->SiS_CRT1Mode = ModeNo;
  2600. StandTableIndex = SiS_GetModePtr(SiS_Pr, ModeNo, ModeIdIndex);
  2601. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  2602. if(SiS_Pr->SiS_VBInfo & (SetSimuScanMode | SwitchCRT2)) {
  2603. SiS_DisableBridge(SiS_Pr);
  2604. }
  2605. }
  2606. SiS_ResetSegmentRegisters(SiS_Pr);
  2607. SiS_SetSeqRegs(SiS_Pr, StandTableIndex);
  2608. SiS_SetMiscRegs(SiS_Pr, StandTableIndex);
  2609. SiS_SetCRTCRegs(SiS_Pr, StandTableIndex);
  2610. SiS_SetATTRegs(SiS_Pr, StandTableIndex);
  2611. SiS_SetGRCRegs(SiS_Pr, StandTableIndex);
  2612. SiS_ClearExt1Regs(SiS_Pr, ModeNo);
  2613. SiS_ResetCRT1VCLK(SiS_Pr);
  2614. SiS_Pr->SiS_SelectCRT2Rate = 0;
  2615. SiS_Pr->SiS_SetFlag &= (~ProgrammingCRT2);
  2616. if(SiS_Pr->SiS_VBInfo & SetSimuScanMode) {
  2617. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  2618. SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
  2619. }
  2620. }
  2621. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  2622. SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
  2623. }
  2624. RefreshRateTableIndex = SiS_GetRatePtr(SiS_Pr, ModeNo, ModeIdIndex);
  2625. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  2626. SiS_Pr->SiS_SetFlag &= ~ProgrammingCRT2;
  2627. }
  2628. if(RefreshRateTableIndex != 0xFFFF) {
  2629. SiS_SetCRT1Sync(SiS_Pr, RefreshRateTableIndex);
  2630. SiS_SetCRT1CRTC(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  2631. SiS_SetCRT1Offset(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  2632. SiS_SetCRT1VCLK(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  2633. }
  2634. switch(SiS_Pr->ChipType) {
  2635. #ifdef CONFIG_FB_SIS_300
  2636. case SIS_300:
  2637. SiS_SetCRT1FIFO_300(SiS_Pr, ModeNo, RefreshRateTableIndex);
  2638. break;
  2639. case SIS_540:
  2640. case SIS_630:
  2641. case SIS_730:
  2642. SiS_SetCRT1FIFO_630(SiS_Pr, ModeNo, RefreshRateTableIndex);
  2643. break;
  2644. #endif
  2645. default:
  2646. #ifdef CONFIG_FB_SIS_315
  2647. if(SiS_Pr->ChipType == XGI_20) {
  2648. unsigned char sr2b = 0, sr2c = 0;
  2649. switch(ModeNo) {
  2650. case 0x00:
  2651. case 0x01: sr2b = 0x4e; sr2c = 0xe9; break;
  2652. case 0x04:
  2653. case 0x05:
  2654. case 0x0d: sr2b = 0x1b; sr2c = 0xe3; break;
  2655. }
  2656. if(sr2b) {
  2657. SiS_SetReg(SiS_Pr->SiS_P3c4,0x2b,sr2b);
  2658. SiS_SetReg(SiS_Pr->SiS_P3c4,0x2c,sr2c);
  2659. SiS_SetRegByte(SiS_Pr->SiS_P3c2,(SiS_GetRegByte(SiS_Pr->SiS_P3cc) | 0x0c));
  2660. }
  2661. }
  2662. SiS_SetCRT1FIFO_310(SiS_Pr, ModeNo, ModeIdIndex);
  2663. #endif
  2664. break;
  2665. }
  2666. SiS_SetCRT1ModeRegs(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  2667. #ifdef CONFIG_FB_SIS_315
  2668. if(SiS_Pr->ChipType == XGI_40) {
  2669. SiS_SetupDualChip(SiS_Pr);
  2670. }
  2671. #endif
  2672. SiS_LoadDAC(SiS_Pr, ModeNo, ModeIdIndex);
  2673. if(SiS_Pr->SiS_flag_clearbuffer) {
  2674. SiS_ClearBuffer(SiS_Pr, ModeNo);
  2675. }
  2676. if(!(SiS_Pr->SiS_VBInfo & (SetSimuScanMode | SwitchCRT2 | SetCRT2ToLCDA))) {
  2677. SiS_WaitRetrace1(SiS_Pr);
  2678. SiS_DisplayOn(SiS_Pr);
  2679. }
  2680. }
  2681. /*********************************************/
  2682. /* HELPER: VIDEO BRIDGE PROG CLK */
  2683. /*********************************************/
  2684. static void
  2685. SiS_InitVB(struct SiS_Private *SiS_Pr)
  2686. {
  2687. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  2688. SiS_Pr->Init_P4_0E = 0;
  2689. if(SiS_Pr->SiS_ROMNew) {
  2690. SiS_Pr->Init_P4_0E = ROMAddr[0x82];
  2691. } else if(SiS_Pr->ChipType >= XGI_40) {
  2692. if(SiS_Pr->SiS_XGIROM) {
  2693. SiS_Pr->Init_P4_0E = ROMAddr[0x80];
  2694. }
  2695. }
  2696. }
  2697. static void
  2698. SiS_ResetVB(struct SiS_Private *SiS_Pr)
  2699. {
  2700. #ifdef CONFIG_FB_SIS_315
  2701. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  2702. unsigned short temp;
  2703. /* VB programming clock */
  2704. if(SiS_Pr->SiS_UseROM) {
  2705. if(SiS_Pr->ChipType < SIS_330) {
  2706. temp = ROMAddr[VB310Data_1_2_Offset] | 0x40;
  2707. if(SiS_Pr->SiS_ROMNew) temp = ROMAddr[0x80] | 0x40;
  2708. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x02,temp);
  2709. } else if(SiS_Pr->ChipType >= SIS_661 && SiS_Pr->ChipType < XGI_20) {
  2710. temp = ROMAddr[0x7e] | 0x40;
  2711. if(SiS_Pr->SiS_ROMNew) temp = ROMAddr[0x80] | 0x40;
  2712. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x02,temp);
  2713. }
  2714. } else if(SiS_Pr->ChipType >= XGI_40) {
  2715. temp = 0x40;
  2716. if(SiS_Pr->SiS_XGIROM) temp |= ROMAddr[0x7e];
  2717. /* Can we do this on any chipset? */
  2718. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x02,temp);
  2719. }
  2720. #endif
  2721. }
  2722. /*********************************************/
  2723. /* HELPER: SET VIDEO/CAPTURE REGISTERS */
  2724. /*********************************************/
  2725. static void
  2726. SiS_StrangeStuff(struct SiS_Private *SiS_Pr)
  2727. {
  2728. /* SiS65x and XGI set up some sort of "lock mode" for text
  2729. * which locks CRT2 in some way to CRT1 timing. Disable
  2730. * this here.
  2731. */
  2732. #ifdef CONFIG_FB_SIS_315
  2733. if((IS_SIS651) || (IS_SISM650) ||
  2734. SiS_Pr->ChipType == SIS_340 ||
  2735. SiS_Pr->ChipType == XGI_40) {
  2736. SiS_SetReg(SiS_Pr->SiS_VidCapt, 0x3f, 0x00); /* Fiddle with capture regs */
  2737. SiS_SetReg(SiS_Pr->SiS_VidCapt, 0x00, 0x00);
  2738. SiS_SetReg(SiS_Pr->SiS_VidPlay, 0x00, 0x86); /* (BIOS does NOT unlock) */
  2739. SiS_SetRegAND(SiS_Pr->SiS_VidPlay, 0x30, 0xfe); /* Fiddle with video regs */
  2740. SiS_SetRegAND(SiS_Pr->SiS_VidPlay, 0x3f, 0xef);
  2741. }
  2742. /* !!! This does not support modes < 0x13 !!! */
  2743. #endif
  2744. }
  2745. /*********************************************/
  2746. /* HELPER: SET AGP TIMING FOR SiS760 */
  2747. /*********************************************/
  2748. static void
  2749. SiS_Handle760(struct SiS_Private *SiS_Pr)
  2750. {
  2751. #ifdef CONFIG_FB_SIS_315
  2752. unsigned int somebase;
  2753. unsigned char temp1, temp2, temp3;
  2754. if( (SiS_Pr->ChipType != SIS_760) ||
  2755. ((SiS_GetReg(SiS_Pr->SiS_P3d4, 0x5c) & 0xf8) != 0x80) ||
  2756. (!(SiS_Pr->SiS_SysFlags & SF_760LFB)) ||
  2757. (!(SiS_Pr->SiS_SysFlags & SF_760UMA)) )
  2758. return;
  2759. somebase = sisfb_read_mio_pci_word(SiS_Pr, 0x74);
  2760. somebase &= 0xffff;
  2761. if(somebase == 0) return;
  2762. temp3 = SiS_GetRegByte((somebase + 0x85)) & 0xb7;
  2763. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40) {
  2764. temp1 = 0x21;
  2765. temp2 = 0x03;
  2766. temp3 |= 0x08;
  2767. } else {
  2768. temp1 = 0x25;
  2769. temp2 = 0x0b;
  2770. }
  2771. sisfb_write_nbridge_pci_byte(SiS_Pr, 0x7e, temp1);
  2772. sisfb_write_nbridge_pci_byte(SiS_Pr, 0x8d, temp2);
  2773. SiS_SetRegByte((somebase + 0x85), temp3);
  2774. #endif
  2775. }
  2776. /*********************************************/
  2777. /* SiSSetMode() */
  2778. /*********************************************/
  2779. bool
  2780. SiSSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  2781. {
  2782. SISIOADDRESS BaseAddr = SiS_Pr->IOAddress;
  2783. unsigned short RealModeNo, ModeIdIndex;
  2784. unsigned char backupreg = 0;
  2785. unsigned short KeepLockReg;
  2786. SiS_Pr->UseCustomMode = false;
  2787. SiS_Pr->CRT1UsesCustomMode = false;
  2788. SiS_Pr->SiS_flag_clearbuffer = 0;
  2789. if(SiS_Pr->UseCustomMode) {
  2790. ModeNo = 0xfe;
  2791. } else {
  2792. if(!(ModeNo & 0x80)) SiS_Pr->SiS_flag_clearbuffer = 1;
  2793. ModeNo &= 0x7f;
  2794. }
  2795. /* Don't use FSTN mode for CRT1 */
  2796. RealModeNo = ModeNo;
  2797. if(ModeNo == 0x5b) ModeNo = 0x56;
  2798. SiSInitPtr(SiS_Pr);
  2799. SiSRegInit(SiS_Pr, BaseAddr);
  2800. SiS_GetSysFlags(SiS_Pr);
  2801. SiS_Pr->SiS_VGAINFO = 0x11;
  2802. KeepLockReg = SiS_GetReg(SiS_Pr->SiS_P3c4,0x05);
  2803. SiS_SetReg(SiS_Pr->SiS_P3c4,0x05,0x86);
  2804. SiSInitPCIetc(SiS_Pr);
  2805. SiSSetLVDSetc(SiS_Pr);
  2806. SiSDetermineROMUsage(SiS_Pr);
  2807. SiS_UnLockCRT2(SiS_Pr);
  2808. if(!SiS_Pr->UseCustomMode) {
  2809. if(!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) return false;
  2810. } else {
  2811. ModeIdIndex = 0;
  2812. }
  2813. SiS_GetVBType(SiS_Pr);
  2814. /* Init/restore some VB registers */
  2815. SiS_InitVB(SiS_Pr);
  2816. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  2817. if(SiS_Pr->ChipType >= SIS_315H) {
  2818. SiS_ResetVB(SiS_Pr);
  2819. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x32,0x10);
  2820. SiS_SetRegOR(SiS_Pr->SiS_Part2Port,0x00,0x0c);
  2821. backupreg = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  2822. } else {
  2823. backupreg = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
  2824. }
  2825. }
  2826. /* Get VB information (connectors, connected devices) */
  2827. SiS_GetVBInfo(SiS_Pr, ModeNo, ModeIdIndex, (SiS_Pr->UseCustomMode) ? 0 : 1);
  2828. SiS_SetYPbPr(SiS_Pr);
  2829. SiS_SetTVMode(SiS_Pr, ModeNo, ModeIdIndex);
  2830. SiS_GetLCDResInfo(SiS_Pr, ModeNo, ModeIdIndex);
  2831. SiS_SetLowModeTest(SiS_Pr, ModeNo);
  2832. /* Check memory size (kernel framebuffer driver only) */
  2833. if(!SiS_CheckMemorySize(SiS_Pr, ModeNo, ModeIdIndex)) {
  2834. return false;
  2835. }
  2836. SiS_OpenCRTC(SiS_Pr);
  2837. if(SiS_Pr->UseCustomMode) {
  2838. SiS_Pr->CRT1UsesCustomMode = true;
  2839. SiS_Pr->CSRClock_CRT1 = SiS_Pr->CSRClock;
  2840. SiS_Pr->CModeFlag_CRT1 = SiS_Pr->CModeFlag;
  2841. } else {
  2842. SiS_Pr->CRT1UsesCustomMode = false;
  2843. }
  2844. /* Set mode on CRT1 */
  2845. if( (SiS_Pr->SiS_VBInfo & (SetSimuScanMode | SetCRT2ToLCDA)) ||
  2846. (!(SiS_Pr->SiS_VBInfo & SwitchCRT2)) ) {
  2847. SiS_SetCRT1Group(SiS_Pr, ModeNo, ModeIdIndex);
  2848. }
  2849. /* Set mode on CRT2 */
  2850. if(SiS_Pr->SiS_VBInfo & (SetSimuScanMode | SwitchCRT2 | SetCRT2ToLCDA)) {
  2851. if( (SiS_Pr->SiS_VBType & VB_SISVB) ||
  2852. (SiS_Pr->SiS_IF_DEF_LVDS == 1) ||
  2853. (SiS_Pr->SiS_IF_DEF_CH70xx != 0) ||
  2854. (SiS_Pr->SiS_IF_DEF_TRUMPION != 0) ) {
  2855. SiS_SetCRT2Group(SiS_Pr, RealModeNo);
  2856. }
  2857. }
  2858. SiS_HandleCRT1(SiS_Pr);
  2859. SiS_StrangeStuff(SiS_Pr);
  2860. SiS_DisplayOn(SiS_Pr);
  2861. SiS_SetRegByte(SiS_Pr->SiS_P3c6,0xFF);
  2862. #ifdef CONFIG_FB_SIS_315
  2863. if(SiS_Pr->ChipType >= SIS_315H) {
  2864. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  2865. if(!(SiS_IsDualEdge(SiS_Pr))) {
  2866. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb);
  2867. }
  2868. }
  2869. }
  2870. #endif
  2871. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  2872. if(SiS_Pr->ChipType >= SIS_315H) {
  2873. #ifdef CONFIG_FB_SIS_315
  2874. if(!SiS_Pr->SiS_ROMNew) {
  2875. if(SiS_IsVAMode(SiS_Pr)) {
  2876. SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x35,0x01);
  2877. } else {
  2878. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x35,0xFE);
  2879. }
  2880. }
  2881. SiS_SetReg(SiS_Pr->SiS_P3d4,0x38,backupreg);
  2882. if((IS_SIS650) && (SiS_GetReg(SiS_Pr->SiS_P3d4,0x30) & 0xfc)) {
  2883. if((ModeNo == 0x03) || (ModeNo == 0x10)) {
  2884. SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x51,0x80);
  2885. SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x56,0x08);
  2886. }
  2887. }
  2888. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x30) & SetCRT2ToLCD) {
  2889. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x38,0xfc);
  2890. }
  2891. #endif
  2892. } else if((SiS_Pr->ChipType == SIS_630) ||
  2893. (SiS_Pr->ChipType == SIS_730)) {
  2894. SiS_SetReg(SiS_Pr->SiS_P3d4,0x35,backupreg);
  2895. }
  2896. }
  2897. SiS_CloseCRTC(SiS_Pr);
  2898. SiS_Handle760(SiS_Pr);
  2899. /* We never lock registers in XF86 */
  2900. if(KeepLockReg != 0xA1) SiS_SetReg(SiS_Pr->SiS_P3c4,0x05,0x00);
  2901. return true;
  2902. }
  2903. #ifndef GETBITSTR
  2904. #define BITMASK(h,l) (((unsigned)(1U << ((h)-(l)+1))-1)<<(l))
  2905. #define GENMASK(mask) BITMASK(1?mask,0?mask)
  2906. #define GETBITS(var,mask) (((var) & GENMASK(mask)) >> (0?mask))
  2907. #define GETBITSTR(val,from,to) ((GETBITS(val,from)) << (0?to))
  2908. #endif
  2909. void
  2910. SiS_CalcCRRegisters(struct SiS_Private *SiS_Pr, int depth)
  2911. {
  2912. int x = 1; /* Fix sync */
  2913. SiS_Pr->CCRT1CRTC[0] = ((SiS_Pr->CHTotal >> 3) - 5) & 0xff; /* CR0 */
  2914. SiS_Pr->CCRT1CRTC[1] = (SiS_Pr->CHDisplay >> 3) - 1; /* CR1 */
  2915. SiS_Pr->CCRT1CRTC[2] = (SiS_Pr->CHBlankStart >> 3) - 1; /* CR2 */
  2916. SiS_Pr->CCRT1CRTC[3] = (((SiS_Pr->CHBlankEnd >> 3) - 1) & 0x1F) | 0x80; /* CR3 */
  2917. SiS_Pr->CCRT1CRTC[4] = (SiS_Pr->CHSyncStart >> 3) + 3; /* CR4 */
  2918. SiS_Pr->CCRT1CRTC[5] = ((((SiS_Pr->CHBlankEnd >> 3) - 1) & 0x20) << 2) | /* CR5 */
  2919. (((SiS_Pr->CHSyncEnd >> 3) + 3) & 0x1F);
  2920. SiS_Pr->CCRT1CRTC[6] = (SiS_Pr->CVTotal - 2) & 0xFF; /* CR6 */
  2921. SiS_Pr->CCRT1CRTC[7] = (((SiS_Pr->CVTotal - 2) & 0x100) >> 8) /* CR7 */
  2922. | (((SiS_Pr->CVDisplay - 1) & 0x100) >> 7)
  2923. | (((SiS_Pr->CVSyncStart - x) & 0x100) >> 6)
  2924. | (((SiS_Pr->CVBlankStart- 1) & 0x100) >> 5)
  2925. | 0x10
  2926. | (((SiS_Pr->CVTotal - 2) & 0x200) >> 4)
  2927. | (((SiS_Pr->CVDisplay - 1) & 0x200) >> 3)
  2928. | (((SiS_Pr->CVSyncStart - x) & 0x200) >> 2);
  2929. SiS_Pr->CCRT1CRTC[16] = ((((SiS_Pr->CVBlankStart - 1) & 0x200) >> 4) >> 5); /* CR9 */
  2930. if(depth != 8) {
  2931. if(SiS_Pr->CHDisplay >= 1600) SiS_Pr->CCRT1CRTC[16] |= 0x60; /* SRE */
  2932. else if(SiS_Pr->CHDisplay >= 640) SiS_Pr->CCRT1CRTC[16] |= 0x40;
  2933. }
  2934. SiS_Pr->CCRT1CRTC[8] = (SiS_Pr->CVSyncStart - x) & 0xFF; /* CR10 */
  2935. SiS_Pr->CCRT1CRTC[9] = ((SiS_Pr->CVSyncEnd - x) & 0x0F) | 0x80; /* CR11 */
  2936. SiS_Pr->CCRT1CRTC[10] = (SiS_Pr->CVDisplay - 1) & 0xFF; /* CR12 */
  2937. SiS_Pr->CCRT1CRTC[11] = (SiS_Pr->CVBlankStart - 1) & 0xFF; /* CR15 */
  2938. SiS_Pr->CCRT1CRTC[12] = (SiS_Pr->CVBlankEnd - 1) & 0xFF; /* CR16 */
  2939. SiS_Pr->CCRT1CRTC[13] = /* SRA */
  2940. GETBITSTR((SiS_Pr->CVTotal -2), 10:10, 0:0) |
  2941. GETBITSTR((SiS_Pr->CVDisplay -1), 10:10, 1:1) |
  2942. GETBITSTR((SiS_Pr->CVBlankStart-1), 10:10, 2:2) |
  2943. GETBITSTR((SiS_Pr->CVSyncStart -x), 10:10, 3:3) |
  2944. GETBITSTR((SiS_Pr->CVBlankEnd -1), 8:8, 4:4) |
  2945. GETBITSTR((SiS_Pr->CVSyncEnd ), 4:4, 5:5) ;
  2946. SiS_Pr->CCRT1CRTC[14] = /* SRB */
  2947. GETBITSTR((SiS_Pr->CHTotal >> 3) - 5, 9:8, 1:0) |
  2948. GETBITSTR((SiS_Pr->CHDisplay >> 3) - 1, 9:8, 3:2) |
  2949. GETBITSTR((SiS_Pr->CHBlankStart >> 3) - 1, 9:8, 5:4) |
  2950. GETBITSTR((SiS_Pr->CHSyncStart >> 3) + 3, 9:8, 7:6) ;
  2951. SiS_Pr->CCRT1CRTC[15] = /* SRC */
  2952. GETBITSTR((SiS_Pr->CHBlankEnd >> 3) - 1, 7:6, 1:0) |
  2953. GETBITSTR((SiS_Pr->CHSyncEnd >> 3) + 3, 5:5, 2:2) ;
  2954. }
  2955. void
  2956. SiS_CalcLCDACRT1Timing(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  2957. unsigned short ModeIdIndex)
  2958. {
  2959. unsigned short modeflag, tempax, tempbx = 0, remaining = 0;
  2960. unsigned short VGAHDE = SiS_Pr->SiS_VGAHDE;
  2961. int i, j;
  2962. /* 1:1 data: use data set by setcrt1crtc() */
  2963. if(SiS_Pr->SiS_LCDInfo & LCDPass11) return;
  2964. modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
  2965. if(modeflag & HalfDCLK) VGAHDE >>= 1;
  2966. SiS_Pr->CHDisplay = VGAHDE;
  2967. SiS_Pr->CHBlankStart = VGAHDE;
  2968. SiS_Pr->CVDisplay = SiS_Pr->SiS_VGAVDE;
  2969. SiS_Pr->CVBlankStart = SiS_Pr->SiS_VGAVDE;
  2970. if(SiS_Pr->ChipType < SIS_315H) {
  2971. #ifdef CONFIG_FB_SIS_300
  2972. tempbx = SiS_Pr->SiS_VGAHT;
  2973. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  2974. tempbx = SiS_Pr->PanelHT;
  2975. }
  2976. if(modeflag & HalfDCLK) tempbx >>= 1;
  2977. remaining = tempbx % 8;
  2978. #endif
  2979. } else {
  2980. #ifdef CONFIG_FB_SIS_315
  2981. /* OK for LCDA, LVDS */
  2982. tempbx = SiS_Pr->PanelHT - SiS_Pr->PanelXRes;
  2983. tempax = SiS_Pr->SiS_VGAHDE; /* not /2 ! */
  2984. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  2985. tempax = SiS_Pr->PanelXRes;
  2986. }
  2987. tempbx += tempax;
  2988. if(modeflag & HalfDCLK) tempbx -= VGAHDE;
  2989. #endif
  2990. }
  2991. SiS_Pr->CHTotal = SiS_Pr->CHBlankEnd = tempbx;
  2992. if(SiS_Pr->ChipType < SIS_315H) {
  2993. #ifdef CONFIG_FB_SIS_300
  2994. if(SiS_Pr->SiS_VGAHDE == SiS_Pr->PanelXRes) {
  2995. SiS_Pr->CHSyncStart = SiS_Pr->SiS_VGAHDE + ((SiS_Pr->PanelHRS + 1) & ~1);
  2996. SiS_Pr->CHSyncEnd = SiS_Pr->CHSyncStart + SiS_Pr->PanelHRE;
  2997. if(modeflag & HalfDCLK) {
  2998. SiS_Pr->CHSyncStart >>= 1;
  2999. SiS_Pr->CHSyncEnd >>= 1;
  3000. }
  3001. } else if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3002. tempax = (SiS_Pr->PanelXRes - SiS_Pr->SiS_VGAHDE) >> 1;
  3003. tempbx = (SiS_Pr->PanelHRS + 1) & ~1;
  3004. if(modeflag & HalfDCLK) {
  3005. tempax >>= 1;
  3006. tempbx >>= 1;
  3007. }
  3008. SiS_Pr->CHSyncStart = (VGAHDE + tempax + tempbx + 7) & ~7;
  3009. tempax = SiS_Pr->PanelHRE + 7;
  3010. if(modeflag & HalfDCLK) tempax >>= 1;
  3011. SiS_Pr->CHSyncEnd = (SiS_Pr->CHSyncStart + tempax) & ~7;
  3012. } else {
  3013. SiS_Pr->CHSyncStart = SiS_Pr->SiS_VGAHDE;
  3014. if(modeflag & HalfDCLK) {
  3015. SiS_Pr->CHSyncStart >>= 1;
  3016. tempax = ((SiS_Pr->CHTotal - SiS_Pr->CHSyncStart) / 3) << 1;
  3017. SiS_Pr->CHSyncEnd = SiS_Pr->CHSyncStart + tempax;
  3018. } else {
  3019. SiS_Pr->CHSyncEnd = (SiS_Pr->CHSyncStart + (SiS_Pr->CHTotal / 10) + 7) & ~7;
  3020. SiS_Pr->CHSyncStart += 8;
  3021. }
  3022. }
  3023. #endif
  3024. } else {
  3025. #ifdef CONFIG_FB_SIS_315
  3026. tempax = VGAHDE;
  3027. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3028. tempbx = SiS_Pr->PanelXRes;
  3029. if(modeflag & HalfDCLK) tempbx >>= 1;
  3030. tempax += ((tempbx - tempax) >> 1);
  3031. }
  3032. tempax += SiS_Pr->PanelHRS;
  3033. SiS_Pr->CHSyncStart = tempax;
  3034. tempax += SiS_Pr->PanelHRE;
  3035. SiS_Pr->CHSyncEnd = tempax;
  3036. #endif
  3037. }
  3038. tempbx = SiS_Pr->PanelVT - SiS_Pr->PanelYRes;
  3039. tempax = SiS_Pr->SiS_VGAVDE;
  3040. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3041. tempax = SiS_Pr->PanelYRes;
  3042. } else if(SiS_Pr->ChipType < SIS_315H) {
  3043. #ifdef CONFIG_FB_SIS_300
  3044. /* Stupid hack for 640x400/320x200 */
  3045. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  3046. if((tempax + tempbx) == 438) tempbx += 16;
  3047. } else if((SiS_Pr->SiS_LCDResInfo == Panel_800x600) ||
  3048. (SiS_Pr->SiS_LCDResInfo == Panel_1024x600)) {
  3049. tempax = 0;
  3050. tempbx = SiS_Pr->SiS_VGAVT;
  3051. }
  3052. #endif
  3053. }
  3054. SiS_Pr->CVTotal = SiS_Pr->CVBlankEnd = tempbx + tempax;
  3055. tempax = SiS_Pr->SiS_VGAVDE;
  3056. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3057. tempax += (SiS_Pr->PanelYRes - tempax) >> 1;
  3058. }
  3059. tempax += SiS_Pr->PanelVRS;
  3060. SiS_Pr->CVSyncStart = tempax;
  3061. tempax += SiS_Pr->PanelVRE;
  3062. SiS_Pr->CVSyncEnd = tempax;
  3063. if(SiS_Pr->ChipType < SIS_315H) {
  3064. SiS_Pr->CVSyncStart--;
  3065. SiS_Pr->CVSyncEnd--;
  3066. }
  3067. SiS_CalcCRRegisters(SiS_Pr, 8);
  3068. SiS_Pr->CCRT1CRTC[15] &= ~0xF8;
  3069. SiS_Pr->CCRT1CRTC[15] |= (remaining << 4);
  3070. SiS_Pr->CCRT1CRTC[16] &= ~0xE0;
  3071. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x11,0x7f);
  3072. for(i = 0, j = 0; i <= 7; i++, j++) {
  3073. SiS_SetReg(SiS_Pr->SiS_P3d4,j,SiS_Pr->CCRT1CRTC[i]);
  3074. }
  3075. for(j = 0x10; i <= 10; i++, j++) {
  3076. SiS_SetReg(SiS_Pr->SiS_P3d4,j,SiS_Pr->CCRT1CRTC[i]);
  3077. }
  3078. for(j = 0x15; i <= 12; i++, j++) {
  3079. SiS_SetReg(SiS_Pr->SiS_P3d4,j,SiS_Pr->CCRT1CRTC[i]);
  3080. }
  3081. for(j = 0x0A; i <= 15; i++, j++) {
  3082. SiS_SetReg(SiS_Pr->SiS_P3c4,j,SiS_Pr->CCRT1CRTC[i]);
  3083. }
  3084. tempax = SiS_Pr->CCRT1CRTC[16] & 0xE0;
  3085. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0E,0x1F,tempax);
  3086. tempax = (SiS_Pr->CCRT1CRTC[16] & 0x01) << 5;
  3087. if(modeflag & DoubleScanMode) tempax |= 0x80;
  3088. SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x09,0x5F,tempax);
  3089. }
  3090. void
  3091. SiS_Generic_ConvertCRData(struct SiS_Private *SiS_Pr, unsigned char *crdata,
  3092. int xres, int yres,
  3093. struct fb_var_screeninfo *var, bool writeres
  3094. )
  3095. {
  3096. unsigned short HRE, HBE, HRS, HBS, HDE, HT;
  3097. unsigned short VRE, VBE, VRS, VBS, VDE, VT;
  3098. unsigned char sr_data, cr_data, cr_data2;
  3099. int A, B, C, D, E, F, temp;
  3100. sr_data = crdata[14];
  3101. /* Horizontal total */
  3102. HT = crdata[0] | ((unsigned short)(sr_data & 0x03) << 8);
  3103. A = HT + 5;
  3104. /* Horizontal display enable end */
  3105. HDE = crdata[1] | ((unsigned short)(sr_data & 0x0C) << 6);
  3106. E = HDE + 1;
  3107. /* Horizontal retrace (=sync) start */
  3108. HRS = crdata[4] | ((unsigned short)(sr_data & 0xC0) << 2);
  3109. F = HRS - E - 3;
  3110. /* Horizontal blank start */
  3111. HBS = crdata[2] | ((unsigned short)(sr_data & 0x30) << 4);
  3112. sr_data = crdata[15];
  3113. cr_data = crdata[5];
  3114. /* Horizontal blank end */
  3115. HBE = (crdata[3] & 0x1f) |
  3116. ((unsigned short)(cr_data & 0x80) >> 2) |
  3117. ((unsigned short)(sr_data & 0x03) << 6);
  3118. /* Horizontal retrace (=sync) end */
  3119. HRE = (cr_data & 0x1f) | ((sr_data & 0x04) << 3);
  3120. temp = HBE - ((E - 1) & 255);
  3121. B = (temp > 0) ? temp : (temp + 256);
  3122. temp = HRE - ((E + F + 3) & 63);
  3123. C = (temp > 0) ? temp : (temp + 64);
  3124. D = B - F - C;
  3125. if(writeres) var->xres = xres = E * 8;
  3126. var->left_margin = D * 8;
  3127. var->right_margin = F * 8;
  3128. var->hsync_len = C * 8;
  3129. /* Vertical */
  3130. sr_data = crdata[13];
  3131. cr_data = crdata[7];
  3132. /* Vertical total */
  3133. VT = crdata[6] |
  3134. ((unsigned short)(cr_data & 0x01) << 8) |
  3135. ((unsigned short)(cr_data & 0x20) << 4) |
  3136. ((unsigned short)(sr_data & 0x01) << 10);
  3137. A = VT + 2;
  3138. /* Vertical display enable end */
  3139. VDE = crdata[10] |
  3140. ((unsigned short)(cr_data & 0x02) << 7) |
  3141. ((unsigned short)(cr_data & 0x40) << 3) |
  3142. ((unsigned short)(sr_data & 0x02) << 9);
  3143. E = VDE + 1;
  3144. /* Vertical retrace (=sync) start */
  3145. VRS = crdata[8] |
  3146. ((unsigned short)(cr_data & 0x04) << 6) |
  3147. ((unsigned short)(cr_data & 0x80) << 2) |
  3148. ((unsigned short)(sr_data & 0x08) << 7);
  3149. F = VRS + 1 - E;
  3150. cr_data2 = (crdata[16] & 0x01) << 5;
  3151. /* Vertical blank start */
  3152. VBS = crdata[11] |
  3153. ((unsigned short)(cr_data & 0x08) << 5) |
  3154. ((unsigned short)(cr_data2 & 0x20) << 4) |
  3155. ((unsigned short)(sr_data & 0x04) << 8);
  3156. /* Vertical blank end */
  3157. VBE = crdata[12] | ((unsigned short)(sr_data & 0x10) << 4);
  3158. temp = VBE - ((E - 1) & 511);
  3159. B = (temp > 0) ? temp : (temp + 512);
  3160. /* Vertical retrace (=sync) end */
  3161. VRE = (crdata[9] & 0x0f) | ((sr_data & 0x20) >> 1);
  3162. temp = VRE - ((E + F - 1) & 31);
  3163. C = (temp > 0) ? temp : (temp + 32);
  3164. D = B - F - C;
  3165. if(writeres) var->yres = yres = E;
  3166. var->upper_margin = D;
  3167. var->lower_margin = F;
  3168. var->vsync_len = C;
  3169. if((xres == 320) && ((yres == 200) || (yres == 240))) {
  3170. /* Terrible hack, but correct CRTC data for
  3171. * these modes only produces a black screen...
  3172. * (HRE is 0, leading into a too large C and
  3173. * a negative D. The CRT controller does not
  3174. * seem to like correcting HRE to 50)
  3175. */
  3176. var->left_margin = (400 - 376);
  3177. var->right_margin = (328 - 320);
  3178. var->hsync_len = (376 - 328);
  3179. }
  3180. }