radeon_base.c 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568
  1. /*
  2. * drivers/video/aty/radeon_base.c
  3. *
  4. * framebuffer driver for ATI Radeon chipset video boards
  5. *
  6. * Copyright 2003 Ben. Herrenschmidt <benh@kernel.crashing.org>
  7. * Copyright 2000 Ani Joshi <ajoshi@kernel.crashing.org>
  8. *
  9. * i2c bits from Luca Tettamanti <kronos@kronoz.cjb.net>
  10. *
  11. * Special thanks to ATI DevRel team for their hardware donations.
  12. *
  13. * ...Insert GPL boilerplate here...
  14. *
  15. * Significant portions of this driver apdated from XFree86 Radeon
  16. * driver which has the following copyright notice:
  17. *
  18. * Copyright 2000 ATI Technologies Inc., Markham, Ontario, and
  19. * VA Linux Systems Inc., Fremont, California.
  20. *
  21. * All Rights Reserved.
  22. *
  23. * Permission is hereby granted, free of charge, to any person obtaining
  24. * a copy of this software and associated documentation files (the
  25. * "Software"), to deal in the Software without restriction, including
  26. * without limitation on the rights to use, copy, modify, merge,
  27. * publish, distribute, sublicense, and/or sell copies of the Software,
  28. * and to permit persons to whom the Software is furnished to do so,
  29. * subject to the following conditions:
  30. *
  31. * The above copyright notice and this permission notice (including the
  32. * next paragraph) shall be included in all copies or substantial
  33. * portions of the Software.
  34. *
  35. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  36. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  37. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  38. * NON-INFRINGEMENT. IN NO EVENT SHALL ATI, VA LINUX SYSTEMS AND/OR
  39. * THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  40. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  41. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  42. * DEALINGS IN THE SOFTWARE.
  43. *
  44. * XFree86 driver authors:
  45. *
  46. * Kevin E. Martin <martin@xfree86.org>
  47. * Rickard E. Faith <faith@valinux.com>
  48. * Alan Hourihane <alanh@fairlite.demon.co.uk>
  49. *
  50. */
  51. #define RADEON_VERSION "0.2.0"
  52. #include <linux/module.h>
  53. #include <linux/moduleparam.h>
  54. #include <linux/kernel.h>
  55. #include <linux/errno.h>
  56. #include <linux/string.h>
  57. #include <linux/mm.h>
  58. #include <linux/slab.h>
  59. #include <linux/delay.h>
  60. #include <linux/time.h>
  61. #include <linux/fb.h>
  62. #include <linux/ioport.h>
  63. #include <linux/init.h>
  64. #include <linux/pci.h>
  65. #include <linux/vmalloc.h>
  66. #include <linux/device.h>
  67. #include <asm/io.h>
  68. #include <linux/uaccess.h>
  69. #ifdef CONFIG_PPC_OF
  70. #include <asm/pci-bridge.h>
  71. #include "../macmodes.h"
  72. #ifdef CONFIG_BOOTX_TEXT
  73. #include <asm/btext.h>
  74. #endif
  75. #endif /* CONFIG_PPC_OF */
  76. #ifdef CONFIG_MTRR
  77. #include <asm/mtrr.h>
  78. #endif
  79. #include <video/radeon.h>
  80. #include <linux/radeonfb.h>
  81. #include "../edid.h" // MOVE THAT TO include/video
  82. #include "ati_ids.h"
  83. #include "radeonfb.h"
  84. #define MAX_MAPPED_VRAM (2048*2048*4)
  85. #define MIN_MAPPED_VRAM (1024*768*1)
  86. #define CHIP_DEF(id, family, flags) \
  87. { PCI_VENDOR_ID_ATI, id, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (flags) | (CHIP_FAMILY_##family) }
  88. static struct pci_device_id radeonfb_pci_table[] = {
  89. /* Radeon Xpress 200m */
  90. CHIP_DEF(PCI_CHIP_RS480_5955, RS480, CHIP_HAS_CRTC2 | CHIP_IS_IGP | CHIP_IS_MOBILITY),
  91. CHIP_DEF(PCI_CHIP_RS482_5975, RS480, CHIP_HAS_CRTC2 | CHIP_IS_IGP | CHIP_IS_MOBILITY),
  92. /* Mobility M6 */
  93. CHIP_DEF(PCI_CHIP_RADEON_LY, RV100, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
  94. CHIP_DEF(PCI_CHIP_RADEON_LZ, RV100, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
  95. /* Radeon VE/7000 */
  96. CHIP_DEF(PCI_CHIP_RV100_QY, RV100, CHIP_HAS_CRTC2),
  97. CHIP_DEF(PCI_CHIP_RV100_QZ, RV100, CHIP_HAS_CRTC2),
  98. CHIP_DEF(PCI_CHIP_RN50, RV100, CHIP_HAS_CRTC2),
  99. /* Radeon IGP320M (U1) */
  100. CHIP_DEF(PCI_CHIP_RS100_4336, RS100, CHIP_HAS_CRTC2 | CHIP_IS_IGP | CHIP_IS_MOBILITY),
  101. /* Radeon IGP320 (A3) */
  102. CHIP_DEF(PCI_CHIP_RS100_4136, RS100, CHIP_HAS_CRTC2 | CHIP_IS_IGP),
  103. /* IGP330M/340M/350M (U2) */
  104. CHIP_DEF(PCI_CHIP_RS200_4337, RS200, CHIP_HAS_CRTC2 | CHIP_IS_IGP | CHIP_IS_MOBILITY),
  105. /* IGP330/340/350 (A4) */
  106. CHIP_DEF(PCI_CHIP_RS200_4137, RS200, CHIP_HAS_CRTC2 | CHIP_IS_IGP),
  107. /* Mobility 7000 IGP */
  108. CHIP_DEF(PCI_CHIP_RS250_4437, RS200, CHIP_HAS_CRTC2 | CHIP_IS_IGP | CHIP_IS_MOBILITY),
  109. /* 7000 IGP (A4+) */
  110. CHIP_DEF(PCI_CHIP_RS250_4237, RS200, CHIP_HAS_CRTC2 | CHIP_IS_IGP),
  111. /* 8500 AIW */
  112. CHIP_DEF(PCI_CHIP_R200_BB, R200, CHIP_HAS_CRTC2),
  113. CHIP_DEF(PCI_CHIP_R200_BC, R200, CHIP_HAS_CRTC2),
  114. /* 8700/8800 */
  115. CHIP_DEF(PCI_CHIP_R200_QH, R200, CHIP_HAS_CRTC2),
  116. /* 8500 */
  117. CHIP_DEF(PCI_CHIP_R200_QL, R200, CHIP_HAS_CRTC2),
  118. /* 9100 */
  119. CHIP_DEF(PCI_CHIP_R200_QM, R200, CHIP_HAS_CRTC2),
  120. /* Mobility M7 */
  121. CHIP_DEF(PCI_CHIP_RADEON_LW, RV200, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
  122. CHIP_DEF(PCI_CHIP_RADEON_LX, RV200, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
  123. /* 7500 */
  124. CHIP_DEF(PCI_CHIP_RV200_QW, RV200, CHIP_HAS_CRTC2),
  125. CHIP_DEF(PCI_CHIP_RV200_QX, RV200, CHIP_HAS_CRTC2),
  126. /* Mobility M9 */
  127. CHIP_DEF(PCI_CHIP_RV250_Ld, RV250, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
  128. CHIP_DEF(PCI_CHIP_RV250_Le, RV250, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
  129. CHIP_DEF(PCI_CHIP_RV250_Lf, RV250, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
  130. CHIP_DEF(PCI_CHIP_RV250_Lg, RV250, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
  131. /* 9000/Pro */
  132. CHIP_DEF(PCI_CHIP_RV250_If, RV250, CHIP_HAS_CRTC2),
  133. CHIP_DEF(PCI_CHIP_RV250_Ig, RV250, CHIP_HAS_CRTC2),
  134. CHIP_DEF(PCI_CHIP_RC410_5A62, RC410, CHIP_HAS_CRTC2 | CHIP_IS_IGP | CHIP_IS_MOBILITY),
  135. /* Mobility 9100 IGP (U3) */
  136. CHIP_DEF(PCI_CHIP_RS300_5835, RS300, CHIP_HAS_CRTC2 | CHIP_IS_IGP | CHIP_IS_MOBILITY),
  137. CHIP_DEF(PCI_CHIP_RS350_7835, RS300, CHIP_HAS_CRTC2 | CHIP_IS_IGP | CHIP_IS_MOBILITY),
  138. /* 9100 IGP (A5) */
  139. CHIP_DEF(PCI_CHIP_RS300_5834, RS300, CHIP_HAS_CRTC2 | CHIP_IS_IGP),
  140. CHIP_DEF(PCI_CHIP_RS350_7834, RS300, CHIP_HAS_CRTC2 | CHIP_IS_IGP),
  141. /* Mobility 9200 (M9+) */
  142. CHIP_DEF(PCI_CHIP_RV280_5C61, RV280, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
  143. CHIP_DEF(PCI_CHIP_RV280_5C63, RV280, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
  144. /* 9200 */
  145. CHIP_DEF(PCI_CHIP_RV280_5960, RV280, CHIP_HAS_CRTC2),
  146. CHIP_DEF(PCI_CHIP_RV280_5961, RV280, CHIP_HAS_CRTC2),
  147. CHIP_DEF(PCI_CHIP_RV280_5962, RV280, CHIP_HAS_CRTC2),
  148. CHIP_DEF(PCI_CHIP_RV280_5964, RV280, CHIP_HAS_CRTC2),
  149. /* 9500 */
  150. CHIP_DEF(PCI_CHIP_R300_AD, R300, CHIP_HAS_CRTC2),
  151. CHIP_DEF(PCI_CHIP_R300_AE, R300, CHIP_HAS_CRTC2),
  152. /* 9600TX / FireGL Z1 */
  153. CHIP_DEF(PCI_CHIP_R300_AF, R300, CHIP_HAS_CRTC2),
  154. CHIP_DEF(PCI_CHIP_R300_AG, R300, CHIP_HAS_CRTC2),
  155. /* 9700/9500/Pro/FireGL X1 */
  156. CHIP_DEF(PCI_CHIP_R300_ND, R300, CHIP_HAS_CRTC2),
  157. CHIP_DEF(PCI_CHIP_R300_NE, R300, CHIP_HAS_CRTC2),
  158. CHIP_DEF(PCI_CHIP_R300_NF, R300, CHIP_HAS_CRTC2),
  159. CHIP_DEF(PCI_CHIP_R300_NG, R300, CHIP_HAS_CRTC2),
  160. /* Mobility M10/M11 */
  161. CHIP_DEF(PCI_CHIP_RV350_NP, RV350, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
  162. CHIP_DEF(PCI_CHIP_RV350_NQ, RV350, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
  163. CHIP_DEF(PCI_CHIP_RV350_NR, RV350, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
  164. CHIP_DEF(PCI_CHIP_RV350_NS, RV350, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
  165. CHIP_DEF(PCI_CHIP_RV350_NT, RV350, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
  166. CHIP_DEF(PCI_CHIP_RV350_NV, RV350, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
  167. /* 9600/FireGL T2 */
  168. CHIP_DEF(PCI_CHIP_RV350_AP, RV350, CHIP_HAS_CRTC2),
  169. CHIP_DEF(PCI_CHIP_RV350_AQ, RV350, CHIP_HAS_CRTC2),
  170. CHIP_DEF(PCI_CHIP_RV360_AR, RV350, CHIP_HAS_CRTC2),
  171. CHIP_DEF(PCI_CHIP_RV350_AS, RV350, CHIP_HAS_CRTC2),
  172. CHIP_DEF(PCI_CHIP_RV350_AT, RV350, CHIP_HAS_CRTC2),
  173. CHIP_DEF(PCI_CHIP_RV350_AV, RV350, CHIP_HAS_CRTC2),
  174. /* 9800/Pro/FileGL X2 */
  175. CHIP_DEF(PCI_CHIP_R350_AH, R350, CHIP_HAS_CRTC2),
  176. CHIP_DEF(PCI_CHIP_R350_AI, R350, CHIP_HAS_CRTC2),
  177. CHIP_DEF(PCI_CHIP_R350_AJ, R350, CHIP_HAS_CRTC2),
  178. CHIP_DEF(PCI_CHIP_R350_AK, R350, CHIP_HAS_CRTC2),
  179. CHIP_DEF(PCI_CHIP_R350_NH, R350, CHIP_HAS_CRTC2),
  180. CHIP_DEF(PCI_CHIP_R350_NI, R350, CHIP_HAS_CRTC2),
  181. CHIP_DEF(PCI_CHIP_R360_NJ, R350, CHIP_HAS_CRTC2),
  182. CHIP_DEF(PCI_CHIP_R350_NK, R350, CHIP_HAS_CRTC2),
  183. /* Newer stuff */
  184. CHIP_DEF(PCI_CHIP_RV380_3E50, RV380, CHIP_HAS_CRTC2),
  185. CHIP_DEF(PCI_CHIP_RV380_3E54, RV380, CHIP_HAS_CRTC2),
  186. CHIP_DEF(PCI_CHIP_RV380_3150, RV380, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
  187. CHIP_DEF(PCI_CHIP_RV380_3154, RV380, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
  188. CHIP_DEF(PCI_CHIP_RV370_5B60, RV380, CHIP_HAS_CRTC2),
  189. CHIP_DEF(PCI_CHIP_RV370_5B62, RV380, CHIP_HAS_CRTC2),
  190. CHIP_DEF(PCI_CHIP_RV370_5B64, RV380, CHIP_HAS_CRTC2),
  191. CHIP_DEF(PCI_CHIP_RV370_5B65, RV380, CHIP_HAS_CRTC2),
  192. CHIP_DEF(PCI_CHIP_RV370_5460, RV380, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
  193. CHIP_DEF(PCI_CHIP_RV370_5464, RV380, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
  194. CHIP_DEF(PCI_CHIP_R420_JH, R420, CHIP_HAS_CRTC2),
  195. CHIP_DEF(PCI_CHIP_R420_JI, R420, CHIP_HAS_CRTC2),
  196. CHIP_DEF(PCI_CHIP_R420_JJ, R420, CHIP_HAS_CRTC2),
  197. CHIP_DEF(PCI_CHIP_R420_JK, R420, CHIP_HAS_CRTC2),
  198. CHIP_DEF(PCI_CHIP_R420_JL, R420, CHIP_HAS_CRTC2),
  199. CHIP_DEF(PCI_CHIP_R420_JM, R420, CHIP_HAS_CRTC2),
  200. CHIP_DEF(PCI_CHIP_R420_JN, R420, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
  201. CHIP_DEF(PCI_CHIP_R420_JP, R420, CHIP_HAS_CRTC2),
  202. CHIP_DEF(PCI_CHIP_R423_UH, R420, CHIP_HAS_CRTC2),
  203. CHIP_DEF(PCI_CHIP_R423_UI, R420, CHIP_HAS_CRTC2),
  204. CHIP_DEF(PCI_CHIP_R423_UJ, R420, CHIP_HAS_CRTC2),
  205. CHIP_DEF(PCI_CHIP_R423_UK, R420, CHIP_HAS_CRTC2),
  206. CHIP_DEF(PCI_CHIP_R423_UQ, R420, CHIP_HAS_CRTC2),
  207. CHIP_DEF(PCI_CHIP_R423_UR, R420, CHIP_HAS_CRTC2),
  208. CHIP_DEF(PCI_CHIP_R423_UT, R420, CHIP_HAS_CRTC2),
  209. CHIP_DEF(PCI_CHIP_R423_5D57, R420, CHIP_HAS_CRTC2),
  210. /* Original Radeon/7200 */
  211. CHIP_DEF(PCI_CHIP_RADEON_QD, RADEON, 0),
  212. CHIP_DEF(PCI_CHIP_RADEON_QE, RADEON, 0),
  213. CHIP_DEF(PCI_CHIP_RADEON_QF, RADEON, 0),
  214. CHIP_DEF(PCI_CHIP_RADEON_QG, RADEON, 0),
  215. { 0, }
  216. };
  217. MODULE_DEVICE_TABLE(pci, radeonfb_pci_table);
  218. typedef struct {
  219. u16 reg;
  220. u32 val;
  221. } reg_val;
  222. /* these common regs are cleared before mode setting so they do not
  223. * interfere with anything
  224. */
  225. static reg_val common_regs[] = {
  226. { OVR_CLR, 0 },
  227. { OVR_WID_LEFT_RIGHT, 0 },
  228. { OVR_WID_TOP_BOTTOM, 0 },
  229. { OV0_SCALE_CNTL, 0 },
  230. { SUBPIC_CNTL, 0 },
  231. { VIPH_CONTROL, 0 },
  232. { I2C_CNTL_1, 0 },
  233. { GEN_INT_CNTL, 0 },
  234. { CAP0_TRIG_CNTL, 0 },
  235. { CAP1_TRIG_CNTL, 0 },
  236. };
  237. /*
  238. * globals
  239. */
  240. static char *mode_option;
  241. static char *monitor_layout;
  242. static int noaccel = 0;
  243. static int default_dynclk = -2;
  244. static int nomodeset = 0;
  245. static int ignore_edid = 0;
  246. static int mirror = 0;
  247. static int panel_yres = 0;
  248. static int force_dfp = 0;
  249. static int force_measure_pll = 0;
  250. #ifdef CONFIG_MTRR
  251. static int nomtrr = 0;
  252. #endif
  253. static int force_sleep;
  254. static int ignore_devlist;
  255. #ifdef CONFIG_PMAC_BACKLIGHT
  256. static int backlight = 1;
  257. #else
  258. static int backlight = 0;
  259. #endif
  260. /*
  261. * prototypes
  262. */
  263. static void radeon_unmap_ROM(struct radeonfb_info *rinfo, struct pci_dev *dev)
  264. {
  265. if (!rinfo->bios_seg)
  266. return;
  267. pci_unmap_rom(dev, rinfo->bios_seg);
  268. }
  269. static int __devinit radeon_map_ROM(struct radeonfb_info *rinfo, struct pci_dev *dev)
  270. {
  271. void __iomem *rom;
  272. u16 dptr;
  273. u8 rom_type;
  274. size_t rom_size;
  275. /* If this is a primary card, there is a shadow copy of the
  276. * ROM somewhere in the first meg. We will just ignore the copy
  277. * and use the ROM directly.
  278. */
  279. /* Fix from ATI for problem with Radeon hardware not leaving ROM enabled */
  280. unsigned int temp;
  281. temp = INREG(MPP_TB_CONFIG);
  282. temp &= 0x00ffffffu;
  283. temp |= 0x04 << 24;
  284. OUTREG(MPP_TB_CONFIG, temp);
  285. temp = INREG(MPP_TB_CONFIG);
  286. rom = pci_map_rom(dev, &rom_size);
  287. if (!rom) {
  288. printk(KERN_ERR "radeonfb (%s): ROM failed to map\n",
  289. pci_name(rinfo->pdev));
  290. return -ENOMEM;
  291. }
  292. rinfo->bios_seg = rom;
  293. /* Very simple test to make sure it appeared */
  294. if (BIOS_IN16(0) != 0xaa55) {
  295. printk(KERN_DEBUG "radeonfb (%s): Invalid ROM signature %x "
  296. "should be 0xaa55\n",
  297. pci_name(rinfo->pdev), BIOS_IN16(0));
  298. goto failed;
  299. }
  300. /* Look for the PCI data to check the ROM type */
  301. dptr = BIOS_IN16(0x18);
  302. /* Check the PCI data signature. If it's wrong, we still assume a normal x86 ROM
  303. * for now, until I've verified this works everywhere. The goal here is more
  304. * to phase out Open Firmware images.
  305. *
  306. * Currently, we only look at the first PCI data, we could iteratre and deal with
  307. * them all, and we should use fb_bios_start relative to start of image and not
  308. * relative start of ROM, but so far, I never found a dual-image ATI card
  309. *
  310. * typedef struct {
  311. * u32 signature; + 0x00
  312. * u16 vendor; + 0x04
  313. * u16 device; + 0x06
  314. * u16 reserved_1; + 0x08
  315. * u16 dlen; + 0x0a
  316. * u8 drevision; + 0x0c
  317. * u8 class_hi; + 0x0d
  318. * u16 class_lo; + 0x0e
  319. * u16 ilen; + 0x10
  320. * u16 irevision; + 0x12
  321. * u8 type; + 0x14
  322. * u8 indicator; + 0x15
  323. * u16 reserved_2; + 0x16
  324. * } pci_data_t;
  325. */
  326. if (BIOS_IN32(dptr) != (('R' << 24) | ('I' << 16) | ('C' << 8) | 'P')) {
  327. printk(KERN_WARNING "radeonfb (%s): PCI DATA signature in ROM"
  328. "incorrect: %08x\n", pci_name(rinfo->pdev), BIOS_IN32(dptr));
  329. goto anyway;
  330. }
  331. rom_type = BIOS_IN8(dptr + 0x14);
  332. switch(rom_type) {
  333. case 0:
  334. printk(KERN_INFO "radeonfb: Found Intel x86 BIOS ROM Image\n");
  335. break;
  336. case 1:
  337. printk(KERN_INFO "radeonfb: Found Open Firmware ROM Image\n");
  338. goto failed;
  339. case 2:
  340. printk(KERN_INFO "radeonfb: Found HP PA-RISC ROM Image\n");
  341. goto failed;
  342. default:
  343. printk(KERN_INFO "radeonfb: Found unknown type %d ROM Image\n", rom_type);
  344. goto failed;
  345. }
  346. anyway:
  347. /* Locate the flat panel infos, do some sanity checking !!! */
  348. rinfo->fp_bios_start = BIOS_IN16(0x48);
  349. return 0;
  350. failed:
  351. rinfo->bios_seg = NULL;
  352. radeon_unmap_ROM(rinfo, dev);
  353. return -ENXIO;
  354. }
  355. #ifdef CONFIG_X86
  356. static int __devinit radeon_find_mem_vbios(struct radeonfb_info *rinfo)
  357. {
  358. /* I simplified this code as we used to miss the signatures in
  359. * a lot of case. It's now closer to XFree, we just don't check
  360. * for signatures at all... Something better will have to be done
  361. * if we end up having conflicts
  362. */
  363. u32 segstart;
  364. void __iomem *rom_base = NULL;
  365. for(segstart=0x000c0000; segstart<0x000f0000; segstart+=0x00001000) {
  366. rom_base = ioremap(segstart, 0x10000);
  367. if (rom_base == NULL)
  368. return -ENOMEM;
  369. if (readb(rom_base) == 0x55 && readb(rom_base + 1) == 0xaa)
  370. break;
  371. iounmap(rom_base);
  372. rom_base = NULL;
  373. }
  374. if (rom_base == NULL)
  375. return -ENXIO;
  376. /* Locate the flat panel infos, do some sanity checking !!! */
  377. rinfo->bios_seg = rom_base;
  378. rinfo->fp_bios_start = BIOS_IN16(0x48);
  379. return 0;
  380. }
  381. #endif
  382. #if defined(CONFIG_PPC_OF) || defined(CONFIG_SPARC)
  383. /*
  384. * Read XTAL (ref clock), SCLK and MCLK from Open Firmware device
  385. * tree. Hopefully, ATI OF driver is kind enough to fill these
  386. */
  387. static int __devinit radeon_read_xtal_OF (struct radeonfb_info *rinfo)
  388. {
  389. struct device_node *dp = rinfo->of_node;
  390. const u32 *val;
  391. if (dp == NULL)
  392. return -ENODEV;
  393. val = of_get_property(dp, "ATY,RefCLK", NULL);
  394. if (!val || !*val) {
  395. printk(KERN_WARNING "radeonfb: No ATY,RefCLK property !\n");
  396. return -EINVAL;
  397. }
  398. rinfo->pll.ref_clk = (*val) / 10;
  399. val = of_get_property(dp, "ATY,SCLK", NULL);
  400. if (val && *val)
  401. rinfo->pll.sclk = (*val) / 10;
  402. val = of_get_property(dp, "ATY,MCLK", NULL);
  403. if (val && *val)
  404. rinfo->pll.mclk = (*val) / 10;
  405. return 0;
  406. }
  407. #endif /* CONFIG_PPC_OF || CONFIG_SPARC */
  408. /*
  409. * Read PLL infos from chip registers
  410. */
  411. static int __devinit radeon_probe_pll_params(struct radeonfb_info *rinfo)
  412. {
  413. unsigned char ppll_div_sel;
  414. unsigned Ns, Nm, M;
  415. unsigned sclk, mclk, tmp, ref_div;
  416. int hTotal, vTotal, num, denom, m, n;
  417. unsigned long long hz, vclk;
  418. long xtal;
  419. struct timeval start_tv, stop_tv;
  420. long total_secs, total_usecs;
  421. int i;
  422. /* Ugh, we cut interrupts, bad bad bad, but we want some precision
  423. * here, so... --BenH
  424. */
  425. /* Flush PCI buffers ? */
  426. tmp = INREG16(DEVICE_ID);
  427. local_irq_disable();
  428. for(i=0; i<1000000; i++)
  429. if (((INREG(CRTC_VLINE_CRNT_VLINE) >> 16) & 0x3ff) == 0)
  430. break;
  431. do_gettimeofday(&start_tv);
  432. for(i=0; i<1000000; i++)
  433. if (((INREG(CRTC_VLINE_CRNT_VLINE) >> 16) & 0x3ff) != 0)
  434. break;
  435. for(i=0; i<1000000; i++)
  436. if (((INREG(CRTC_VLINE_CRNT_VLINE) >> 16) & 0x3ff) == 0)
  437. break;
  438. do_gettimeofday(&stop_tv);
  439. local_irq_enable();
  440. total_secs = stop_tv.tv_sec - start_tv.tv_sec;
  441. if (total_secs > 10)
  442. return -1;
  443. total_usecs = stop_tv.tv_usec - start_tv.tv_usec;
  444. total_usecs += total_secs * 1000000;
  445. if (total_usecs < 0)
  446. total_usecs = -total_usecs;
  447. hz = 1000000/total_usecs;
  448. hTotal = ((INREG(CRTC_H_TOTAL_DISP) & 0x1ff) + 1) * 8;
  449. vTotal = ((INREG(CRTC_V_TOTAL_DISP) & 0x3ff) + 1);
  450. vclk = (long long)hTotal * (long long)vTotal * hz;
  451. switch((INPLL(PPLL_REF_DIV) & 0x30000) >> 16) {
  452. case 0:
  453. default:
  454. num = 1;
  455. denom = 1;
  456. break;
  457. case 1:
  458. n = ((INPLL(M_SPLL_REF_FB_DIV) >> 16) & 0xff);
  459. m = (INPLL(M_SPLL_REF_FB_DIV) & 0xff);
  460. num = 2*n;
  461. denom = 2*m;
  462. break;
  463. case 2:
  464. n = ((INPLL(M_SPLL_REF_FB_DIV) >> 8) & 0xff);
  465. m = (INPLL(M_SPLL_REF_FB_DIV) & 0xff);
  466. num = 2*n;
  467. denom = 2*m;
  468. break;
  469. }
  470. ppll_div_sel = INREG8(CLOCK_CNTL_INDEX + 1) & 0x3;
  471. radeon_pll_errata_after_index(rinfo);
  472. n = (INPLL(PPLL_DIV_0 + ppll_div_sel) & 0x7ff);
  473. m = (INPLL(PPLL_REF_DIV) & 0x3ff);
  474. num *= n;
  475. denom *= m;
  476. switch ((INPLL(PPLL_DIV_0 + ppll_div_sel) >> 16) & 0x7) {
  477. case 1:
  478. denom *= 2;
  479. break;
  480. case 2:
  481. denom *= 4;
  482. break;
  483. case 3:
  484. denom *= 8;
  485. break;
  486. case 4:
  487. denom *= 3;
  488. break;
  489. case 6:
  490. denom *= 6;
  491. break;
  492. case 7:
  493. denom *= 12;
  494. break;
  495. }
  496. vclk *= denom;
  497. do_div(vclk, 1000 * num);
  498. xtal = vclk;
  499. if ((xtal > 26900) && (xtal < 27100))
  500. xtal = 2700;
  501. else if ((xtal > 14200) && (xtal < 14400))
  502. xtal = 1432;
  503. else if ((xtal > 29400) && (xtal < 29600))
  504. xtal = 2950;
  505. else {
  506. printk(KERN_WARNING "xtal calculation failed: %ld\n", xtal);
  507. return -1;
  508. }
  509. tmp = INPLL(M_SPLL_REF_FB_DIV);
  510. ref_div = INPLL(PPLL_REF_DIV) & 0x3ff;
  511. Ns = (tmp & 0xff0000) >> 16;
  512. Nm = (tmp & 0xff00) >> 8;
  513. M = (tmp & 0xff);
  514. sclk = round_div((2 * Ns * xtal), (2 * M));
  515. mclk = round_div((2 * Nm * xtal), (2 * M));
  516. /* we're done, hopefully these are sane values */
  517. rinfo->pll.ref_clk = xtal;
  518. rinfo->pll.ref_div = ref_div;
  519. rinfo->pll.sclk = sclk;
  520. rinfo->pll.mclk = mclk;
  521. return 0;
  522. }
  523. /*
  524. * Retrieve PLL infos by different means (BIOS, Open Firmware, register probing...)
  525. */
  526. static void __devinit radeon_get_pllinfo(struct radeonfb_info *rinfo)
  527. {
  528. /*
  529. * In the case nothing works, these are defaults; they are mostly
  530. * incomplete, however. It does provide ppll_max and _min values
  531. * even for most other methods, however.
  532. */
  533. switch (rinfo->chipset) {
  534. case PCI_DEVICE_ID_ATI_RADEON_QW:
  535. case PCI_DEVICE_ID_ATI_RADEON_QX:
  536. rinfo->pll.ppll_max = 35000;
  537. rinfo->pll.ppll_min = 12000;
  538. rinfo->pll.mclk = 23000;
  539. rinfo->pll.sclk = 23000;
  540. rinfo->pll.ref_clk = 2700;
  541. break;
  542. case PCI_DEVICE_ID_ATI_RADEON_QL:
  543. case PCI_DEVICE_ID_ATI_RADEON_QN:
  544. case PCI_DEVICE_ID_ATI_RADEON_QO:
  545. case PCI_DEVICE_ID_ATI_RADEON_Ql:
  546. case PCI_DEVICE_ID_ATI_RADEON_BB:
  547. rinfo->pll.ppll_max = 35000;
  548. rinfo->pll.ppll_min = 12000;
  549. rinfo->pll.mclk = 27500;
  550. rinfo->pll.sclk = 27500;
  551. rinfo->pll.ref_clk = 2700;
  552. break;
  553. case PCI_DEVICE_ID_ATI_RADEON_Id:
  554. case PCI_DEVICE_ID_ATI_RADEON_Ie:
  555. case PCI_DEVICE_ID_ATI_RADEON_If:
  556. case PCI_DEVICE_ID_ATI_RADEON_Ig:
  557. rinfo->pll.ppll_max = 35000;
  558. rinfo->pll.ppll_min = 12000;
  559. rinfo->pll.mclk = 25000;
  560. rinfo->pll.sclk = 25000;
  561. rinfo->pll.ref_clk = 2700;
  562. break;
  563. case PCI_DEVICE_ID_ATI_RADEON_ND:
  564. case PCI_DEVICE_ID_ATI_RADEON_NE:
  565. case PCI_DEVICE_ID_ATI_RADEON_NF:
  566. case PCI_DEVICE_ID_ATI_RADEON_NG:
  567. rinfo->pll.ppll_max = 40000;
  568. rinfo->pll.ppll_min = 20000;
  569. rinfo->pll.mclk = 27000;
  570. rinfo->pll.sclk = 27000;
  571. rinfo->pll.ref_clk = 2700;
  572. break;
  573. case PCI_DEVICE_ID_ATI_RADEON_QD:
  574. case PCI_DEVICE_ID_ATI_RADEON_QE:
  575. case PCI_DEVICE_ID_ATI_RADEON_QF:
  576. case PCI_DEVICE_ID_ATI_RADEON_QG:
  577. default:
  578. rinfo->pll.ppll_max = 35000;
  579. rinfo->pll.ppll_min = 12000;
  580. rinfo->pll.mclk = 16600;
  581. rinfo->pll.sclk = 16600;
  582. rinfo->pll.ref_clk = 2700;
  583. break;
  584. }
  585. rinfo->pll.ref_div = INPLL(PPLL_REF_DIV) & PPLL_REF_DIV_MASK;
  586. #if defined(CONFIG_PPC_OF) || defined(CONFIG_SPARC)
  587. /*
  588. * Retrieve PLL infos from Open Firmware first
  589. */
  590. if (!force_measure_pll && radeon_read_xtal_OF(rinfo) == 0) {
  591. printk(KERN_INFO "radeonfb: Retrieved PLL infos from Open Firmware\n");
  592. goto found;
  593. }
  594. #endif /* CONFIG_PPC_OF || CONFIG_SPARC */
  595. /*
  596. * Check out if we have an X86 which gave us some PLL informations
  597. * and if yes, retrieve them
  598. */
  599. if (!force_measure_pll && rinfo->bios_seg) {
  600. u16 pll_info_block = BIOS_IN16(rinfo->fp_bios_start + 0x30);
  601. rinfo->pll.sclk = BIOS_IN16(pll_info_block + 0x08);
  602. rinfo->pll.mclk = BIOS_IN16(pll_info_block + 0x0a);
  603. rinfo->pll.ref_clk = BIOS_IN16(pll_info_block + 0x0e);
  604. rinfo->pll.ref_div = BIOS_IN16(pll_info_block + 0x10);
  605. rinfo->pll.ppll_min = BIOS_IN32(pll_info_block + 0x12);
  606. rinfo->pll.ppll_max = BIOS_IN32(pll_info_block + 0x16);
  607. printk(KERN_INFO "radeonfb: Retrieved PLL infos from BIOS\n");
  608. goto found;
  609. }
  610. /*
  611. * We didn't get PLL parameters from either OF or BIOS, we try to
  612. * probe them
  613. */
  614. if (radeon_probe_pll_params(rinfo) == 0) {
  615. printk(KERN_INFO "radeonfb: Retrieved PLL infos from registers\n");
  616. goto found;
  617. }
  618. /*
  619. * Fall back to already-set defaults...
  620. */
  621. printk(KERN_INFO "radeonfb: Used default PLL infos\n");
  622. found:
  623. /*
  624. * Some methods fail to retrieve SCLK and MCLK values, we apply default
  625. * settings in this case (200Mhz). If that really happne often, we could
  626. * fetch from registers instead...
  627. */
  628. if (rinfo->pll.mclk == 0)
  629. rinfo->pll.mclk = 20000;
  630. if (rinfo->pll.sclk == 0)
  631. rinfo->pll.sclk = 20000;
  632. printk("radeonfb: Reference=%d.%02d MHz (RefDiv=%d) Memory=%d.%02d Mhz, System=%d.%02d MHz\n",
  633. rinfo->pll.ref_clk / 100, rinfo->pll.ref_clk % 100,
  634. rinfo->pll.ref_div,
  635. rinfo->pll.mclk / 100, rinfo->pll.mclk % 100,
  636. rinfo->pll.sclk / 100, rinfo->pll.sclk % 100);
  637. printk("radeonfb: PLL min %d max %d\n", rinfo->pll.ppll_min, rinfo->pll.ppll_max);
  638. }
  639. static int radeonfb_check_var (struct fb_var_screeninfo *var, struct fb_info *info)
  640. {
  641. struct radeonfb_info *rinfo = info->par;
  642. struct fb_var_screeninfo v;
  643. int nom, den;
  644. unsigned int pitch;
  645. if (radeon_match_mode(rinfo, &v, var))
  646. return -EINVAL;
  647. switch (v.bits_per_pixel) {
  648. case 0 ... 8:
  649. v.bits_per_pixel = 8;
  650. break;
  651. case 9 ... 16:
  652. v.bits_per_pixel = 16;
  653. break;
  654. case 17 ... 24:
  655. #if 0 /* Doesn't seem to work */
  656. v.bits_per_pixel = 24;
  657. break;
  658. #endif
  659. return -EINVAL;
  660. case 25 ... 32:
  661. v.bits_per_pixel = 32;
  662. break;
  663. default:
  664. return -EINVAL;
  665. }
  666. switch (var_to_depth(&v)) {
  667. case 8:
  668. nom = den = 1;
  669. v.red.offset = v.green.offset = v.blue.offset = 0;
  670. v.red.length = v.green.length = v.blue.length = 8;
  671. v.transp.offset = v.transp.length = 0;
  672. break;
  673. case 15:
  674. nom = 2;
  675. den = 1;
  676. v.red.offset = 10;
  677. v.green.offset = 5;
  678. v.blue.offset = 0;
  679. v.red.length = v.green.length = v.blue.length = 5;
  680. v.transp.offset = v.transp.length = 0;
  681. break;
  682. case 16:
  683. nom = 2;
  684. den = 1;
  685. v.red.offset = 11;
  686. v.green.offset = 5;
  687. v.blue.offset = 0;
  688. v.red.length = 5;
  689. v.green.length = 6;
  690. v.blue.length = 5;
  691. v.transp.offset = v.transp.length = 0;
  692. break;
  693. case 24:
  694. nom = 4;
  695. den = 1;
  696. v.red.offset = 16;
  697. v.green.offset = 8;
  698. v.blue.offset = 0;
  699. v.red.length = v.blue.length = v.green.length = 8;
  700. v.transp.offset = v.transp.length = 0;
  701. break;
  702. case 32:
  703. nom = 4;
  704. den = 1;
  705. v.red.offset = 16;
  706. v.green.offset = 8;
  707. v.blue.offset = 0;
  708. v.red.length = v.blue.length = v.green.length = 8;
  709. v.transp.offset = 24;
  710. v.transp.length = 8;
  711. break;
  712. default:
  713. printk ("radeonfb: mode %dx%dx%d rejected, color depth invalid\n",
  714. var->xres, var->yres, var->bits_per_pixel);
  715. return -EINVAL;
  716. }
  717. if (v.yres_virtual < v.yres)
  718. v.yres_virtual = v.yres;
  719. if (v.xres_virtual < v.xres)
  720. v.xres_virtual = v.xres;
  721. /* XXX I'm adjusting xres_virtual to the pitch, that may help XFree
  722. * with some panels, though I don't quite like this solution
  723. */
  724. if (rinfo->info->flags & FBINFO_HWACCEL_DISABLED) {
  725. v.xres_virtual = v.xres_virtual & ~7ul;
  726. } else {
  727. pitch = ((v.xres_virtual * ((v.bits_per_pixel + 1) / 8) + 0x3f)
  728. & ~(0x3f)) >> 6;
  729. v.xres_virtual = (pitch << 6) / ((v.bits_per_pixel + 1) / 8);
  730. }
  731. if (((v.xres_virtual * v.yres_virtual * nom) / den) > rinfo->mapped_vram)
  732. return -EINVAL;
  733. if (v.xres_virtual < v.xres)
  734. v.xres = v.xres_virtual;
  735. if (v.xoffset < 0)
  736. v.xoffset = 0;
  737. if (v.yoffset < 0)
  738. v.yoffset = 0;
  739. if (v.xoffset > v.xres_virtual - v.xres)
  740. v.xoffset = v.xres_virtual - v.xres - 1;
  741. if (v.yoffset > v.yres_virtual - v.yres)
  742. v.yoffset = v.yres_virtual - v.yres - 1;
  743. v.red.msb_right = v.green.msb_right = v.blue.msb_right =
  744. v.transp.offset = v.transp.length =
  745. v.transp.msb_right = 0;
  746. memcpy(var, &v, sizeof(v));
  747. return 0;
  748. }
  749. static int radeonfb_pan_display (struct fb_var_screeninfo *var,
  750. struct fb_info *info)
  751. {
  752. struct radeonfb_info *rinfo = info->par;
  753. if ((var->xoffset + var->xres > var->xres_virtual)
  754. || (var->yoffset + var->yres > var->yres_virtual))
  755. return -EINVAL;
  756. if (rinfo->asleep)
  757. return 0;
  758. radeon_fifo_wait(2);
  759. OUTREG(CRTC_OFFSET, ((var->yoffset * var->xres_virtual + var->xoffset)
  760. * var->bits_per_pixel / 8) & ~7);
  761. return 0;
  762. }
  763. static int radeonfb_ioctl (struct fb_info *info, unsigned int cmd,
  764. unsigned long arg)
  765. {
  766. struct radeonfb_info *rinfo = info->par;
  767. unsigned int tmp;
  768. u32 value = 0;
  769. int rc;
  770. switch (cmd) {
  771. /*
  772. * TODO: set mirror accordingly for non-Mobility chipsets with 2 CRTC's
  773. * and do something better using 2nd CRTC instead of just hackish
  774. * routing to second output
  775. */
  776. case FBIO_RADEON_SET_MIRROR:
  777. if (!rinfo->is_mobility)
  778. return -EINVAL;
  779. rc = get_user(value, (__u32 __user *)arg);
  780. if (rc)
  781. return rc;
  782. radeon_fifo_wait(2);
  783. if (value & 0x01) {
  784. tmp = INREG(LVDS_GEN_CNTL);
  785. tmp |= (LVDS_ON | LVDS_BLON);
  786. } else {
  787. tmp = INREG(LVDS_GEN_CNTL);
  788. tmp &= ~(LVDS_ON | LVDS_BLON);
  789. }
  790. OUTREG(LVDS_GEN_CNTL, tmp);
  791. if (value & 0x02) {
  792. tmp = INREG(CRTC_EXT_CNTL);
  793. tmp |= CRTC_CRT_ON;
  794. mirror = 1;
  795. } else {
  796. tmp = INREG(CRTC_EXT_CNTL);
  797. tmp &= ~CRTC_CRT_ON;
  798. mirror = 0;
  799. }
  800. OUTREG(CRTC_EXT_CNTL, tmp);
  801. return 0;
  802. case FBIO_RADEON_GET_MIRROR:
  803. if (!rinfo->is_mobility)
  804. return -EINVAL;
  805. tmp = INREG(LVDS_GEN_CNTL);
  806. if ((LVDS_ON | LVDS_BLON) & tmp)
  807. value |= 0x01;
  808. tmp = INREG(CRTC_EXT_CNTL);
  809. if (CRTC_CRT_ON & tmp)
  810. value |= 0x02;
  811. return put_user(value, (__u32 __user *)arg);
  812. default:
  813. return -EINVAL;
  814. }
  815. return -EINVAL;
  816. }
  817. int radeon_screen_blank(struct radeonfb_info *rinfo, int blank, int mode_switch)
  818. {
  819. u32 val;
  820. u32 tmp_pix_clks;
  821. int unblank = 0;
  822. if (rinfo->lock_blank)
  823. return 0;
  824. radeon_engine_idle();
  825. val = INREG(CRTC_EXT_CNTL);
  826. val &= ~(CRTC_DISPLAY_DIS | CRTC_HSYNC_DIS |
  827. CRTC_VSYNC_DIS);
  828. switch (blank) {
  829. case FB_BLANK_VSYNC_SUSPEND:
  830. val |= (CRTC_DISPLAY_DIS | CRTC_VSYNC_DIS);
  831. break;
  832. case FB_BLANK_HSYNC_SUSPEND:
  833. val |= (CRTC_DISPLAY_DIS | CRTC_HSYNC_DIS);
  834. break;
  835. case FB_BLANK_POWERDOWN:
  836. val |= (CRTC_DISPLAY_DIS | CRTC_VSYNC_DIS |
  837. CRTC_HSYNC_DIS);
  838. break;
  839. case FB_BLANK_NORMAL:
  840. val |= CRTC_DISPLAY_DIS;
  841. break;
  842. case FB_BLANK_UNBLANK:
  843. default:
  844. unblank = 1;
  845. }
  846. OUTREG(CRTC_EXT_CNTL, val);
  847. switch (rinfo->mon1_type) {
  848. case MT_DFP:
  849. if (unblank)
  850. OUTREGP(FP_GEN_CNTL, (FP_FPON | FP_TMDS_EN),
  851. ~(FP_FPON | FP_TMDS_EN));
  852. else {
  853. if (mode_switch || blank == FB_BLANK_NORMAL)
  854. break;
  855. OUTREGP(FP_GEN_CNTL, 0, ~(FP_FPON | FP_TMDS_EN));
  856. }
  857. break;
  858. case MT_LCD:
  859. del_timer_sync(&rinfo->lvds_timer);
  860. val = INREG(LVDS_GEN_CNTL);
  861. if (unblank) {
  862. u32 target_val = (val & ~LVDS_DISPLAY_DIS) | LVDS_BLON | LVDS_ON
  863. | LVDS_EN | (rinfo->init_state.lvds_gen_cntl
  864. & (LVDS_DIGON | LVDS_BL_MOD_EN));
  865. if ((val ^ target_val) == LVDS_DISPLAY_DIS)
  866. OUTREG(LVDS_GEN_CNTL, target_val);
  867. else if ((val ^ target_val) != 0) {
  868. OUTREG(LVDS_GEN_CNTL, target_val
  869. & ~(LVDS_ON | LVDS_BL_MOD_EN));
  870. rinfo->init_state.lvds_gen_cntl &= ~LVDS_STATE_MASK;
  871. rinfo->init_state.lvds_gen_cntl |=
  872. target_val & LVDS_STATE_MASK;
  873. if (mode_switch) {
  874. radeon_msleep(rinfo->panel_info.pwr_delay);
  875. OUTREG(LVDS_GEN_CNTL, target_val);
  876. }
  877. else {
  878. rinfo->pending_lvds_gen_cntl = target_val;
  879. mod_timer(&rinfo->lvds_timer,
  880. jiffies +
  881. msecs_to_jiffies(rinfo->panel_info.pwr_delay));
  882. }
  883. }
  884. } else {
  885. val |= LVDS_DISPLAY_DIS;
  886. OUTREG(LVDS_GEN_CNTL, val);
  887. /* We don't do a full switch-off on a simple mode switch */
  888. if (mode_switch || blank == FB_BLANK_NORMAL)
  889. break;
  890. /* Asic bug, when turning off LVDS_ON, we have to make sure
  891. * RADEON_PIXCLK_LVDS_ALWAYS_ON bit is off
  892. */
  893. tmp_pix_clks = INPLL(PIXCLKS_CNTL);
  894. if (rinfo->is_mobility || rinfo->is_IGP)
  895. OUTPLLP(PIXCLKS_CNTL, 0, ~PIXCLK_LVDS_ALWAYS_ONb);
  896. val &= ~(LVDS_BL_MOD_EN);
  897. OUTREG(LVDS_GEN_CNTL, val);
  898. udelay(100);
  899. val &= ~(LVDS_ON | LVDS_EN);
  900. OUTREG(LVDS_GEN_CNTL, val);
  901. val &= ~LVDS_DIGON;
  902. rinfo->pending_lvds_gen_cntl = val;
  903. mod_timer(&rinfo->lvds_timer,
  904. jiffies +
  905. msecs_to_jiffies(rinfo->panel_info.pwr_delay));
  906. rinfo->init_state.lvds_gen_cntl &= ~LVDS_STATE_MASK;
  907. rinfo->init_state.lvds_gen_cntl |= val & LVDS_STATE_MASK;
  908. if (rinfo->is_mobility || rinfo->is_IGP)
  909. OUTPLL(PIXCLKS_CNTL, tmp_pix_clks);
  910. }
  911. break;
  912. case MT_CRT:
  913. // todo: powerdown DAC
  914. default:
  915. break;
  916. }
  917. return 0;
  918. }
  919. static int radeonfb_blank (int blank, struct fb_info *info)
  920. {
  921. struct radeonfb_info *rinfo = info->par;
  922. if (rinfo->asleep)
  923. return 0;
  924. return radeon_screen_blank(rinfo, blank, 0);
  925. }
  926. static int radeon_setcolreg (unsigned regno, unsigned red, unsigned green,
  927. unsigned blue, unsigned transp,
  928. struct radeonfb_info *rinfo)
  929. {
  930. u32 pindex;
  931. unsigned int i;
  932. if (regno > 255)
  933. return -EINVAL;
  934. red >>= 8;
  935. green >>= 8;
  936. blue >>= 8;
  937. rinfo->palette[regno].red = red;
  938. rinfo->palette[regno].green = green;
  939. rinfo->palette[regno].blue = blue;
  940. /* default */
  941. pindex = regno;
  942. if (!rinfo->asleep) {
  943. radeon_fifo_wait(9);
  944. if (rinfo->bpp == 16) {
  945. pindex = regno * 8;
  946. if (rinfo->depth == 16 && regno > 63)
  947. return -EINVAL;
  948. if (rinfo->depth == 15 && regno > 31)
  949. return -EINVAL;
  950. /* For 565, the green component is mixed one order
  951. * below
  952. */
  953. if (rinfo->depth == 16) {
  954. OUTREG(PALETTE_INDEX, pindex>>1);
  955. OUTREG(PALETTE_DATA,
  956. (rinfo->palette[regno>>1].red << 16) |
  957. (green << 8) |
  958. (rinfo->palette[regno>>1].blue));
  959. green = rinfo->palette[regno<<1].green;
  960. }
  961. }
  962. if (rinfo->depth != 16 || regno < 32) {
  963. OUTREG(PALETTE_INDEX, pindex);
  964. OUTREG(PALETTE_DATA, (red << 16) |
  965. (green << 8) | blue);
  966. }
  967. }
  968. if (regno < 16) {
  969. u32 *pal = rinfo->info->pseudo_palette;
  970. switch (rinfo->depth) {
  971. case 15:
  972. pal[regno] = (regno << 10) | (regno << 5) | regno;
  973. break;
  974. case 16:
  975. pal[regno] = (regno << 11) | (regno << 5) | regno;
  976. break;
  977. case 24:
  978. pal[regno] = (regno << 16) | (regno << 8) | regno;
  979. break;
  980. case 32:
  981. i = (regno << 8) | regno;
  982. pal[regno] = (i << 16) | i;
  983. break;
  984. }
  985. }
  986. return 0;
  987. }
  988. static int radeonfb_setcolreg (unsigned regno, unsigned red, unsigned green,
  989. unsigned blue, unsigned transp,
  990. struct fb_info *info)
  991. {
  992. struct radeonfb_info *rinfo = info->par;
  993. u32 dac_cntl2, vclk_cntl = 0;
  994. int rc;
  995. if (!rinfo->asleep) {
  996. if (rinfo->is_mobility) {
  997. vclk_cntl = INPLL(VCLK_ECP_CNTL);
  998. OUTPLL(VCLK_ECP_CNTL,
  999. vclk_cntl & ~PIXCLK_DAC_ALWAYS_ONb);
  1000. }
  1001. /* Make sure we are on first palette */
  1002. if (rinfo->has_CRTC2) {
  1003. dac_cntl2 = INREG(DAC_CNTL2);
  1004. dac_cntl2 &= ~DAC2_PALETTE_ACCESS_CNTL;
  1005. OUTREG(DAC_CNTL2, dac_cntl2);
  1006. }
  1007. }
  1008. rc = radeon_setcolreg (regno, red, green, blue, transp, rinfo);
  1009. if (!rinfo->asleep && rinfo->is_mobility)
  1010. OUTPLL(VCLK_ECP_CNTL, vclk_cntl);
  1011. return rc;
  1012. }
  1013. static int radeonfb_setcmap(struct fb_cmap *cmap, struct fb_info *info)
  1014. {
  1015. struct radeonfb_info *rinfo = info->par;
  1016. u16 *red, *green, *blue, *transp;
  1017. u32 dac_cntl2, vclk_cntl = 0;
  1018. int i, start, rc = 0;
  1019. if (!rinfo->asleep) {
  1020. if (rinfo->is_mobility) {
  1021. vclk_cntl = INPLL(VCLK_ECP_CNTL);
  1022. OUTPLL(VCLK_ECP_CNTL,
  1023. vclk_cntl & ~PIXCLK_DAC_ALWAYS_ONb);
  1024. }
  1025. /* Make sure we are on first palette */
  1026. if (rinfo->has_CRTC2) {
  1027. dac_cntl2 = INREG(DAC_CNTL2);
  1028. dac_cntl2 &= ~DAC2_PALETTE_ACCESS_CNTL;
  1029. OUTREG(DAC_CNTL2, dac_cntl2);
  1030. }
  1031. }
  1032. red = cmap->red;
  1033. green = cmap->green;
  1034. blue = cmap->blue;
  1035. transp = cmap->transp;
  1036. start = cmap->start;
  1037. for (i = 0; i < cmap->len; i++) {
  1038. u_int hred, hgreen, hblue, htransp = 0xffff;
  1039. hred = *red++;
  1040. hgreen = *green++;
  1041. hblue = *blue++;
  1042. if (transp)
  1043. htransp = *transp++;
  1044. rc = radeon_setcolreg (start++, hred, hgreen, hblue, htransp,
  1045. rinfo);
  1046. if (rc)
  1047. break;
  1048. }
  1049. if (!rinfo->asleep && rinfo->is_mobility)
  1050. OUTPLL(VCLK_ECP_CNTL, vclk_cntl);
  1051. return rc;
  1052. }
  1053. static void radeon_save_state (struct radeonfb_info *rinfo,
  1054. struct radeon_regs *save)
  1055. {
  1056. /* CRTC regs */
  1057. save->crtc_gen_cntl = INREG(CRTC_GEN_CNTL);
  1058. save->crtc_ext_cntl = INREG(CRTC_EXT_CNTL);
  1059. save->crtc_more_cntl = INREG(CRTC_MORE_CNTL);
  1060. save->dac_cntl = INREG(DAC_CNTL);
  1061. save->crtc_h_total_disp = INREG(CRTC_H_TOTAL_DISP);
  1062. save->crtc_h_sync_strt_wid = INREG(CRTC_H_SYNC_STRT_WID);
  1063. save->crtc_v_total_disp = INREG(CRTC_V_TOTAL_DISP);
  1064. save->crtc_v_sync_strt_wid = INREG(CRTC_V_SYNC_STRT_WID);
  1065. save->crtc_pitch = INREG(CRTC_PITCH);
  1066. save->surface_cntl = INREG(SURFACE_CNTL);
  1067. /* FP regs */
  1068. save->fp_crtc_h_total_disp = INREG(FP_CRTC_H_TOTAL_DISP);
  1069. save->fp_crtc_v_total_disp = INREG(FP_CRTC_V_TOTAL_DISP);
  1070. save->fp_gen_cntl = INREG(FP_GEN_CNTL);
  1071. save->fp_h_sync_strt_wid = INREG(FP_H_SYNC_STRT_WID);
  1072. save->fp_horz_stretch = INREG(FP_HORZ_STRETCH);
  1073. save->fp_v_sync_strt_wid = INREG(FP_V_SYNC_STRT_WID);
  1074. save->fp_vert_stretch = INREG(FP_VERT_STRETCH);
  1075. save->lvds_gen_cntl = INREG(LVDS_GEN_CNTL);
  1076. save->lvds_pll_cntl = INREG(LVDS_PLL_CNTL);
  1077. save->tmds_crc = INREG(TMDS_CRC);
  1078. save->tmds_transmitter_cntl = INREG(TMDS_TRANSMITTER_CNTL);
  1079. save->vclk_ecp_cntl = INPLL(VCLK_ECP_CNTL);
  1080. /* PLL regs */
  1081. save->clk_cntl_index = INREG(CLOCK_CNTL_INDEX) & ~0x3f;
  1082. radeon_pll_errata_after_index(rinfo);
  1083. save->ppll_div_3 = INPLL(PPLL_DIV_3);
  1084. save->ppll_ref_div = INPLL(PPLL_REF_DIV);
  1085. }
  1086. static void radeon_write_pll_regs(struct radeonfb_info *rinfo, struct radeon_regs *mode)
  1087. {
  1088. int i;
  1089. radeon_fifo_wait(20);
  1090. /* Workaround from XFree */
  1091. if (rinfo->is_mobility) {
  1092. /* A temporal workaround for the occational blanking on certain laptop
  1093. * panels. This appears to related to the PLL divider registers
  1094. * (fail to lock?). It occurs even when all dividers are the same
  1095. * with their old settings. In this case we really don't need to
  1096. * fiddle with PLL registers. By doing this we can avoid the blanking
  1097. * problem with some panels.
  1098. */
  1099. if ((mode->ppll_ref_div == (INPLL(PPLL_REF_DIV) & PPLL_REF_DIV_MASK)) &&
  1100. (mode->ppll_div_3 == (INPLL(PPLL_DIV_3) &
  1101. (PPLL_POST3_DIV_MASK | PPLL_FB3_DIV_MASK)))) {
  1102. /* We still have to force a switch to selected PPLL div thanks to
  1103. * an XFree86 driver bug which will switch it away in some cases
  1104. * even when using UseFDev */
  1105. OUTREGP(CLOCK_CNTL_INDEX,
  1106. mode->clk_cntl_index & PPLL_DIV_SEL_MASK,
  1107. ~PPLL_DIV_SEL_MASK);
  1108. radeon_pll_errata_after_index(rinfo);
  1109. radeon_pll_errata_after_data(rinfo);
  1110. return;
  1111. }
  1112. }
  1113. /* Swich VCKL clock input to CPUCLK so it stays fed while PPLL updates*/
  1114. OUTPLLP(VCLK_ECP_CNTL, VCLK_SRC_SEL_CPUCLK, ~VCLK_SRC_SEL_MASK);
  1115. /* Reset PPLL & enable atomic update */
  1116. OUTPLLP(PPLL_CNTL,
  1117. PPLL_RESET | PPLL_ATOMIC_UPDATE_EN | PPLL_VGA_ATOMIC_UPDATE_EN,
  1118. ~(PPLL_RESET | PPLL_ATOMIC_UPDATE_EN | PPLL_VGA_ATOMIC_UPDATE_EN));
  1119. /* Switch to selected PPLL divider */
  1120. OUTREGP(CLOCK_CNTL_INDEX,
  1121. mode->clk_cntl_index & PPLL_DIV_SEL_MASK,
  1122. ~PPLL_DIV_SEL_MASK);
  1123. radeon_pll_errata_after_index(rinfo);
  1124. radeon_pll_errata_after_data(rinfo);
  1125. /* Set PPLL ref. div */
  1126. if (rinfo->family == CHIP_FAMILY_R300 ||
  1127. rinfo->family == CHIP_FAMILY_RS300 ||
  1128. rinfo->family == CHIP_FAMILY_R350 ||
  1129. rinfo->family == CHIP_FAMILY_RV350 ||
  1130. rinfo->family == CHIP_FAMILY_RV380 ) {
  1131. if (mode->ppll_ref_div & R300_PPLL_REF_DIV_ACC_MASK) {
  1132. /* When restoring console mode, use saved PPLL_REF_DIV
  1133. * setting.
  1134. */
  1135. OUTPLLP(PPLL_REF_DIV, mode->ppll_ref_div, 0);
  1136. } else {
  1137. /* R300 uses ref_div_acc field as real ref divider */
  1138. OUTPLLP(PPLL_REF_DIV,
  1139. (mode->ppll_ref_div << R300_PPLL_REF_DIV_ACC_SHIFT),
  1140. ~R300_PPLL_REF_DIV_ACC_MASK);
  1141. }
  1142. } else
  1143. OUTPLLP(PPLL_REF_DIV, mode->ppll_ref_div, ~PPLL_REF_DIV_MASK);
  1144. /* Set PPLL divider 3 & post divider*/
  1145. OUTPLLP(PPLL_DIV_3, mode->ppll_div_3, ~PPLL_FB3_DIV_MASK);
  1146. OUTPLLP(PPLL_DIV_3, mode->ppll_div_3, ~PPLL_POST3_DIV_MASK);
  1147. /* Write update */
  1148. while (INPLL(PPLL_REF_DIV) & PPLL_ATOMIC_UPDATE_R)
  1149. ;
  1150. OUTPLLP(PPLL_REF_DIV, PPLL_ATOMIC_UPDATE_W, ~PPLL_ATOMIC_UPDATE_W);
  1151. /* Wait read update complete */
  1152. /* FIXME: Certain revisions of R300 can't recover here. Not sure of
  1153. the cause yet, but this workaround will mask the problem for now.
  1154. Other chips usually will pass at the very first test, so the
  1155. workaround shouldn't have any effect on them. */
  1156. for (i = 0; (i < 10000 && INPLL(PPLL_REF_DIV) & PPLL_ATOMIC_UPDATE_R); i++)
  1157. ;
  1158. OUTPLL(HTOTAL_CNTL, 0);
  1159. /* Clear reset & atomic update */
  1160. OUTPLLP(PPLL_CNTL, 0,
  1161. ~(PPLL_RESET | PPLL_SLEEP | PPLL_ATOMIC_UPDATE_EN | PPLL_VGA_ATOMIC_UPDATE_EN));
  1162. /* We may want some locking ... oh well */
  1163. radeon_msleep(5);
  1164. /* Switch back VCLK source to PPLL */
  1165. OUTPLLP(VCLK_ECP_CNTL, VCLK_SRC_SEL_PPLLCLK, ~VCLK_SRC_SEL_MASK);
  1166. }
  1167. /*
  1168. * Timer function for delayed LVDS panel power up/down
  1169. */
  1170. static void radeon_lvds_timer_func(unsigned long data)
  1171. {
  1172. struct radeonfb_info *rinfo = (struct radeonfb_info *)data;
  1173. radeon_engine_idle();
  1174. OUTREG(LVDS_GEN_CNTL, rinfo->pending_lvds_gen_cntl);
  1175. }
  1176. /*
  1177. * Apply a video mode. This will apply the whole register set, including
  1178. * the PLL registers, to the card
  1179. */
  1180. void radeon_write_mode (struct radeonfb_info *rinfo, struct radeon_regs *mode,
  1181. int regs_only)
  1182. {
  1183. int i;
  1184. int primary_mon = PRIMARY_MONITOR(rinfo);
  1185. if (nomodeset)
  1186. return;
  1187. if (!regs_only)
  1188. radeon_screen_blank(rinfo, FB_BLANK_NORMAL, 0);
  1189. radeon_fifo_wait(31);
  1190. for (i=0; i<10; i++)
  1191. OUTREG(common_regs[i].reg, common_regs[i].val);
  1192. /* Apply surface registers */
  1193. for (i=0; i<8; i++) {
  1194. OUTREG(SURFACE0_LOWER_BOUND + 0x10*i, mode->surf_lower_bound[i]);
  1195. OUTREG(SURFACE0_UPPER_BOUND + 0x10*i, mode->surf_upper_bound[i]);
  1196. OUTREG(SURFACE0_INFO + 0x10*i, mode->surf_info[i]);
  1197. }
  1198. OUTREG(CRTC_GEN_CNTL, mode->crtc_gen_cntl);
  1199. OUTREGP(CRTC_EXT_CNTL, mode->crtc_ext_cntl,
  1200. ~(CRTC_HSYNC_DIS | CRTC_VSYNC_DIS | CRTC_DISPLAY_DIS));
  1201. OUTREG(CRTC_MORE_CNTL, mode->crtc_more_cntl);
  1202. OUTREGP(DAC_CNTL, mode->dac_cntl, DAC_RANGE_CNTL | DAC_BLANKING);
  1203. OUTREG(CRTC_H_TOTAL_DISP, mode->crtc_h_total_disp);
  1204. OUTREG(CRTC_H_SYNC_STRT_WID, mode->crtc_h_sync_strt_wid);
  1205. OUTREG(CRTC_V_TOTAL_DISP, mode->crtc_v_total_disp);
  1206. OUTREG(CRTC_V_SYNC_STRT_WID, mode->crtc_v_sync_strt_wid);
  1207. OUTREG(CRTC_OFFSET, 0);
  1208. OUTREG(CRTC_OFFSET_CNTL, 0);
  1209. OUTREG(CRTC_PITCH, mode->crtc_pitch);
  1210. OUTREG(SURFACE_CNTL, mode->surface_cntl);
  1211. radeon_write_pll_regs(rinfo, mode);
  1212. if ((primary_mon == MT_DFP) || (primary_mon == MT_LCD)) {
  1213. radeon_fifo_wait(10);
  1214. OUTREG(FP_CRTC_H_TOTAL_DISP, mode->fp_crtc_h_total_disp);
  1215. OUTREG(FP_CRTC_V_TOTAL_DISP, mode->fp_crtc_v_total_disp);
  1216. OUTREG(FP_H_SYNC_STRT_WID, mode->fp_h_sync_strt_wid);
  1217. OUTREG(FP_V_SYNC_STRT_WID, mode->fp_v_sync_strt_wid);
  1218. OUTREG(FP_HORZ_STRETCH, mode->fp_horz_stretch);
  1219. OUTREG(FP_VERT_STRETCH, mode->fp_vert_stretch);
  1220. OUTREG(FP_GEN_CNTL, mode->fp_gen_cntl);
  1221. OUTREG(TMDS_CRC, mode->tmds_crc);
  1222. OUTREG(TMDS_TRANSMITTER_CNTL, mode->tmds_transmitter_cntl);
  1223. }
  1224. if (!regs_only)
  1225. radeon_screen_blank(rinfo, FB_BLANK_UNBLANK, 0);
  1226. radeon_fifo_wait(2);
  1227. OUTPLL(VCLK_ECP_CNTL, mode->vclk_ecp_cntl);
  1228. return;
  1229. }
  1230. /*
  1231. * Calculate the PLL values for a given mode
  1232. */
  1233. static void radeon_calc_pll_regs(struct radeonfb_info *rinfo, struct radeon_regs *regs,
  1234. unsigned long freq)
  1235. {
  1236. const struct {
  1237. int divider;
  1238. int bitvalue;
  1239. } *post_div,
  1240. post_divs[] = {
  1241. { 1, 0 },
  1242. { 2, 1 },
  1243. { 4, 2 },
  1244. { 8, 3 },
  1245. { 3, 4 },
  1246. { 16, 5 },
  1247. { 6, 6 },
  1248. { 12, 7 },
  1249. { 0, 0 },
  1250. };
  1251. int fb_div, pll_output_freq = 0;
  1252. int uses_dvo = 0;
  1253. /* Check if the DVO port is enabled and sourced from the primary CRTC. I'm
  1254. * not sure which model starts having FP2_GEN_CNTL, I assume anything more
  1255. * recent than an r(v)100...
  1256. */
  1257. #if 1
  1258. /* XXX I had reports of flicker happening with the cinema display
  1259. * on TMDS1 that seem to be fixed if I also forbit odd dividers in
  1260. * this case. This could just be a bandwidth calculation issue, I
  1261. * haven't implemented the bandwidth code yet, but in the meantime,
  1262. * forcing uses_dvo to 1 fixes it and shouln't have bad side effects,
  1263. * I haven't seen a case were were absolutely needed an odd PLL
  1264. * divider. I'll find a better fix once I have more infos on the
  1265. * real cause of the problem.
  1266. */
  1267. while (rinfo->has_CRTC2) {
  1268. u32 fp2_gen_cntl = INREG(FP2_GEN_CNTL);
  1269. u32 disp_output_cntl;
  1270. int source;
  1271. /* FP2 path not enabled */
  1272. if ((fp2_gen_cntl & FP2_ON) == 0)
  1273. break;
  1274. /* Not all chip revs have the same format for this register,
  1275. * extract the source selection
  1276. */
  1277. if (rinfo->family == CHIP_FAMILY_R200 ||
  1278. rinfo->family == CHIP_FAMILY_R300 ||
  1279. rinfo->family == CHIP_FAMILY_R350 ||
  1280. rinfo->family == CHIP_FAMILY_RV350) {
  1281. source = (fp2_gen_cntl >> 10) & 0x3;
  1282. /* sourced from transform unit, check for transform unit
  1283. * own source
  1284. */
  1285. if (source == 3) {
  1286. disp_output_cntl = INREG(DISP_OUTPUT_CNTL);
  1287. source = (disp_output_cntl >> 12) & 0x3;
  1288. }
  1289. } else
  1290. source = (fp2_gen_cntl >> 13) & 0x1;
  1291. /* sourced from CRTC2 -> exit */
  1292. if (source == 1)
  1293. break;
  1294. /* so we end up on CRTC1, let's set uses_dvo to 1 now */
  1295. uses_dvo = 1;
  1296. break;
  1297. }
  1298. #else
  1299. uses_dvo = 1;
  1300. #endif
  1301. if (freq > rinfo->pll.ppll_max)
  1302. freq = rinfo->pll.ppll_max;
  1303. if (freq*12 < rinfo->pll.ppll_min)
  1304. freq = rinfo->pll.ppll_min / 12;
  1305. RTRACE("freq = %lu, PLL min = %u, PLL max = %u\n",
  1306. freq, rinfo->pll.ppll_min, rinfo->pll.ppll_max);
  1307. for (post_div = &post_divs[0]; post_div->divider; ++post_div) {
  1308. pll_output_freq = post_div->divider * freq;
  1309. /* If we output to the DVO port (external TMDS), we don't allow an
  1310. * odd PLL divider as those aren't supported on this path
  1311. */
  1312. if (uses_dvo && (post_div->divider & 1))
  1313. continue;
  1314. if (pll_output_freq >= rinfo->pll.ppll_min &&
  1315. pll_output_freq <= rinfo->pll.ppll_max)
  1316. break;
  1317. }
  1318. /* If we fall through the bottom, try the "default value"
  1319. given by the terminal post_div->bitvalue */
  1320. if ( !post_div->divider ) {
  1321. post_div = &post_divs[post_div->bitvalue];
  1322. pll_output_freq = post_div->divider * freq;
  1323. }
  1324. RTRACE("ref_div = %d, ref_clk = %d, output_freq = %d\n",
  1325. rinfo->pll.ref_div, rinfo->pll.ref_clk,
  1326. pll_output_freq);
  1327. /* If we fall through the bottom, try the "default value"
  1328. given by the terminal post_div->bitvalue */
  1329. if ( !post_div->divider ) {
  1330. post_div = &post_divs[post_div->bitvalue];
  1331. pll_output_freq = post_div->divider * freq;
  1332. }
  1333. RTRACE("ref_div = %d, ref_clk = %d, output_freq = %d\n",
  1334. rinfo->pll.ref_div, rinfo->pll.ref_clk,
  1335. pll_output_freq);
  1336. fb_div = round_div(rinfo->pll.ref_div*pll_output_freq,
  1337. rinfo->pll.ref_clk);
  1338. regs->ppll_ref_div = rinfo->pll.ref_div;
  1339. regs->ppll_div_3 = fb_div | (post_div->bitvalue << 16);
  1340. RTRACE("post div = 0x%x\n", post_div->bitvalue);
  1341. RTRACE("fb_div = 0x%x\n", fb_div);
  1342. RTRACE("ppll_div_3 = 0x%x\n", regs->ppll_div_3);
  1343. }
  1344. static int radeonfb_set_par(struct fb_info *info)
  1345. {
  1346. struct radeonfb_info *rinfo = info->par;
  1347. struct fb_var_screeninfo *mode = &info->var;
  1348. struct radeon_regs *newmode;
  1349. int hTotal, vTotal, hSyncStart, hSyncEnd,
  1350. hSyncPol, vSyncStart, vSyncEnd, vSyncPol, cSync;
  1351. u8 hsync_adj_tab[] = {0, 0x12, 9, 9, 6, 5};
  1352. u8 hsync_fudge_fp[] = {2, 2, 0, 0, 5, 5};
  1353. u32 sync, h_sync_pol, v_sync_pol, dotClock, pixClock;
  1354. int i, freq;
  1355. int format = 0;
  1356. int nopllcalc = 0;
  1357. int hsync_start, hsync_fudge, bytpp, hsync_wid, vsync_wid;
  1358. int primary_mon = PRIMARY_MONITOR(rinfo);
  1359. int depth = var_to_depth(mode);
  1360. int use_rmx = 0;
  1361. newmode = kmalloc(sizeof(struct radeon_regs), GFP_KERNEL);
  1362. if (!newmode)
  1363. return -ENOMEM;
  1364. /* We always want engine to be idle on a mode switch, even
  1365. * if we won't actually change the mode
  1366. */
  1367. radeon_engine_idle();
  1368. hSyncStart = mode->xres + mode->right_margin;
  1369. hSyncEnd = hSyncStart + mode->hsync_len;
  1370. hTotal = hSyncEnd + mode->left_margin;
  1371. vSyncStart = mode->yres + mode->lower_margin;
  1372. vSyncEnd = vSyncStart + mode->vsync_len;
  1373. vTotal = vSyncEnd + mode->upper_margin;
  1374. pixClock = mode->pixclock;
  1375. sync = mode->sync;
  1376. h_sync_pol = sync & FB_SYNC_HOR_HIGH_ACT ? 0 : 1;
  1377. v_sync_pol = sync & FB_SYNC_VERT_HIGH_ACT ? 0 : 1;
  1378. if (primary_mon == MT_DFP || primary_mon == MT_LCD) {
  1379. if (rinfo->panel_info.xres < mode->xres)
  1380. mode->xres = rinfo->panel_info.xres;
  1381. if (rinfo->panel_info.yres < mode->yres)
  1382. mode->yres = rinfo->panel_info.yres;
  1383. hTotal = mode->xres + rinfo->panel_info.hblank;
  1384. hSyncStart = mode->xres + rinfo->panel_info.hOver_plus;
  1385. hSyncEnd = hSyncStart + rinfo->panel_info.hSync_width;
  1386. vTotal = mode->yres + rinfo->panel_info.vblank;
  1387. vSyncStart = mode->yres + rinfo->panel_info.vOver_plus;
  1388. vSyncEnd = vSyncStart + rinfo->panel_info.vSync_width;
  1389. h_sync_pol = !rinfo->panel_info.hAct_high;
  1390. v_sync_pol = !rinfo->panel_info.vAct_high;
  1391. pixClock = 100000000 / rinfo->panel_info.clock;
  1392. if (rinfo->panel_info.use_bios_dividers) {
  1393. nopllcalc = 1;
  1394. newmode->ppll_div_3 = rinfo->panel_info.fbk_divider |
  1395. (rinfo->panel_info.post_divider << 16);
  1396. newmode->ppll_ref_div = rinfo->panel_info.ref_divider;
  1397. }
  1398. }
  1399. dotClock = 1000000000 / pixClock;
  1400. freq = dotClock / 10; /* x100 */
  1401. RTRACE("hStart = %d, hEnd = %d, hTotal = %d\n",
  1402. hSyncStart, hSyncEnd, hTotal);
  1403. RTRACE("vStart = %d, vEnd = %d, vTotal = %d\n",
  1404. vSyncStart, vSyncEnd, vTotal);
  1405. hsync_wid = (hSyncEnd - hSyncStart) / 8;
  1406. vsync_wid = vSyncEnd - vSyncStart;
  1407. if (hsync_wid == 0)
  1408. hsync_wid = 1;
  1409. else if (hsync_wid > 0x3f) /* max */
  1410. hsync_wid = 0x3f;
  1411. if (vsync_wid == 0)
  1412. vsync_wid = 1;
  1413. else if (vsync_wid > 0x1f) /* max */
  1414. vsync_wid = 0x1f;
  1415. hSyncPol = mode->sync & FB_SYNC_HOR_HIGH_ACT ? 0 : 1;
  1416. vSyncPol = mode->sync & FB_SYNC_VERT_HIGH_ACT ? 0 : 1;
  1417. cSync = mode->sync & FB_SYNC_COMP_HIGH_ACT ? (1 << 4) : 0;
  1418. format = radeon_get_dstbpp(depth);
  1419. bytpp = mode->bits_per_pixel >> 3;
  1420. if ((primary_mon == MT_DFP) || (primary_mon == MT_LCD))
  1421. hsync_fudge = hsync_fudge_fp[format-1];
  1422. else
  1423. hsync_fudge = hsync_adj_tab[format-1];
  1424. hsync_start = hSyncStart - 8 + hsync_fudge;
  1425. newmode->crtc_gen_cntl = CRTC_EXT_DISP_EN | CRTC_EN |
  1426. (format << 8);
  1427. /* Clear auto-center etc... */
  1428. newmode->crtc_more_cntl = rinfo->init_state.crtc_more_cntl;
  1429. newmode->crtc_more_cntl &= 0xfffffff0;
  1430. if ((primary_mon == MT_DFP) || (primary_mon == MT_LCD)) {
  1431. newmode->crtc_ext_cntl = VGA_ATI_LINEAR | XCRT_CNT_EN;
  1432. if (mirror)
  1433. newmode->crtc_ext_cntl |= CRTC_CRT_ON;
  1434. newmode->crtc_gen_cntl &= ~(CRTC_DBL_SCAN_EN |
  1435. CRTC_INTERLACE_EN);
  1436. } else {
  1437. newmode->crtc_ext_cntl = VGA_ATI_LINEAR | XCRT_CNT_EN |
  1438. CRTC_CRT_ON;
  1439. }
  1440. newmode->dac_cntl = /* INREG(DAC_CNTL) | */ DAC_MASK_ALL | DAC_VGA_ADR_EN |
  1441. DAC_8BIT_EN;
  1442. newmode->crtc_h_total_disp = ((((hTotal / 8) - 1) & 0x3ff) |
  1443. (((mode->xres / 8) - 1) << 16));
  1444. newmode->crtc_h_sync_strt_wid = ((hsync_start & 0x1fff) |
  1445. (hsync_wid << 16) | (h_sync_pol << 23));
  1446. newmode->crtc_v_total_disp = ((vTotal - 1) & 0xffff) |
  1447. ((mode->yres - 1) << 16);
  1448. newmode->crtc_v_sync_strt_wid = (((vSyncStart - 1) & 0xfff) |
  1449. (vsync_wid << 16) | (v_sync_pol << 23));
  1450. if (!(info->flags & FBINFO_HWACCEL_DISABLED)) {
  1451. /* We first calculate the engine pitch */
  1452. rinfo->pitch = ((mode->xres_virtual * ((mode->bits_per_pixel + 1) / 8) + 0x3f)
  1453. & ~(0x3f)) >> 6;
  1454. /* Then, re-multiply it to get the CRTC pitch */
  1455. newmode->crtc_pitch = (rinfo->pitch << 3) / ((mode->bits_per_pixel + 1) / 8);
  1456. } else
  1457. newmode->crtc_pitch = (mode->xres_virtual >> 3);
  1458. newmode->crtc_pitch |= (newmode->crtc_pitch << 16);
  1459. /*
  1460. * It looks like recent chips have a problem with SURFACE_CNTL,
  1461. * setting SURF_TRANSLATION_DIS completely disables the
  1462. * swapper as well, so we leave it unset now.
  1463. */
  1464. newmode->surface_cntl = 0;
  1465. #if defined(__BIG_ENDIAN)
  1466. /* Setup swapping on both apertures, though we currently
  1467. * only use aperture 0, enabling swapper on aperture 1
  1468. * won't harm
  1469. */
  1470. switch (mode->bits_per_pixel) {
  1471. case 16:
  1472. newmode->surface_cntl |= NONSURF_AP0_SWP_16BPP;
  1473. newmode->surface_cntl |= NONSURF_AP1_SWP_16BPP;
  1474. break;
  1475. case 24:
  1476. case 32:
  1477. newmode->surface_cntl |= NONSURF_AP0_SWP_32BPP;
  1478. newmode->surface_cntl |= NONSURF_AP1_SWP_32BPP;
  1479. break;
  1480. }
  1481. #endif
  1482. /* Clear surface registers */
  1483. for (i=0; i<8; i++) {
  1484. newmode->surf_lower_bound[i] = 0;
  1485. newmode->surf_upper_bound[i] = 0x1f;
  1486. newmode->surf_info[i] = 0;
  1487. }
  1488. RTRACE("h_total_disp = 0x%x\t hsync_strt_wid = 0x%x\n",
  1489. newmode->crtc_h_total_disp, newmode->crtc_h_sync_strt_wid);
  1490. RTRACE("v_total_disp = 0x%x\t vsync_strt_wid = 0x%x\n",
  1491. newmode->crtc_v_total_disp, newmode->crtc_v_sync_strt_wid);
  1492. rinfo->bpp = mode->bits_per_pixel;
  1493. rinfo->depth = depth;
  1494. RTRACE("pixclock = %lu\n", (unsigned long)pixClock);
  1495. RTRACE("freq = %lu\n", (unsigned long)freq);
  1496. /* We use PPLL_DIV_3 */
  1497. newmode->clk_cntl_index = 0x300;
  1498. /* Calculate PPLL value if necessary */
  1499. if (!nopllcalc)
  1500. radeon_calc_pll_regs(rinfo, newmode, freq);
  1501. newmode->vclk_ecp_cntl = rinfo->init_state.vclk_ecp_cntl;
  1502. if ((primary_mon == MT_DFP) || (primary_mon == MT_LCD)) {
  1503. unsigned int hRatio, vRatio;
  1504. if (mode->xres > rinfo->panel_info.xres)
  1505. mode->xres = rinfo->panel_info.xres;
  1506. if (mode->yres > rinfo->panel_info.yres)
  1507. mode->yres = rinfo->panel_info.yres;
  1508. newmode->fp_horz_stretch = (((rinfo->panel_info.xres / 8) - 1)
  1509. << HORZ_PANEL_SHIFT);
  1510. newmode->fp_vert_stretch = ((rinfo->panel_info.yres - 1)
  1511. << VERT_PANEL_SHIFT);
  1512. if (mode->xres != rinfo->panel_info.xres) {
  1513. hRatio = round_div(mode->xres * HORZ_STRETCH_RATIO_MAX,
  1514. rinfo->panel_info.xres);
  1515. newmode->fp_horz_stretch = (((((unsigned long)hRatio) & HORZ_STRETCH_RATIO_MASK)) |
  1516. (newmode->fp_horz_stretch &
  1517. (HORZ_PANEL_SIZE | HORZ_FP_LOOP_STRETCH |
  1518. HORZ_AUTO_RATIO_INC)));
  1519. newmode->fp_horz_stretch |= (HORZ_STRETCH_BLEND |
  1520. HORZ_STRETCH_ENABLE);
  1521. use_rmx = 1;
  1522. }
  1523. newmode->fp_horz_stretch &= ~HORZ_AUTO_RATIO;
  1524. if (mode->yres != rinfo->panel_info.yres) {
  1525. vRatio = round_div(mode->yres * VERT_STRETCH_RATIO_MAX,
  1526. rinfo->panel_info.yres);
  1527. newmode->fp_vert_stretch = (((((unsigned long)vRatio) & VERT_STRETCH_RATIO_MASK)) |
  1528. (newmode->fp_vert_stretch &
  1529. (VERT_PANEL_SIZE | VERT_STRETCH_RESERVED)));
  1530. newmode->fp_vert_stretch |= (VERT_STRETCH_BLEND |
  1531. VERT_STRETCH_ENABLE);
  1532. use_rmx = 1;
  1533. }
  1534. newmode->fp_vert_stretch &= ~VERT_AUTO_RATIO_EN;
  1535. newmode->fp_gen_cntl = (rinfo->init_state.fp_gen_cntl & (u32)
  1536. ~(FP_SEL_CRTC2 |
  1537. FP_RMX_HVSYNC_CONTROL_EN |
  1538. FP_DFP_SYNC_SEL |
  1539. FP_CRT_SYNC_SEL |
  1540. FP_CRTC_LOCK_8DOT |
  1541. FP_USE_SHADOW_EN |
  1542. FP_CRTC_USE_SHADOW_VEND |
  1543. FP_CRT_SYNC_ALT));
  1544. newmode->fp_gen_cntl |= (FP_CRTC_DONT_SHADOW_VPAR |
  1545. FP_CRTC_DONT_SHADOW_HEND |
  1546. FP_PANEL_FORMAT);
  1547. if (IS_R300_VARIANT(rinfo) ||
  1548. (rinfo->family == CHIP_FAMILY_R200)) {
  1549. newmode->fp_gen_cntl &= ~R200_FP_SOURCE_SEL_MASK;
  1550. if (use_rmx)
  1551. newmode->fp_gen_cntl |= R200_FP_SOURCE_SEL_RMX;
  1552. else
  1553. newmode->fp_gen_cntl |= R200_FP_SOURCE_SEL_CRTC1;
  1554. } else
  1555. newmode->fp_gen_cntl |= FP_SEL_CRTC1;
  1556. newmode->lvds_gen_cntl = rinfo->init_state.lvds_gen_cntl;
  1557. newmode->lvds_pll_cntl = rinfo->init_state.lvds_pll_cntl;
  1558. newmode->tmds_crc = rinfo->init_state.tmds_crc;
  1559. newmode->tmds_transmitter_cntl = rinfo->init_state.tmds_transmitter_cntl;
  1560. if (primary_mon == MT_LCD) {
  1561. newmode->lvds_gen_cntl |= (LVDS_ON | LVDS_BLON);
  1562. newmode->fp_gen_cntl &= ~(FP_FPON | FP_TMDS_EN);
  1563. } else {
  1564. /* DFP */
  1565. newmode->fp_gen_cntl |= (FP_FPON | FP_TMDS_EN);
  1566. newmode->tmds_transmitter_cntl &= ~(TMDS_PLLRST);
  1567. /* TMDS_PLL_EN bit is reversed on RV (and mobility) chips */
  1568. if (IS_R300_VARIANT(rinfo) ||
  1569. (rinfo->family == CHIP_FAMILY_R200) || !rinfo->has_CRTC2)
  1570. newmode->tmds_transmitter_cntl &= ~TMDS_PLL_EN;
  1571. else
  1572. newmode->tmds_transmitter_cntl |= TMDS_PLL_EN;
  1573. newmode->crtc_ext_cntl &= ~CRTC_CRT_ON;
  1574. }
  1575. newmode->fp_crtc_h_total_disp = (((rinfo->panel_info.hblank / 8) & 0x3ff) |
  1576. (((mode->xres / 8) - 1) << 16));
  1577. newmode->fp_crtc_v_total_disp = (rinfo->panel_info.vblank & 0xffff) |
  1578. ((mode->yres - 1) << 16);
  1579. newmode->fp_h_sync_strt_wid = ((rinfo->panel_info.hOver_plus & 0x1fff) |
  1580. (hsync_wid << 16) | (h_sync_pol << 23));
  1581. newmode->fp_v_sync_strt_wid = ((rinfo->panel_info.vOver_plus & 0xfff) |
  1582. (vsync_wid << 16) | (v_sync_pol << 23));
  1583. }
  1584. /* do it! */
  1585. if (!rinfo->asleep) {
  1586. memcpy(&rinfo->state, newmode, sizeof(*newmode));
  1587. radeon_write_mode (rinfo, newmode, 0);
  1588. /* (re)initialize the engine */
  1589. if (!(info->flags & FBINFO_HWACCEL_DISABLED))
  1590. radeonfb_engine_init (rinfo);
  1591. }
  1592. /* Update fix */
  1593. if (!(info->flags & FBINFO_HWACCEL_DISABLED))
  1594. info->fix.line_length = rinfo->pitch*64;
  1595. else
  1596. info->fix.line_length = mode->xres_virtual
  1597. * ((mode->bits_per_pixel + 1) / 8);
  1598. info->fix.visual = rinfo->depth == 8 ? FB_VISUAL_PSEUDOCOLOR
  1599. : FB_VISUAL_DIRECTCOLOR;
  1600. #ifdef CONFIG_BOOTX_TEXT
  1601. /* Update debug text engine */
  1602. btext_update_display(rinfo->fb_base_phys, mode->xres, mode->yres,
  1603. rinfo->depth, info->fix.line_length);
  1604. #endif
  1605. kfree(newmode);
  1606. return 0;
  1607. }
  1608. static struct fb_ops radeonfb_ops = {
  1609. .owner = THIS_MODULE,
  1610. .fb_check_var = radeonfb_check_var,
  1611. .fb_set_par = radeonfb_set_par,
  1612. .fb_setcolreg = radeonfb_setcolreg,
  1613. .fb_setcmap = radeonfb_setcmap,
  1614. .fb_pan_display = radeonfb_pan_display,
  1615. .fb_blank = radeonfb_blank,
  1616. .fb_ioctl = radeonfb_ioctl,
  1617. .fb_sync = radeonfb_sync,
  1618. .fb_fillrect = radeonfb_fillrect,
  1619. .fb_copyarea = radeonfb_copyarea,
  1620. .fb_imageblit = radeonfb_imageblit,
  1621. };
  1622. static int __devinit radeon_set_fbinfo (struct radeonfb_info *rinfo)
  1623. {
  1624. struct fb_info *info = rinfo->info;
  1625. info->par = rinfo;
  1626. info->pseudo_palette = rinfo->pseudo_palette;
  1627. info->flags = FBINFO_DEFAULT
  1628. | FBINFO_HWACCEL_COPYAREA
  1629. | FBINFO_HWACCEL_FILLRECT
  1630. | FBINFO_HWACCEL_XPAN
  1631. | FBINFO_HWACCEL_YPAN;
  1632. info->fbops = &radeonfb_ops;
  1633. info->screen_base = rinfo->fb_base;
  1634. info->screen_size = rinfo->mapped_vram;
  1635. /* Fill fix common fields */
  1636. strlcpy(info->fix.id, rinfo->name, sizeof(info->fix.id));
  1637. info->fix.smem_start = rinfo->fb_base_phys;
  1638. info->fix.smem_len = rinfo->video_ram;
  1639. info->fix.type = FB_TYPE_PACKED_PIXELS;
  1640. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  1641. info->fix.xpanstep = 8;
  1642. info->fix.ypanstep = 1;
  1643. info->fix.ywrapstep = 0;
  1644. info->fix.type_aux = 0;
  1645. info->fix.mmio_start = rinfo->mmio_base_phys;
  1646. info->fix.mmio_len = RADEON_REGSIZE;
  1647. info->fix.accel = FB_ACCEL_ATI_RADEON;
  1648. fb_alloc_cmap(&info->cmap, 256, 0);
  1649. if (noaccel)
  1650. info->flags |= FBINFO_HWACCEL_DISABLED;
  1651. return 0;
  1652. }
  1653. /*
  1654. * This reconfigure the card's internal memory map. In theory, we'd like
  1655. * to setup the card's memory at the same address as it's PCI bus address,
  1656. * and the AGP aperture right after that so that system RAM on 32 bits
  1657. * machines at least, is directly accessible. However, doing so would
  1658. * conflict with the current XFree drivers...
  1659. * Ultimately, I hope XFree, GATOS and ATI binary drivers will all agree
  1660. * on the proper way to set this up and duplicate this here. In the meantime,
  1661. * I put the card's memory at 0 in card space and AGP at some random high
  1662. * local (0xe0000000 for now) that will be changed by XFree/DRI anyway
  1663. */
  1664. #ifdef CONFIG_PPC_OF
  1665. #undef SET_MC_FB_FROM_APERTURE
  1666. static void fixup_memory_mappings(struct radeonfb_info *rinfo)
  1667. {
  1668. u32 save_crtc_gen_cntl, save_crtc2_gen_cntl = 0;
  1669. u32 save_crtc_ext_cntl;
  1670. u32 aper_base, aper_size;
  1671. u32 agp_base;
  1672. /* First, we disable display to avoid interfering */
  1673. if (rinfo->has_CRTC2) {
  1674. save_crtc2_gen_cntl = INREG(CRTC2_GEN_CNTL);
  1675. OUTREG(CRTC2_GEN_CNTL, save_crtc2_gen_cntl | CRTC2_DISP_REQ_EN_B);
  1676. }
  1677. save_crtc_gen_cntl = INREG(CRTC_GEN_CNTL);
  1678. save_crtc_ext_cntl = INREG(CRTC_EXT_CNTL);
  1679. OUTREG(CRTC_EXT_CNTL, save_crtc_ext_cntl | CRTC_DISPLAY_DIS);
  1680. OUTREG(CRTC_GEN_CNTL, save_crtc_gen_cntl | CRTC_DISP_REQ_EN_B);
  1681. mdelay(100);
  1682. aper_base = INREG(CONFIG_APER_0_BASE);
  1683. aper_size = INREG(CONFIG_APER_SIZE);
  1684. #ifdef SET_MC_FB_FROM_APERTURE
  1685. /* Set framebuffer to be at the same address as set in PCI BAR */
  1686. OUTREG(MC_FB_LOCATION,
  1687. ((aper_base + aper_size - 1) & 0xffff0000) | (aper_base >> 16));
  1688. rinfo->fb_local_base = aper_base;
  1689. #else
  1690. OUTREG(MC_FB_LOCATION, 0x7fff0000);
  1691. rinfo->fb_local_base = 0;
  1692. #endif
  1693. agp_base = aper_base + aper_size;
  1694. if (agp_base & 0xf0000000)
  1695. agp_base = (aper_base | 0x0fffffff) + 1;
  1696. /* Set AGP to be just after the framebuffer on a 256Mb boundary. This
  1697. * assumes the FB isn't mapped to 0xf0000000 or above, but this is
  1698. * always the case on PPCs afaik.
  1699. */
  1700. #ifdef SET_MC_FB_FROM_APERTURE
  1701. OUTREG(MC_AGP_LOCATION, 0xffff0000 | (agp_base >> 16));
  1702. #else
  1703. OUTREG(MC_AGP_LOCATION, 0xffffe000);
  1704. #endif
  1705. /* Fixup the display base addresses & engine offsets while we
  1706. * are at it as well
  1707. */
  1708. #ifdef SET_MC_FB_FROM_APERTURE
  1709. OUTREG(DISPLAY_BASE_ADDR, aper_base);
  1710. if (rinfo->has_CRTC2)
  1711. OUTREG(CRTC2_DISPLAY_BASE_ADDR, aper_base);
  1712. OUTREG(OV0_BASE_ADDR, aper_base);
  1713. #else
  1714. OUTREG(DISPLAY_BASE_ADDR, 0);
  1715. if (rinfo->has_CRTC2)
  1716. OUTREG(CRTC2_DISPLAY_BASE_ADDR, 0);
  1717. OUTREG(OV0_BASE_ADDR, 0);
  1718. #endif
  1719. mdelay(100);
  1720. /* Restore display settings */
  1721. OUTREG(CRTC_GEN_CNTL, save_crtc_gen_cntl);
  1722. OUTREG(CRTC_EXT_CNTL, save_crtc_ext_cntl);
  1723. if (rinfo->has_CRTC2)
  1724. OUTREG(CRTC2_GEN_CNTL, save_crtc2_gen_cntl);
  1725. RTRACE("aper_base: %08x MC_FB_LOC to: %08x, MC_AGP_LOC to: %08x\n",
  1726. aper_base,
  1727. ((aper_base + aper_size - 1) & 0xffff0000) | (aper_base >> 16),
  1728. 0xffff0000 | (agp_base >> 16));
  1729. }
  1730. #endif /* CONFIG_PPC_OF */
  1731. static void radeon_identify_vram(struct radeonfb_info *rinfo)
  1732. {
  1733. u32 tmp;
  1734. /* framebuffer size */
  1735. if ((rinfo->family == CHIP_FAMILY_RS100) ||
  1736. (rinfo->family == CHIP_FAMILY_RS200) ||
  1737. (rinfo->family == CHIP_FAMILY_RS300) ||
  1738. (rinfo->family == CHIP_FAMILY_RC410) ||
  1739. (rinfo->family == CHIP_FAMILY_RS480) ) {
  1740. u32 tom = INREG(NB_TOM);
  1741. tmp = ((((tom >> 16) - (tom & 0xffff) + 1) << 6) * 1024);
  1742. radeon_fifo_wait(6);
  1743. OUTREG(MC_FB_LOCATION, tom);
  1744. OUTREG(DISPLAY_BASE_ADDR, (tom & 0xffff) << 16);
  1745. OUTREG(CRTC2_DISPLAY_BASE_ADDR, (tom & 0xffff) << 16);
  1746. OUTREG(OV0_BASE_ADDR, (tom & 0xffff) << 16);
  1747. /* This is supposed to fix the crtc2 noise problem. */
  1748. OUTREG(GRPH2_BUFFER_CNTL, INREG(GRPH2_BUFFER_CNTL) & ~0x7f0000);
  1749. if ((rinfo->family == CHIP_FAMILY_RS100) ||
  1750. (rinfo->family == CHIP_FAMILY_RS200)) {
  1751. /* This is to workaround the asic bug for RMX, some versions
  1752. of BIOS dosen't have this register initialized correctly.
  1753. */
  1754. OUTREGP(CRTC_MORE_CNTL, CRTC_H_CUTOFF_ACTIVE_EN,
  1755. ~CRTC_H_CUTOFF_ACTIVE_EN);
  1756. }
  1757. } else {
  1758. tmp = INREG(CONFIG_MEMSIZE);
  1759. }
  1760. /* mem size is bits [28:0], mask off the rest */
  1761. rinfo->video_ram = tmp & CONFIG_MEMSIZE_MASK;
  1762. /*
  1763. * Hack to get around some busted production M6's
  1764. * reporting no ram
  1765. */
  1766. if (rinfo->video_ram == 0) {
  1767. switch (rinfo->pdev->device) {
  1768. case PCI_CHIP_RADEON_LY:
  1769. case PCI_CHIP_RADEON_LZ:
  1770. rinfo->video_ram = 8192 * 1024;
  1771. break;
  1772. default:
  1773. break;
  1774. }
  1775. }
  1776. /*
  1777. * Now try to identify VRAM type
  1778. */
  1779. if (rinfo->is_IGP || (rinfo->family >= CHIP_FAMILY_R300) ||
  1780. (INREG(MEM_SDRAM_MODE_REG) & (1<<30)))
  1781. rinfo->vram_ddr = 1;
  1782. else
  1783. rinfo->vram_ddr = 0;
  1784. tmp = INREG(MEM_CNTL);
  1785. if (IS_R300_VARIANT(rinfo)) {
  1786. tmp &= R300_MEM_NUM_CHANNELS_MASK;
  1787. switch (tmp) {
  1788. case 0: rinfo->vram_width = 64; break;
  1789. case 1: rinfo->vram_width = 128; break;
  1790. case 2: rinfo->vram_width = 256; break;
  1791. default: rinfo->vram_width = 128; break;
  1792. }
  1793. } else if ((rinfo->family == CHIP_FAMILY_RV100) ||
  1794. (rinfo->family == CHIP_FAMILY_RS100) ||
  1795. (rinfo->family == CHIP_FAMILY_RS200)){
  1796. if (tmp & RV100_MEM_HALF_MODE)
  1797. rinfo->vram_width = 32;
  1798. else
  1799. rinfo->vram_width = 64;
  1800. } else {
  1801. if (tmp & MEM_NUM_CHANNELS_MASK)
  1802. rinfo->vram_width = 128;
  1803. else
  1804. rinfo->vram_width = 64;
  1805. }
  1806. /* This may not be correct, as some cards can have half of channel disabled
  1807. * ToDo: identify these cases
  1808. */
  1809. RTRACE("radeonfb (%s): Found %ldk of %s %d bits wide videoram\n",
  1810. pci_name(rinfo->pdev),
  1811. rinfo->video_ram / 1024,
  1812. rinfo->vram_ddr ? "DDR" : "SDRAM",
  1813. rinfo->vram_width);
  1814. }
  1815. /*
  1816. * Sysfs
  1817. */
  1818. static ssize_t radeon_show_one_edid(char *buf, loff_t off, size_t count, const u8 *edid)
  1819. {
  1820. if (off > EDID_LENGTH)
  1821. return 0;
  1822. if (off + count > EDID_LENGTH)
  1823. count = EDID_LENGTH - off;
  1824. memcpy(buf, edid + off, count);
  1825. return count;
  1826. }
  1827. static ssize_t radeon_show_edid1(struct kobject *kobj,
  1828. struct bin_attribute *bin_attr,
  1829. char *buf, loff_t off, size_t count)
  1830. {
  1831. struct device *dev = container_of(kobj, struct device, kobj);
  1832. struct pci_dev *pdev = to_pci_dev(dev);
  1833. struct fb_info *info = pci_get_drvdata(pdev);
  1834. struct radeonfb_info *rinfo = info->par;
  1835. return radeon_show_one_edid(buf, off, count, rinfo->mon1_EDID);
  1836. }
  1837. static ssize_t radeon_show_edid2(struct kobject *kobj,
  1838. struct bin_attribute *bin_attr,
  1839. char *buf, loff_t off, size_t count)
  1840. {
  1841. struct device *dev = container_of(kobj, struct device, kobj);
  1842. struct pci_dev *pdev = to_pci_dev(dev);
  1843. struct fb_info *info = pci_get_drvdata(pdev);
  1844. struct radeonfb_info *rinfo = info->par;
  1845. return radeon_show_one_edid(buf, off, count, rinfo->mon2_EDID);
  1846. }
  1847. static struct bin_attribute edid1_attr = {
  1848. .attr = {
  1849. .name = "edid1",
  1850. .mode = 0444,
  1851. },
  1852. .size = EDID_LENGTH,
  1853. .read = radeon_show_edid1,
  1854. };
  1855. static struct bin_attribute edid2_attr = {
  1856. .attr = {
  1857. .name = "edid2",
  1858. .mode = 0444,
  1859. },
  1860. .size = EDID_LENGTH,
  1861. .read = radeon_show_edid2,
  1862. };
  1863. static int __devinit radeonfb_pci_register (struct pci_dev *pdev,
  1864. const struct pci_device_id *ent)
  1865. {
  1866. struct fb_info *info;
  1867. struct radeonfb_info *rinfo;
  1868. int ret;
  1869. RTRACE("radeonfb_pci_register BEGIN\n");
  1870. /* Enable device in PCI config */
  1871. ret = pci_enable_device(pdev);
  1872. if (ret < 0) {
  1873. printk(KERN_ERR "radeonfb (%s): Cannot enable PCI device\n",
  1874. pci_name(pdev));
  1875. goto err_out;
  1876. }
  1877. info = framebuffer_alloc(sizeof(struct radeonfb_info), &pdev->dev);
  1878. if (!info) {
  1879. printk (KERN_ERR "radeonfb (%s): could not allocate memory\n",
  1880. pci_name(pdev));
  1881. ret = -ENOMEM;
  1882. goto err_disable;
  1883. }
  1884. rinfo = info->par;
  1885. rinfo->info = info;
  1886. rinfo->pdev = pdev;
  1887. spin_lock_init(&rinfo->reg_lock);
  1888. init_timer(&rinfo->lvds_timer);
  1889. rinfo->lvds_timer.function = radeon_lvds_timer_func;
  1890. rinfo->lvds_timer.data = (unsigned long)rinfo;
  1891. strcpy(rinfo->name, "ATI Radeon XX ");
  1892. rinfo->name[11] = ent->device >> 8;
  1893. rinfo->name[12] = ent->device & 0xFF;
  1894. rinfo->family = ent->driver_data & CHIP_FAMILY_MASK;
  1895. rinfo->chipset = pdev->device;
  1896. rinfo->has_CRTC2 = (ent->driver_data & CHIP_HAS_CRTC2) != 0;
  1897. rinfo->is_mobility = (ent->driver_data & CHIP_IS_MOBILITY) != 0;
  1898. rinfo->is_IGP = (ent->driver_data & CHIP_IS_IGP) != 0;
  1899. /* Set base addrs */
  1900. rinfo->fb_base_phys = pci_resource_start (pdev, 0);
  1901. rinfo->mmio_base_phys = pci_resource_start (pdev, 2);
  1902. /* request the mem regions */
  1903. ret = pci_request_region(pdev, 0, "radeonfb framebuffer");
  1904. if (ret < 0) {
  1905. printk( KERN_ERR "radeonfb (%s): cannot request region 0.\n",
  1906. pci_name(rinfo->pdev));
  1907. goto err_release_fb;
  1908. }
  1909. ret = pci_request_region(pdev, 2, "radeonfb mmio");
  1910. if (ret < 0) {
  1911. printk( KERN_ERR "radeonfb (%s): cannot request region 2.\n",
  1912. pci_name(rinfo->pdev));
  1913. goto err_release_pci0;
  1914. }
  1915. /* map the regions */
  1916. rinfo->mmio_base = ioremap(rinfo->mmio_base_phys, RADEON_REGSIZE);
  1917. if (!rinfo->mmio_base) {
  1918. printk(KERN_ERR "radeonfb (%s): cannot map MMIO\n",
  1919. pci_name(rinfo->pdev));
  1920. ret = -EIO;
  1921. goto err_release_pci2;
  1922. }
  1923. rinfo->fb_local_base = INREG(MC_FB_LOCATION) << 16;
  1924. /*
  1925. * Check for errata
  1926. */
  1927. rinfo->errata = 0;
  1928. if (rinfo->family == CHIP_FAMILY_R300 &&
  1929. (INREG(CONFIG_CNTL) & CFG_ATI_REV_ID_MASK)
  1930. == CFG_ATI_REV_A11)
  1931. rinfo->errata |= CHIP_ERRATA_R300_CG;
  1932. if (rinfo->family == CHIP_FAMILY_RV200 ||
  1933. rinfo->family == CHIP_FAMILY_RS200)
  1934. rinfo->errata |= CHIP_ERRATA_PLL_DUMMYREADS;
  1935. if (rinfo->family == CHIP_FAMILY_RV100 ||
  1936. rinfo->family == CHIP_FAMILY_RS100 ||
  1937. rinfo->family == CHIP_FAMILY_RS200)
  1938. rinfo->errata |= CHIP_ERRATA_PLL_DELAY;
  1939. #if defined(CONFIG_PPC_OF) || defined(CONFIG_SPARC)
  1940. /* On PPC, we obtain the OF device-node pointer to the firmware
  1941. * data for this chip
  1942. */
  1943. rinfo->of_node = pci_device_to_OF_node(pdev);
  1944. if (rinfo->of_node == NULL)
  1945. printk(KERN_WARNING "radeonfb (%s): Cannot match card to OF node !\n",
  1946. pci_name(rinfo->pdev));
  1947. #endif /* CONFIG_PPC_OF || CONFIG_SPARC */
  1948. #ifdef CONFIG_PPC_OF
  1949. /* On PPC, the firmware sets up a memory mapping that tends
  1950. * to cause lockups when enabling the engine. We reconfigure
  1951. * the card internal memory mappings properly
  1952. */
  1953. fixup_memory_mappings(rinfo);
  1954. #endif /* CONFIG_PPC_OF */
  1955. /* Get VRAM size and type */
  1956. radeon_identify_vram(rinfo);
  1957. rinfo->mapped_vram = min_t(unsigned long, MAX_MAPPED_VRAM, rinfo->video_ram);
  1958. do {
  1959. rinfo->fb_base = ioremap (rinfo->fb_base_phys,
  1960. rinfo->mapped_vram);
  1961. } while ( rinfo->fb_base == 0 &&
  1962. ((rinfo->mapped_vram /=2) >= MIN_MAPPED_VRAM) );
  1963. if (rinfo->fb_base == NULL) {
  1964. printk (KERN_ERR "radeonfb (%s): cannot map FB\n",
  1965. pci_name(rinfo->pdev));
  1966. ret = -EIO;
  1967. goto err_unmap_rom;
  1968. }
  1969. RTRACE("radeonfb (%s): mapped %ldk videoram\n", pci_name(rinfo->pdev),
  1970. rinfo->mapped_vram/1024);
  1971. /*
  1972. * Map the BIOS ROM if any and retrieve PLL parameters from
  1973. * the BIOS. We skip that on mobility chips as the real panel
  1974. * values we need aren't in the ROM but in the BIOS image in
  1975. * memory. This is definitely not the best meacnism though,
  1976. * we really need the arch code to tell us which is the "primary"
  1977. * video adapter to use the memory image (or better, the arch
  1978. * should provide us a copy of the BIOS image to shield us from
  1979. * archs who would store that elsewhere and/or could initialize
  1980. * more than one adapter during boot).
  1981. */
  1982. if (!rinfo->is_mobility)
  1983. radeon_map_ROM(rinfo, pdev);
  1984. /*
  1985. * On x86, the primary display on laptop may have it's BIOS
  1986. * ROM elsewhere, try to locate it at the legacy memory hole.
  1987. * We probably need to make sure this is the primary display,
  1988. * but that is difficult without some arch support.
  1989. */
  1990. #ifdef CONFIG_X86
  1991. if (rinfo->bios_seg == NULL)
  1992. radeon_find_mem_vbios(rinfo);
  1993. #endif
  1994. /* If both above failed, try the BIOS ROM again for mobility
  1995. * chips
  1996. */
  1997. if (rinfo->bios_seg == NULL && rinfo->is_mobility)
  1998. radeon_map_ROM(rinfo, pdev);
  1999. /* Get informations about the board's PLL */
  2000. radeon_get_pllinfo(rinfo);
  2001. #ifdef CONFIG_FB_RADEON_I2C
  2002. /* Register I2C bus */
  2003. radeon_create_i2c_busses(rinfo);
  2004. #endif
  2005. /* set all the vital stuff */
  2006. radeon_set_fbinfo (rinfo);
  2007. /* Probe screen types */
  2008. radeon_probe_screens(rinfo, monitor_layout, ignore_edid);
  2009. /* Build mode list, check out panel native model */
  2010. radeon_check_modes(rinfo, mode_option);
  2011. /* Register some sysfs stuff (should be done better) */
  2012. if (rinfo->mon1_EDID)
  2013. sysfs_create_bin_file(&rinfo->pdev->dev.kobj, &edid1_attr);
  2014. if (rinfo->mon2_EDID)
  2015. sysfs_create_bin_file(&rinfo->pdev->dev.kobj, &edid2_attr);
  2016. /* save current mode regs before we switch into the new one
  2017. * so we can restore this upon __exit
  2018. */
  2019. radeon_save_state (rinfo, &rinfo->init_state);
  2020. memcpy(&rinfo->state, &rinfo->init_state, sizeof(struct radeon_regs));
  2021. /* Setup Power Management capabilities */
  2022. if (default_dynclk < -1) {
  2023. /* -2 is special: means ON on mobility chips and do not
  2024. * change on others
  2025. */
  2026. radeonfb_pm_init(rinfo, rinfo->is_mobility ? 1 : -1, ignore_devlist, force_sleep);
  2027. } else
  2028. radeonfb_pm_init(rinfo, default_dynclk, ignore_devlist, force_sleep);
  2029. pci_set_drvdata(pdev, info);
  2030. /* Register with fbdev layer */
  2031. ret = register_framebuffer(info);
  2032. if (ret < 0) {
  2033. printk (KERN_ERR "radeonfb (%s): could not register framebuffer\n",
  2034. pci_name(rinfo->pdev));
  2035. goto err_unmap_fb;
  2036. }
  2037. #ifdef CONFIG_MTRR
  2038. rinfo->mtrr_hdl = nomtrr ? -1 : mtrr_add(rinfo->fb_base_phys,
  2039. rinfo->video_ram,
  2040. MTRR_TYPE_WRCOMB, 1);
  2041. #endif
  2042. if (backlight)
  2043. radeonfb_bl_init(rinfo);
  2044. printk ("radeonfb (%s): %s\n", pci_name(rinfo->pdev), rinfo->name);
  2045. if (rinfo->bios_seg)
  2046. radeon_unmap_ROM(rinfo, pdev);
  2047. RTRACE("radeonfb_pci_register END\n");
  2048. return 0;
  2049. err_unmap_fb:
  2050. iounmap(rinfo->fb_base);
  2051. err_unmap_rom:
  2052. kfree(rinfo->mon1_EDID);
  2053. kfree(rinfo->mon2_EDID);
  2054. if (rinfo->mon1_modedb)
  2055. fb_destroy_modedb(rinfo->mon1_modedb);
  2056. fb_dealloc_cmap(&info->cmap);
  2057. #ifdef CONFIG_FB_RADEON_I2C
  2058. radeon_delete_i2c_busses(rinfo);
  2059. #endif
  2060. if (rinfo->bios_seg)
  2061. radeon_unmap_ROM(rinfo, pdev);
  2062. iounmap(rinfo->mmio_base);
  2063. err_release_pci2:
  2064. pci_release_region(pdev, 2);
  2065. err_release_pci0:
  2066. pci_release_region(pdev, 0);
  2067. err_release_fb:
  2068. framebuffer_release(info);
  2069. err_disable:
  2070. err_out:
  2071. return ret;
  2072. }
  2073. static void __devexit radeonfb_pci_unregister (struct pci_dev *pdev)
  2074. {
  2075. struct fb_info *info = pci_get_drvdata(pdev);
  2076. struct radeonfb_info *rinfo = info->par;
  2077. if (!rinfo)
  2078. return;
  2079. radeonfb_pm_exit(rinfo);
  2080. if (rinfo->mon1_EDID)
  2081. sysfs_remove_bin_file(&rinfo->pdev->dev.kobj, &edid1_attr);
  2082. if (rinfo->mon2_EDID)
  2083. sysfs_remove_bin_file(&rinfo->pdev->dev.kobj, &edid2_attr);
  2084. #if 0
  2085. /* restore original state
  2086. *
  2087. * Doesn't quite work yet, I suspect if we come from a legacy
  2088. * VGA mode (or worse, text mode), we need to do some VGA black
  2089. * magic here that I know nothing about. --BenH
  2090. */
  2091. radeon_write_mode (rinfo, &rinfo->init_state, 1);
  2092. #endif
  2093. del_timer_sync(&rinfo->lvds_timer);
  2094. #ifdef CONFIG_MTRR
  2095. if (rinfo->mtrr_hdl >= 0)
  2096. mtrr_del(rinfo->mtrr_hdl, 0, 0);
  2097. #endif
  2098. unregister_framebuffer(info);
  2099. radeonfb_bl_exit(rinfo);
  2100. iounmap(rinfo->mmio_base);
  2101. iounmap(rinfo->fb_base);
  2102. pci_release_region(pdev, 2);
  2103. pci_release_region(pdev, 0);
  2104. kfree(rinfo->mon1_EDID);
  2105. kfree(rinfo->mon2_EDID);
  2106. if (rinfo->mon1_modedb)
  2107. fb_destroy_modedb(rinfo->mon1_modedb);
  2108. #ifdef CONFIG_FB_RADEON_I2C
  2109. radeon_delete_i2c_busses(rinfo);
  2110. #endif
  2111. fb_dealloc_cmap(&info->cmap);
  2112. framebuffer_release(info);
  2113. }
  2114. static struct pci_driver radeonfb_driver = {
  2115. .name = "radeonfb",
  2116. .id_table = radeonfb_pci_table,
  2117. .probe = radeonfb_pci_register,
  2118. .remove = __devexit_p(radeonfb_pci_unregister),
  2119. #ifdef CONFIG_PM
  2120. .suspend = radeonfb_pci_suspend,
  2121. .resume = radeonfb_pci_resume,
  2122. #endif /* CONFIG_PM */
  2123. };
  2124. #ifndef MODULE
  2125. static int __init radeonfb_setup (char *options)
  2126. {
  2127. char *this_opt;
  2128. if (!options || !*options)
  2129. return 0;
  2130. while ((this_opt = strsep (&options, ",")) != NULL) {
  2131. if (!*this_opt)
  2132. continue;
  2133. if (!strncmp(this_opt, "noaccel", 7)) {
  2134. noaccel = 1;
  2135. } else if (!strncmp(this_opt, "mirror", 6)) {
  2136. mirror = 1;
  2137. } else if (!strncmp(this_opt, "force_dfp", 9)) {
  2138. force_dfp = 1;
  2139. } else if (!strncmp(this_opt, "panel_yres:", 11)) {
  2140. panel_yres = simple_strtoul((this_opt+11), NULL, 0);
  2141. } else if (!strncmp(this_opt, "backlight:", 10)) {
  2142. backlight = simple_strtoul(this_opt+10, NULL, 0);
  2143. #ifdef CONFIG_MTRR
  2144. } else if (!strncmp(this_opt, "nomtrr", 6)) {
  2145. nomtrr = 1;
  2146. #endif
  2147. } else if (!strncmp(this_opt, "nomodeset", 9)) {
  2148. nomodeset = 1;
  2149. } else if (!strncmp(this_opt, "force_measure_pll", 17)) {
  2150. force_measure_pll = 1;
  2151. } else if (!strncmp(this_opt, "ignore_edid", 11)) {
  2152. ignore_edid = 1;
  2153. #if defined(CONFIG_PM) && defined(CONFIG_X86)
  2154. } else if (!strncmp(this_opt, "force_sleep", 11)) {
  2155. force_sleep = 1;
  2156. } else if (!strncmp(this_opt, "ignore_devlist", 14)) {
  2157. ignore_devlist = 1;
  2158. #endif
  2159. } else
  2160. mode_option = this_opt;
  2161. }
  2162. return 0;
  2163. }
  2164. #endif /* MODULE */
  2165. static int __init radeonfb_init (void)
  2166. {
  2167. #ifndef MODULE
  2168. char *option = NULL;
  2169. if (fb_get_options("radeonfb", &option))
  2170. return -ENODEV;
  2171. radeonfb_setup(option);
  2172. #endif
  2173. return pci_register_driver (&radeonfb_driver);
  2174. }
  2175. static void __exit radeonfb_exit (void)
  2176. {
  2177. pci_unregister_driver (&radeonfb_driver);
  2178. }
  2179. module_init(radeonfb_init);
  2180. module_exit(radeonfb_exit);
  2181. MODULE_AUTHOR("Ani Joshi");
  2182. MODULE_DESCRIPTION("framebuffer driver for ATI Radeon chipset");
  2183. MODULE_LICENSE("GPL");
  2184. module_param(noaccel, bool, 0);
  2185. module_param(default_dynclk, int, 0);
  2186. MODULE_PARM_DESC(default_dynclk, "int: -2=enable on mobility only,-1=do not change,0=off,1=on");
  2187. MODULE_PARM_DESC(noaccel, "bool: disable acceleration");
  2188. module_param(nomodeset, bool, 0);
  2189. MODULE_PARM_DESC(nomodeset, "bool: disable actual setting of video mode");
  2190. module_param(mirror, bool, 0);
  2191. MODULE_PARM_DESC(mirror, "bool: mirror the display to both monitors");
  2192. module_param(force_dfp, bool, 0);
  2193. MODULE_PARM_DESC(force_dfp, "bool: force display to dfp");
  2194. module_param(ignore_edid, bool, 0);
  2195. MODULE_PARM_DESC(ignore_edid, "bool: Ignore EDID data when doing DDC probe");
  2196. module_param(monitor_layout, charp, 0);
  2197. MODULE_PARM_DESC(monitor_layout, "Specify monitor mapping (like XFree86)");
  2198. module_param(force_measure_pll, bool, 0);
  2199. MODULE_PARM_DESC(force_measure_pll, "Force measurement of PLL (debug)");
  2200. #ifdef CONFIG_MTRR
  2201. module_param(nomtrr, bool, 0);
  2202. MODULE_PARM_DESC(nomtrr, "bool: disable use of MTRR registers");
  2203. #endif
  2204. module_param(panel_yres, int, 0);
  2205. MODULE_PARM_DESC(panel_yres, "int: set panel yres");
  2206. module_param(mode_option, charp, 0);
  2207. MODULE_PARM_DESC(mode_option, "Specify resolution as \"<xres>x<yres>[-<bpp>][@<refresh>]\" ");
  2208. #if defined(CONFIG_PM) && defined(CONFIG_X86)
  2209. module_param(force_sleep, bool, 0);
  2210. MODULE_PARM_DESC(force_sleep, "bool: force D2 sleep mode on all hardware");
  2211. module_param(ignore_devlist, bool, 0);
  2212. MODULE_PARM_DESC(ignore_devlist, "bool: ignore workarounds for bugs in specific laptops");
  2213. #endif