radeon_base.c 77 KB

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