init.c 106 KB

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