radeonfb.c 86 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168
  1. /*
  2. * drivers/video/radeonfb.c
  3. * framebuffer driver for ATI Radeon chipset video boards
  4. *
  5. * Copyright 2000 Ani Joshi <ajoshi@kernel.crashing.org>
  6. *
  7. *
  8. * ChangeLog:
  9. * 2000-08-03 initial version 0.0.1
  10. * 2000-09-10 more bug fixes, public release 0.0.5
  11. * 2001-02-19 mode bug fixes, 0.0.7
  12. * 2001-07-05 fixed scrolling issues, engine initialization,
  13. * and minor mode tweaking, 0.0.9
  14. * 2001-09-07 Radeon VE support, Nick Kurshev
  15. * blanking, pan_display, and cmap fixes, 0.1.0
  16. * 2001-10-10 Radeon 7500 and 8500 support, and experimental
  17. * flat panel support, 0.1.1
  18. * 2001-11-17 Radeon M6 (ppc) support, Daniel Berlin, 0.1.2
  19. * 2001-11-18 DFP fixes, Kevin Hendricks, 0.1.3
  20. * 2001-11-29 more cmap, backlight fixes, Benjamin Herrenschmidt
  21. * 2002-01-18 DFP panel detection via BIOS, Michael Clark, 0.1.4
  22. * 2002-06-02 console switching, mode set fixes, accel fixes
  23. * 2002-06-03 MTRR support, Peter Horton, 0.1.5
  24. * 2002-09-21 rv250, r300, m9 initial support,
  25. * added mirror option, 0.1.6
  26. *
  27. * Special thanks to ATI DevRel team for their hardware donations.
  28. *
  29. */
  30. #define RADEON_VERSION "0.1.6"
  31. #include <linux/config.h>
  32. #include <linux/module.h>
  33. #include <linux/kernel.h>
  34. #include <linux/errno.h>
  35. #include <linux/string.h>
  36. #include <linux/mm.h>
  37. #include <linux/tty.h>
  38. #include <linux/slab.h>
  39. #include <linux/delay.h>
  40. #include <linux/fb.h>
  41. #include <linux/ioport.h>
  42. #include <linux/init.h>
  43. #include <linux/pci.h>
  44. #include <linux/vmalloc.h>
  45. #include <asm/io.h>
  46. #include <asm/uaccess.h>
  47. #if defined(__powerpc__)
  48. #include <asm/prom.h>
  49. #include <asm/pci-bridge.h>
  50. #include "macmodes.h"
  51. #ifdef CONFIG_NVRAM
  52. #include <linux/nvram.h>
  53. #endif
  54. #ifdef CONFIG_PMAC_BACKLIGHT
  55. #include <asm/backlight.h>
  56. #endif
  57. #ifdef CONFIG_BOOTX_TEXT
  58. #include <asm/btext.h>
  59. #endif
  60. #ifdef CONFIG_ADB_PMU
  61. #include <linux/adb.h>
  62. #include <linux/pmu.h>
  63. #endif
  64. #endif /* __powerpc__ */
  65. #ifdef CONFIG_MTRR
  66. #include <asm/mtrr.h>
  67. #endif
  68. #include <video/radeon.h>
  69. #include <linux/radeonfb.h>
  70. #define DEBUG 0
  71. #if DEBUG
  72. #define RTRACE printk
  73. #else
  74. #define RTRACE if(0) printk
  75. #endif
  76. // XXX
  77. #undef CONFIG_PMAC_PBOOK
  78. enum radeon_chips {
  79. RADEON_QD,
  80. RADEON_QE,
  81. RADEON_QF,
  82. RADEON_QG,
  83. RADEON_QY,
  84. RADEON_QZ,
  85. RADEON_LW,
  86. RADEON_LX,
  87. RADEON_LY,
  88. RADEON_LZ,
  89. RADEON_QL,
  90. RADEON_QN,
  91. RADEON_QO,
  92. RADEON_Ql,
  93. RADEON_BB,
  94. RADEON_QW,
  95. RADEON_QX,
  96. RADEON_Id,
  97. RADEON_Ie,
  98. RADEON_If,
  99. RADEON_Ig,
  100. RADEON_Ya,
  101. RADEON_Yd,
  102. RADEON_Ld,
  103. RADEON_Le,
  104. RADEON_Lf,
  105. RADEON_Lg,
  106. RADEON_ND,
  107. RADEON_NE,
  108. RADEON_NF,
  109. RADEON_NG,
  110. RADEON_QM
  111. };
  112. enum radeon_arch {
  113. RADEON_R100,
  114. RADEON_RV100,
  115. RADEON_R200,
  116. RADEON_RV200,
  117. RADEON_RV250,
  118. RADEON_R300,
  119. RADEON_M6,
  120. RADEON_M7,
  121. RADEON_M9
  122. };
  123. static struct radeon_chip_info {
  124. const char *name;
  125. unsigned char arch;
  126. } radeon_chip_info[] __devinitdata = {
  127. { "QD", RADEON_R100 },
  128. { "QE", RADEON_R100 },
  129. { "QF", RADEON_R100 },
  130. { "QG", RADEON_R100 },
  131. { "VE QY", RADEON_RV100 },
  132. { "VE QZ", RADEON_RV100 },
  133. { "M7 LW", RADEON_M7 },
  134. { "M7 LX", RADEON_M7 },
  135. { "M6 LY", RADEON_M6 },
  136. { "M6 LZ", RADEON_M6 },
  137. { "8500 QL", RADEON_R200 },
  138. { "8500 QN", RADEON_R200 },
  139. { "8500 QO", RADEON_R200 },
  140. { "8500 Ql", RADEON_R200 },
  141. { "8500 BB", RADEON_R200 },
  142. { "7500 QW", RADEON_RV200 },
  143. { "7500 QX", RADEON_RV200 },
  144. { "9000 Id", RADEON_RV250 },
  145. { "9000 Ie", RADEON_RV250 },
  146. { "9000 If", RADEON_RV250 },
  147. { "9000 Ig", RADEON_RV250 },
  148. { "M9 Ld", RADEON_M9 },
  149. { "M9 Le", RADEON_M9 },
  150. { "M9 Lf", RADEON_M9 },
  151. { "M9 Lg", RADEON_M9 },
  152. { "9700 ND", RADEON_R300 },
  153. { "9700 NE", RADEON_R300 },
  154. { "9700 NF", RADEON_R300 },
  155. { "9700 NG", RADEON_R300 },
  156. { "9100 QM", RADEON_R200 }
  157. };
  158. enum radeon_montype
  159. {
  160. MT_NONE,
  161. MT_CRT, /* CRT */
  162. MT_LCD, /* LCD */
  163. MT_DFP, /* DVI */
  164. MT_CTV, /* composite TV */
  165. MT_STV /* S-Video out */
  166. };
  167. static struct pci_device_id radeonfb_pci_table[] = {
  168. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QD, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QD},
  169. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QE},
  170. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QF, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QF},
  171. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QG, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QG},
  172. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QY, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QY},
  173. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QZ, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QZ},
  174. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_LW, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_LW},
  175. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_LX, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_LX},
  176. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_LY, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_LY},
  177. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_LZ, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_LZ},
  178. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QL, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QL},
  179. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QN, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QN},
  180. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QO, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QO},
  181. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_Ql, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_Ql},
  182. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_BB, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_BB},
  183. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QW, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QW},
  184. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QX, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QX},
  185. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_Id, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_Id},
  186. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_Ie, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_Ie},
  187. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_If, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_If},
  188. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_Ig, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_Ig},
  189. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_Ya, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_Ya},
  190. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_Yd, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_Yd},
  191. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_Ld, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_Ld},
  192. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_Le, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_Le},
  193. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_Lf, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_Lf},
  194. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_Lg, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_Lg},
  195. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_ND, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_ND},
  196. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_NE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_NE},
  197. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_NF, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_NF},
  198. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_NG, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_NG},
  199. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QM, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QM},
  200. { 0, }
  201. };
  202. MODULE_DEVICE_TABLE(pci, radeonfb_pci_table);
  203. typedef struct {
  204. u16 reg;
  205. u32 val;
  206. } reg_val;
  207. /* these common regs are cleared before mode setting so they do not
  208. * interfere with anything
  209. */
  210. static reg_val common_regs[] = {
  211. { OVR_CLR, 0 },
  212. { OVR_WID_LEFT_RIGHT, 0 },
  213. { OVR_WID_TOP_BOTTOM, 0 },
  214. { OV0_SCALE_CNTL, 0 },
  215. { SUBPIC_CNTL, 0 },
  216. { VIPH_CONTROL, 0 },
  217. { I2C_CNTL_1, 0 },
  218. { GEN_INT_CNTL, 0 },
  219. { CAP0_TRIG_CNTL, 0 },
  220. };
  221. static reg_val common_regs_m6[] = {
  222. { OVR_CLR, 0 },
  223. { OVR_WID_LEFT_RIGHT, 0 },
  224. { OVR_WID_TOP_BOTTOM, 0 },
  225. { OV0_SCALE_CNTL, 0 },
  226. { SUBPIC_CNTL, 0 },
  227. { GEN_INT_CNTL, 0 },
  228. { CAP0_TRIG_CNTL, 0 }
  229. };
  230. typedef struct {
  231. u8 clock_chip_type;
  232. u8 struct_size;
  233. u8 accelerator_entry;
  234. u8 VGA_entry;
  235. u16 VGA_table_offset;
  236. u16 POST_table_offset;
  237. u16 XCLK;
  238. u16 MCLK;
  239. u8 num_PLL_blocks;
  240. u8 size_PLL_blocks;
  241. u16 PCLK_ref_freq;
  242. u16 PCLK_ref_divider;
  243. u32 PCLK_min_freq;
  244. u32 PCLK_max_freq;
  245. u16 MCLK_ref_freq;
  246. u16 MCLK_ref_divider;
  247. u32 MCLK_min_freq;
  248. u32 MCLK_max_freq;
  249. u16 XCLK_ref_freq;
  250. u16 XCLK_ref_divider;
  251. u32 XCLK_min_freq;
  252. u32 XCLK_max_freq;
  253. } __attribute__ ((packed)) PLL_BLOCK;
  254. struct pll_info {
  255. int ppll_max;
  256. int ppll_min;
  257. int xclk;
  258. int ref_div;
  259. int ref_clk;
  260. };
  261. struct ram_info {
  262. int ml;
  263. int mb;
  264. int trcd;
  265. int trp;
  266. int twr;
  267. int cl;
  268. int tr2w;
  269. int loop_latency;
  270. int rloop;
  271. };
  272. struct radeon_regs {
  273. /* CRTC regs */
  274. u32 crtc_h_total_disp;
  275. u32 crtc_h_sync_strt_wid;
  276. u32 crtc_v_total_disp;
  277. u32 crtc_v_sync_strt_wid;
  278. u32 crtc_pitch;
  279. u32 crtc_gen_cntl;
  280. u32 crtc_ext_cntl;
  281. u32 dac_cntl;
  282. u32 flags;
  283. u32 pix_clock;
  284. int xres, yres;
  285. /* DDA regs */
  286. u32 dda_config;
  287. u32 dda_on_off;
  288. /* PLL regs */
  289. u32 ppll_div_3;
  290. u32 ppll_ref_div;
  291. u32 vclk_ecp_cntl;
  292. /* Flat panel regs */
  293. u32 fp_crtc_h_total_disp;
  294. u32 fp_crtc_v_total_disp;
  295. u32 fp_gen_cntl;
  296. u32 fp_h_sync_strt_wid;
  297. u32 fp_horz_stretch;
  298. u32 fp_panel_cntl;
  299. u32 fp_v_sync_strt_wid;
  300. u32 fp_vert_stretch;
  301. u32 lvds_gen_cntl;
  302. u32 lvds_pll_cntl;
  303. u32 tmds_crc;
  304. u32 tmds_transmitter_cntl;
  305. #if defined(__BIG_ENDIAN)
  306. u32 surface_cntl;
  307. #endif
  308. };
  309. struct radeonfb_info {
  310. struct fb_info info;
  311. struct radeon_regs state;
  312. struct radeon_regs init_state;
  313. char name[32];
  314. char ram_type[12];
  315. unsigned long mmio_base_phys;
  316. unsigned long fb_base_phys;
  317. void __iomem *mmio_base;
  318. void __iomem *fb_base;
  319. struct pci_dev *pdev;
  320. unsigned char *EDID;
  321. unsigned char __iomem *bios_seg;
  322. u32 pseudo_palette[17];
  323. struct { u8 red, green, blue, pad; } palette[256];
  324. int chipset;
  325. unsigned char arch;
  326. int video_ram;
  327. u8 rev;
  328. int pitch, bpp, depth;
  329. int xres, yres, pixclock;
  330. int xres_virtual, yres_virtual;
  331. u32 accel_flags;
  332. int use_default_var;
  333. int got_dfpinfo;
  334. int hasCRTC2;
  335. int crtDisp_type;
  336. int dviDisp_type;
  337. int panel_xres, panel_yres;
  338. int clock;
  339. int hOver_plus, hSync_width, hblank;
  340. int vOver_plus, vSync_width, vblank;
  341. int hAct_high, vAct_high, interlaced;
  342. int synct, misc;
  343. u32 dp_gui_master_cntl;
  344. struct pll_info pll;
  345. int pll_output_freq, post_div, fb_div;
  346. struct ram_info ram;
  347. int mtrr_hdl;
  348. #ifdef CONFIG_PMAC_PBOOK
  349. int pm_reg;
  350. u32 save_regs[64];
  351. u32 mdll, mdll2;
  352. #endif /* CONFIG_PMAC_PBOOK */
  353. int asleep;
  354. struct radeonfb_info *next;
  355. };
  356. static struct fb_var_screeninfo radeonfb_default_var = {
  357. 640, 480, 640, 480, 0, 0, 8, 0,
  358. {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0},
  359. 0, 0, -1, -1, 0, 39721, 40, 24, 32, 11, 96, 2,
  360. 0, FB_VMODE_NONINTERLACED
  361. };
  362. /*
  363. * IO macros
  364. */
  365. #define INREG8(addr) readb((rinfo->mmio_base)+addr)
  366. #define OUTREG8(addr,val) writeb(val, (rinfo->mmio_base)+addr)
  367. #define INREG(addr) readl((rinfo->mmio_base)+addr)
  368. #define OUTREG(addr,val) writel(val, (rinfo->mmio_base)+addr)
  369. #define OUTPLL(addr,val) \
  370. do { \
  371. OUTREG8(CLOCK_CNTL_INDEX, (addr & 0x0000003f) | 0x00000080); \
  372. OUTREG(CLOCK_CNTL_DATA, val); \
  373. } while(0)
  374. #define OUTPLLP(addr,val,mask) \
  375. do { \
  376. unsigned int _tmp = INPLL(addr); \
  377. _tmp &= (mask); \
  378. _tmp |= (val); \
  379. OUTPLL(addr, _tmp); \
  380. } while (0)
  381. #define OUTREGP(addr,val,mask) \
  382. do { \
  383. unsigned int _tmp = INREG(addr); \
  384. _tmp &= (mask); \
  385. _tmp |= (val); \
  386. OUTREG(addr, _tmp); \
  387. } while (0)
  388. static __inline__ u32 _INPLL(struct radeonfb_info *rinfo, u32 addr)
  389. {
  390. OUTREG8(CLOCK_CNTL_INDEX, addr & 0x0000003f);
  391. return (INREG(CLOCK_CNTL_DATA));
  392. }
  393. #define INPLL(addr) _INPLL(rinfo, addr)
  394. #define PRIMARY_MONITOR(rinfo) ((rinfo->dviDisp_type != MT_NONE) && \
  395. (rinfo->dviDisp_type != MT_STV) && \
  396. (rinfo->dviDisp_type != MT_CTV) ? \
  397. rinfo->dviDisp_type : rinfo->crtDisp_type)
  398. static char *GET_MON_NAME(int type)
  399. {
  400. char *pret = NULL;
  401. switch (type) {
  402. case MT_NONE:
  403. pret = "no";
  404. break;
  405. case MT_CRT:
  406. pret = "CRT";
  407. break;
  408. case MT_DFP:
  409. pret = "DFP";
  410. break;
  411. case MT_LCD:
  412. pret = "LCD";
  413. break;
  414. case MT_CTV:
  415. pret = "CTV";
  416. break;
  417. case MT_STV:
  418. pret = "STV";
  419. break;
  420. }
  421. return pret;
  422. }
  423. /*
  424. * 2D engine routines
  425. */
  426. static __inline__ void radeon_engine_flush (struct radeonfb_info *rinfo)
  427. {
  428. int i;
  429. /* initiate flush */
  430. OUTREGP(RB2D_DSTCACHE_CTLSTAT, RB2D_DC_FLUSH_ALL,
  431. ~RB2D_DC_FLUSH_ALL);
  432. for (i=0; i < 2000000; i++) {
  433. if (!(INREG(RB2D_DSTCACHE_CTLSTAT) & RB2D_DC_BUSY))
  434. break;
  435. }
  436. }
  437. static __inline__ void _radeon_fifo_wait (struct radeonfb_info *rinfo, int entries)
  438. {
  439. int i;
  440. for (i=0; i<2000000; i++)
  441. if ((INREG(RBBM_STATUS) & 0x7f) >= entries)
  442. return;
  443. }
  444. static __inline__ void _radeon_engine_idle (struct radeonfb_info *rinfo)
  445. {
  446. int i;
  447. /* ensure FIFO is empty before waiting for idle */
  448. _radeon_fifo_wait (rinfo, 64);
  449. for (i=0; i<2000000; i++) {
  450. if (((INREG(RBBM_STATUS) & GUI_ACTIVE)) == 0) {
  451. radeon_engine_flush (rinfo);
  452. return;
  453. }
  454. }
  455. }
  456. #define radeon_engine_idle() _radeon_engine_idle(rinfo)
  457. #define radeon_fifo_wait(entries) _radeon_fifo_wait(rinfo,entries)
  458. /*
  459. * helper routines
  460. */
  461. static __inline__ u32 radeon_get_dstbpp(u16 depth)
  462. {
  463. switch (depth) {
  464. case 8:
  465. return DST_8BPP;
  466. case 15:
  467. return DST_15BPP;
  468. case 16:
  469. return DST_16BPP;
  470. case 32:
  471. return DST_32BPP;
  472. default:
  473. return 0;
  474. }
  475. }
  476. static inline int var_to_depth(const struct fb_var_screeninfo *var)
  477. {
  478. if (var->bits_per_pixel != 16)
  479. return var->bits_per_pixel;
  480. return (var->green.length == 6) ? 16 : 15;
  481. }
  482. static void _radeon_engine_reset(struct radeonfb_info *rinfo)
  483. {
  484. u32 clock_cntl_index, mclk_cntl, rbbm_soft_reset;
  485. radeon_engine_flush (rinfo);
  486. clock_cntl_index = INREG(CLOCK_CNTL_INDEX);
  487. mclk_cntl = INPLL(MCLK_CNTL);
  488. OUTPLL(MCLK_CNTL, (mclk_cntl |
  489. FORCEON_MCLKA |
  490. FORCEON_MCLKB |
  491. FORCEON_YCLKA |
  492. FORCEON_YCLKB |
  493. FORCEON_MC |
  494. FORCEON_AIC));
  495. rbbm_soft_reset = INREG(RBBM_SOFT_RESET);
  496. OUTREG(RBBM_SOFT_RESET, rbbm_soft_reset |
  497. SOFT_RESET_CP |
  498. SOFT_RESET_HI |
  499. SOFT_RESET_SE |
  500. SOFT_RESET_RE |
  501. SOFT_RESET_PP |
  502. SOFT_RESET_E2 |
  503. SOFT_RESET_RB);
  504. INREG(RBBM_SOFT_RESET);
  505. OUTREG(RBBM_SOFT_RESET, rbbm_soft_reset & (u32)
  506. ~(SOFT_RESET_CP |
  507. SOFT_RESET_HI |
  508. SOFT_RESET_SE |
  509. SOFT_RESET_RE |
  510. SOFT_RESET_PP |
  511. SOFT_RESET_E2 |
  512. SOFT_RESET_RB));
  513. INREG(RBBM_SOFT_RESET);
  514. OUTPLL(MCLK_CNTL, mclk_cntl);
  515. OUTREG(CLOCK_CNTL_INDEX, clock_cntl_index);
  516. OUTREG(RBBM_SOFT_RESET, rbbm_soft_reset);
  517. return;
  518. }
  519. #define radeon_engine_reset() _radeon_engine_reset(rinfo)
  520. static __inline__ int round_div(int num, int den)
  521. {
  522. return (num + (den / 2)) / den;
  523. }
  524. static __inline__ int min_bits_req(int val)
  525. {
  526. int bits_req = 0;
  527. if (val == 0)
  528. bits_req = 1;
  529. while (val) {
  530. val >>= 1;
  531. bits_req++;
  532. }
  533. return (bits_req);
  534. }
  535. static __inline__ int _max(int val1, int val2)
  536. {
  537. if (val1 >= val2)
  538. return val1;
  539. else
  540. return val2;
  541. }
  542. /*
  543. * globals
  544. */
  545. #ifndef MODULE
  546. static char *mode_option;
  547. #endif
  548. static char noaccel = 0;
  549. static char mirror = 0;
  550. static int panel_yres = 0;
  551. static char force_dfp = 0;
  552. static struct radeonfb_info *board_list = NULL;
  553. static char nomtrr = 0;
  554. /*
  555. * prototypes
  556. */
  557. static void radeon_save_state (struct radeonfb_info *rinfo,
  558. struct radeon_regs *save);
  559. static void radeon_engine_init (struct radeonfb_info *rinfo);
  560. static void radeon_write_mode (struct radeonfb_info *rinfo,
  561. struct radeon_regs *mode);
  562. static int __devinit radeon_set_fbinfo (struct radeonfb_info *rinfo);
  563. static int __devinit radeon_init_disp (struct radeonfb_info *rinfo);
  564. static int radeon_init_disp_var (struct radeonfb_info *rinfo, struct fb_var_screeninfo *var);
  565. static void __iomem *radeon_find_rom(struct radeonfb_info *rinfo);
  566. static void radeon_get_pllinfo(struct radeonfb_info *rinfo, void __iomem *bios_seg);
  567. static void radeon_get_moninfo (struct radeonfb_info *rinfo);
  568. static int radeon_get_dfpinfo (struct radeonfb_info *rinfo);
  569. static int radeon_get_dfpinfo_BIOS(struct radeonfb_info *rinfo);
  570. static void radeon_get_EDID(struct radeonfb_info *rinfo);
  571. static int radeon_dfp_parse_EDID(struct radeonfb_info *rinfo);
  572. static void radeon_update_default_var(struct radeonfb_info *rinfo);
  573. #ifdef CONFIG_PPC_OF
  574. static int radeon_read_OF (struct radeonfb_info *rinfo);
  575. static int radeon_get_EDID_OF(struct radeonfb_info *rinfo);
  576. extern struct device_node *pci_device_to_OF_node(struct pci_dev *dev);
  577. #ifdef CONFIG_PMAC_PBOOK
  578. int radeon_sleep_notify(struct pmu_sleep_notifier *self, int when);
  579. static struct pmu_sleep_notifier radeon_sleep_notifier = {
  580. radeon_sleep_notify, SLEEP_LEVEL_VIDEO,
  581. };
  582. #endif /* CONFIG_PMAC_PBOOK */
  583. #ifdef CONFIG_PMAC_BACKLIGHT
  584. static int radeon_set_backlight_enable(int on, int level, void *data);
  585. static int radeon_set_backlight_level(int level, void *data);
  586. static struct backlight_controller radeon_backlight_controller = {
  587. radeon_set_backlight_enable,
  588. radeon_set_backlight_level
  589. };
  590. #endif /* CONFIG_PMAC_BACKLIGHT */
  591. #endif /* CONFIG_PPC_OF */
  592. static void __iomem *radeon_find_rom(struct radeonfb_info *rinfo)
  593. {
  594. #if defined(__i386__)
  595. u32 segstart;
  596. char __iomem *rom_base;
  597. char __iomem *rom;
  598. int stage;
  599. int i,j;
  600. char aty_rom_sig[] = "761295520";
  601. char *radeon_sig[] = {
  602. "RG6",
  603. "RADEON"
  604. };
  605. for(segstart=0x000c0000; segstart<0x000f0000; segstart+=0x00001000) {
  606. stage = 1;
  607. rom_base = ioremap(segstart, 0x1000);
  608. if ((*rom_base == 0x55) && (((*(rom_base + 1)) & 0xff) == 0xaa))
  609. stage = 2;
  610. if (stage != 2) {
  611. iounmap(rom_base);
  612. continue;
  613. }
  614. rom = rom_base;
  615. for (i = 0; (i < 128 - strlen(aty_rom_sig)) && (stage != 3); i++) {
  616. if (aty_rom_sig[0] == *rom)
  617. if (strncmp(aty_rom_sig, rom,
  618. strlen(aty_rom_sig)) == 0)
  619. stage = 3;
  620. rom++;
  621. }
  622. if (stage != 3) {
  623. iounmap(rom_base);
  624. continue;
  625. }
  626. rom = rom_base;
  627. for (i = 0; (i < 512) && (stage != 4); i++) {
  628. for(j = 0;j < sizeof(radeon_sig)/sizeof(char *);j++) {
  629. if (radeon_sig[j][0] == *rom)
  630. if (strncmp(radeon_sig[j], rom,
  631. strlen(radeon_sig[j])) == 0) {
  632. stage = 4;
  633. break;
  634. }
  635. }
  636. rom++;
  637. }
  638. if (stage != 4) {
  639. iounmap(rom_base);
  640. continue;
  641. }
  642. return rom_base;
  643. }
  644. #endif
  645. return NULL;
  646. }
  647. static void radeon_get_pllinfo(struct radeonfb_info *rinfo, void __iomem *bios_seg)
  648. {
  649. void __iomem *bios_header;
  650. void __iomem *header_ptr;
  651. u16 bios_header_offset, pll_info_offset;
  652. PLL_BLOCK pll;
  653. if (bios_seg) {
  654. bios_header = bios_seg + 0x48L;
  655. header_ptr = bios_header;
  656. bios_header_offset = readw(header_ptr);
  657. bios_header = bios_seg + bios_header_offset;
  658. bios_header += 0x30;
  659. header_ptr = bios_header;
  660. pll_info_offset = readw(header_ptr);
  661. header_ptr = bios_seg + pll_info_offset;
  662. memcpy_fromio(&pll, header_ptr, 50);
  663. rinfo->pll.xclk = (u32)pll.XCLK;
  664. rinfo->pll.ref_clk = (u32)pll.PCLK_ref_freq;
  665. rinfo->pll.ref_div = (u32)pll.PCLK_ref_divider;
  666. rinfo->pll.ppll_min = pll.PCLK_min_freq;
  667. rinfo->pll.ppll_max = pll.PCLK_max_freq;
  668. printk("radeonfb: ref_clk=%d, ref_div=%d, xclk=%d from BIOS\n",
  669. rinfo->pll.ref_clk, rinfo->pll.ref_div, rinfo->pll.xclk);
  670. } else {
  671. #ifdef CONFIG_PPC_OF
  672. if (radeon_read_OF(rinfo)) {
  673. unsigned int tmp, Nx, M, ref_div, xclk;
  674. tmp = INPLL(M_SPLL_REF_FB_DIV);
  675. ref_div = INPLL(PPLL_REF_DIV) & 0x3ff;
  676. Nx = (tmp & 0xff00) >> 8;
  677. M = (tmp & 0xff);
  678. xclk = ((((2 * Nx * rinfo->pll.ref_clk) + (M)) /
  679. (2 * M)));
  680. rinfo->pll.xclk = xclk;
  681. rinfo->pll.ref_div = ref_div;
  682. rinfo->pll.ppll_min = 12000;
  683. rinfo->pll.ppll_max = 35000;
  684. printk("radeonfb: ref_clk=%d, ref_div=%d, xclk=%d from OF\n",
  685. rinfo->pll.ref_clk, rinfo->pll.ref_div, rinfo->pll.xclk);
  686. return;
  687. }
  688. #endif
  689. /* no BIOS or BIOS not found, use defaults */
  690. switch (rinfo->chipset) {
  691. case PCI_DEVICE_ID_ATI_RADEON_QW:
  692. case PCI_DEVICE_ID_ATI_RADEON_QX:
  693. rinfo->pll.ppll_max = 35000;
  694. rinfo->pll.ppll_min = 12000;
  695. rinfo->pll.xclk = 23000;
  696. rinfo->pll.ref_div = 12;
  697. rinfo->pll.ref_clk = 2700;
  698. break;
  699. case PCI_DEVICE_ID_ATI_RADEON_QL:
  700. case PCI_DEVICE_ID_ATI_RADEON_QN:
  701. case PCI_DEVICE_ID_ATI_RADEON_QO:
  702. case PCI_DEVICE_ID_ATI_RADEON_Ql:
  703. case PCI_DEVICE_ID_ATI_RADEON_BB:
  704. rinfo->pll.ppll_max = 35000;
  705. rinfo->pll.ppll_min = 12000;
  706. rinfo->pll.xclk = 27500;
  707. rinfo->pll.ref_div = 12;
  708. rinfo->pll.ref_clk = 2700;
  709. break;
  710. case PCI_DEVICE_ID_ATI_RADEON_Id:
  711. case PCI_DEVICE_ID_ATI_RADEON_Ie:
  712. case PCI_DEVICE_ID_ATI_RADEON_If:
  713. case PCI_DEVICE_ID_ATI_RADEON_Ig:
  714. rinfo->pll.ppll_max = 35000;
  715. rinfo->pll.ppll_min = 12000;
  716. rinfo->pll.xclk = 25000;
  717. rinfo->pll.ref_div = 12;
  718. rinfo->pll.ref_clk = 2700;
  719. break;
  720. case PCI_DEVICE_ID_ATI_RADEON_ND:
  721. case PCI_DEVICE_ID_ATI_RADEON_NE:
  722. case PCI_DEVICE_ID_ATI_RADEON_NF:
  723. case PCI_DEVICE_ID_ATI_RADEON_NG:
  724. rinfo->pll.ppll_max = 40000;
  725. rinfo->pll.ppll_min = 20000;
  726. rinfo->pll.xclk = 27000;
  727. rinfo->pll.ref_div = 12;
  728. rinfo->pll.ref_clk = 2700;
  729. break;
  730. case PCI_DEVICE_ID_ATI_RADEON_QD:
  731. case PCI_DEVICE_ID_ATI_RADEON_QE:
  732. case PCI_DEVICE_ID_ATI_RADEON_QF:
  733. case PCI_DEVICE_ID_ATI_RADEON_QG:
  734. default:
  735. rinfo->pll.ppll_max = 35000;
  736. rinfo->pll.ppll_min = 12000;
  737. rinfo->pll.xclk = 16600;
  738. rinfo->pll.ref_div = 67;
  739. rinfo->pll.ref_clk = 2700;
  740. break;
  741. }
  742. printk("radeonfb: ref_clk=%d, ref_div=%d, xclk=%d defaults\n",
  743. rinfo->pll.ref_clk, rinfo->pll.ref_div, rinfo->pll.xclk);
  744. }
  745. }
  746. static void radeon_get_moninfo (struct radeonfb_info *rinfo)
  747. {
  748. unsigned int tmp;
  749. if (force_dfp) {
  750. rinfo->dviDisp_type = MT_DFP;
  751. return;
  752. }
  753. tmp = INREG(BIOS_4_SCRATCH);
  754. printk(KERN_DEBUG "radeon_get_moninfo: bios 4 scratch = %x\n", tmp);
  755. if (rinfo->hasCRTC2) {
  756. /* primary DVI port */
  757. if (tmp & 0x08)
  758. rinfo->dviDisp_type = MT_DFP;
  759. else if (tmp & 0x4)
  760. rinfo->dviDisp_type = MT_LCD;
  761. else if (tmp & 0x200)
  762. rinfo->dviDisp_type = MT_CRT;
  763. else if (tmp & 0x10)
  764. rinfo->dviDisp_type = MT_CTV;
  765. else if (tmp & 0x20)
  766. rinfo->dviDisp_type = MT_STV;
  767. /* secondary CRT port */
  768. if (tmp & 0x2)
  769. rinfo->crtDisp_type = MT_CRT;
  770. else if (tmp & 0x800)
  771. rinfo->crtDisp_type = MT_DFP;
  772. else if (tmp & 0x400)
  773. rinfo->crtDisp_type = MT_LCD;
  774. else if (tmp & 0x1000)
  775. rinfo->crtDisp_type = MT_CTV;
  776. else if (tmp & 0x2000)
  777. rinfo->crtDisp_type = MT_STV;
  778. } else {
  779. rinfo->dviDisp_type = MT_NONE;
  780. tmp = INREG(FP_GEN_CNTL);
  781. if (tmp & FP_EN_TMDS)
  782. rinfo->crtDisp_type = MT_DFP;
  783. else
  784. rinfo->crtDisp_type = MT_CRT;
  785. }
  786. }
  787. static void radeon_get_EDID(struct radeonfb_info *rinfo)
  788. {
  789. #ifdef CONFIG_PPC_OF
  790. if (!radeon_get_EDID_OF(rinfo))
  791. RTRACE("radeonfb: could not retrieve EDID from OF\n");
  792. #else
  793. /* XXX use other methods later */
  794. #endif
  795. }
  796. #ifdef CONFIG_PPC_OF
  797. static int radeon_get_EDID_OF(struct radeonfb_info *rinfo)
  798. {
  799. struct device_node *dp;
  800. unsigned char *pedid = NULL;
  801. static char *propnames[] = { "DFP,EDID", "LCD,EDID", "EDID", "EDID1", NULL };
  802. int i;
  803. dp = pci_device_to_OF_node(rinfo->pdev);
  804. while (dp != NULL) {
  805. for (i = 0; propnames[i] != NULL; ++i) {
  806. pedid = (unsigned char *)
  807. get_property(dp, propnames[i], NULL);
  808. if (pedid != NULL) {
  809. rinfo->EDID = pedid;
  810. return 1;
  811. }
  812. }
  813. dp = dp->child;
  814. }
  815. return 0;
  816. }
  817. #endif /* CONFIG_PPC_OF */
  818. static int radeon_dfp_parse_EDID(struct radeonfb_info *rinfo)
  819. {
  820. unsigned char *block = rinfo->EDID;
  821. if (!block)
  822. return 0;
  823. /* jump to the detailed timing block section */
  824. block += 54;
  825. rinfo->clock = (block[0] + (block[1] << 8));
  826. rinfo->panel_xres = (block[2] + ((block[4] & 0xf0) << 4));
  827. rinfo->hblank = (block[3] + ((block[4] & 0x0f) << 8));
  828. rinfo->panel_yres = (block[5] + ((block[7] & 0xf0) << 4));
  829. rinfo->vblank = (block[6] + ((block[7] & 0x0f) << 8));
  830. rinfo->hOver_plus = (block[8] + ((block[11] & 0xc0) << 2));
  831. rinfo->hSync_width = (block[9] + ((block[11] & 0x30) << 4));
  832. rinfo->vOver_plus = ((block[10] >> 4) + ((block[11] & 0x0c) << 2));
  833. rinfo->vSync_width = ((block[10] & 0x0f) + ((block[11] & 0x03) << 4));
  834. rinfo->interlaced = ((block[17] & 0x80) >> 7);
  835. rinfo->synct = ((block[17] & 0x18) >> 3);
  836. rinfo->misc = ((block[17] & 0x06) >> 1);
  837. rinfo->hAct_high = rinfo->vAct_high = 0;
  838. if (rinfo->synct == 3) {
  839. if (rinfo->misc & 2)
  840. rinfo->hAct_high = 1;
  841. if (rinfo->misc & 1)
  842. rinfo->vAct_high = 1;
  843. }
  844. printk("radeonfb: detected DFP panel size from EDID: %dx%d\n",
  845. rinfo->panel_xres, rinfo->panel_yres);
  846. rinfo->got_dfpinfo = 1;
  847. return 1;
  848. }
  849. static void radeon_update_default_var(struct radeonfb_info *rinfo)
  850. {
  851. struct fb_var_screeninfo *var = &radeonfb_default_var;
  852. var->xres = rinfo->panel_xres;
  853. var->yres = rinfo->panel_yres;
  854. var->xres_virtual = rinfo->panel_xres;
  855. var->yres_virtual = rinfo->panel_yres;
  856. var->xoffset = var->yoffset = 0;
  857. var->bits_per_pixel = 8;
  858. var->pixclock = 100000000 / rinfo->clock;
  859. var->left_margin = (rinfo->hblank - rinfo->hOver_plus - rinfo->hSync_width);
  860. var->right_margin = rinfo->hOver_plus;
  861. var->upper_margin = (rinfo->vblank - rinfo->vOver_plus - rinfo->vSync_width);
  862. var->lower_margin = rinfo->vOver_plus;
  863. var->hsync_len = rinfo->hSync_width;
  864. var->vsync_len = rinfo->vSync_width;
  865. var->sync = 0;
  866. if (rinfo->synct == 3) {
  867. if (rinfo->hAct_high)
  868. var->sync |= FB_SYNC_HOR_HIGH_ACT;
  869. if (rinfo->vAct_high)
  870. var->sync |= FB_SYNC_VERT_HIGH_ACT;
  871. }
  872. var->vmode = 0;
  873. if (rinfo->interlaced)
  874. var->vmode |= FB_VMODE_INTERLACED;
  875. rinfo->use_default_var = 1;
  876. }
  877. static int radeon_get_dfpinfo_BIOS(struct radeonfb_info *rinfo)
  878. {
  879. char __iomem *fpbiosstart, *tmp, *tmp0;
  880. char stmp[30];
  881. int i;
  882. if (!rinfo->bios_seg)
  883. return 0;
  884. if (!(fpbiosstart = rinfo->bios_seg + readw(rinfo->bios_seg + 0x48))) {
  885. printk("radeonfb: Failed to detect DFP panel info using BIOS\n");
  886. return 0;
  887. }
  888. if (!(tmp = rinfo->bios_seg + readw(fpbiosstart + 0x40))) {
  889. printk("radeonfb: Failed to detect DFP panel info using BIOS\n");
  890. return 0;
  891. }
  892. for(i=0; i<24; i++)
  893. stmp[i] = readb(tmp+i+1);
  894. stmp[24] = 0;
  895. printk("radeonfb: panel ID string: %s\n", stmp);
  896. rinfo->panel_xres = readw(tmp + 25);
  897. rinfo->panel_yres = readw(tmp + 27);
  898. printk("radeonfb: detected DFP panel size from BIOS: %dx%d\n",
  899. rinfo->panel_xres, rinfo->panel_yres);
  900. for(i=0; i<32; i++) {
  901. tmp0 = rinfo->bios_seg + readw(tmp+64+i*2);
  902. if (tmp0 == 0)
  903. break;
  904. if ((readw(tmp0) == rinfo->panel_xres) &&
  905. (readw(tmp0+2) == rinfo->panel_yres)) {
  906. rinfo->hblank = (readw(tmp0+17) - readw(tmp0+19)) * 8;
  907. rinfo->hOver_plus = ((readw(tmp0+21) - readw(tmp0+19) -1) * 8) & 0x7fff;
  908. rinfo->hSync_width = readb(tmp0+23) * 8;
  909. rinfo->vblank = readw(tmp0+24) - readw(tmp0+26);
  910. rinfo->vOver_plus = (readw(tmp0+28) & 0x7ff) - readw(tmp0+26);
  911. rinfo->vSync_width = (readw(tmp0+28) & 0xf800) >> 11;
  912. rinfo->clock = readw(tmp0+9);
  913. rinfo->got_dfpinfo = 1;
  914. return 1;
  915. }
  916. }
  917. return 0;
  918. }
  919. static int radeon_get_dfpinfo (struct radeonfb_info *rinfo)
  920. {
  921. unsigned int tmp;
  922. unsigned short a, b;
  923. if (radeon_get_dfpinfo_BIOS(rinfo))
  924. radeon_update_default_var(rinfo);
  925. if (radeon_dfp_parse_EDID(rinfo))
  926. radeon_update_default_var(rinfo);
  927. if (!rinfo->got_dfpinfo) {
  928. /*
  929. * it seems all else has failed now and we
  930. * resort to probing registers for our DFP info
  931. */
  932. if (panel_yres) {
  933. rinfo->panel_yres = panel_yres;
  934. } else {
  935. tmp = INREG(FP_VERT_STRETCH);
  936. tmp &= 0x00fff000;
  937. rinfo->panel_yres = (unsigned short)(tmp >> 0x0c) + 1;
  938. }
  939. switch (rinfo->panel_yres) {
  940. case 480:
  941. rinfo->panel_xres = 640;
  942. break;
  943. case 600:
  944. rinfo->panel_xres = 800;
  945. break;
  946. case 768:
  947. #if defined(__powerpc__)
  948. if (rinfo->dviDisp_type == MT_LCD)
  949. rinfo->panel_xres = 1152;
  950. else
  951. #endif
  952. rinfo->panel_xres = 1024;
  953. break;
  954. case 1024:
  955. rinfo->panel_xres = 1280;
  956. break;
  957. case 1050:
  958. rinfo->panel_xres = 1400;
  959. break;
  960. case 1200:
  961. rinfo->panel_xres = 1600;
  962. break;
  963. default:
  964. printk("radeonfb: Failed to detect DFP panel size\n");
  965. return 0;
  966. }
  967. printk("radeonfb: detected DFP panel size from registers: %dx%d\n",
  968. rinfo->panel_xres, rinfo->panel_yres);
  969. tmp = INREG(FP_CRTC_H_TOTAL_DISP);
  970. a = (tmp & FP_CRTC_H_TOTAL_MASK) + 4;
  971. b = (tmp & 0x01ff0000) >> FP_CRTC_H_DISP_SHIFT;
  972. rinfo->hblank = (a - b + 1) * 8;
  973. tmp = INREG(FP_H_SYNC_STRT_WID);
  974. rinfo->hOver_plus = (unsigned short) ((tmp & FP_H_SYNC_STRT_CHAR_MASK) >>
  975. FP_H_SYNC_STRT_CHAR_SHIFT) - b - 1;
  976. rinfo->hOver_plus *= 8;
  977. rinfo->hSync_width = (unsigned short) ((tmp & FP_H_SYNC_WID_MASK) >>
  978. FP_H_SYNC_WID_SHIFT);
  979. rinfo->hSync_width *= 8;
  980. tmp = INREG(FP_CRTC_V_TOTAL_DISP);
  981. a = (tmp & FP_CRTC_V_TOTAL_MASK) + 1;
  982. b = (tmp & FP_CRTC_V_DISP_MASK) >> FP_CRTC_V_DISP_SHIFT;
  983. rinfo->vblank = a - b /* + 24 */ ;
  984. tmp = INREG(FP_V_SYNC_STRT_WID);
  985. rinfo->vOver_plus = (unsigned short) (tmp & FP_V_SYNC_STRT_MASK)
  986. - b + 1;
  987. rinfo->vSync_width = (unsigned short) ((tmp & FP_V_SYNC_WID_MASK) >>
  988. FP_V_SYNC_WID_SHIFT);
  989. return 1;
  990. }
  991. return 1;
  992. }
  993. #ifdef CONFIG_PPC_OF
  994. static int radeon_read_OF (struct radeonfb_info *rinfo)
  995. {
  996. struct device_node *dp;
  997. unsigned int *xtal;
  998. dp = pci_device_to_OF_node(rinfo->pdev);
  999. xtal = (unsigned int *) get_property(dp, "ATY,RefCLK", NULL);
  1000. rinfo->pll.ref_clk = *xtal / 10;
  1001. if (*xtal)
  1002. return 1;
  1003. else
  1004. return 0;
  1005. }
  1006. #endif
  1007. static void radeon_engine_init (struct radeonfb_info *rinfo)
  1008. {
  1009. u32 temp;
  1010. /* disable 3D engine */
  1011. OUTREG(RB3D_CNTL, 0);
  1012. radeon_engine_reset ();
  1013. radeon_fifo_wait (1);
  1014. OUTREG(RB2D_DSTCACHE_MODE, 0);
  1015. radeon_fifo_wait (1);
  1016. temp = INREG(DEFAULT_PITCH_OFFSET);
  1017. OUTREG(DEFAULT_PITCH_OFFSET, ((temp & 0xc0000000) |
  1018. (rinfo->pitch << 0x16)));
  1019. radeon_fifo_wait (1);
  1020. OUTREGP(DP_DATATYPE, 0, ~HOST_BIG_ENDIAN_EN);
  1021. radeon_fifo_wait (1);
  1022. OUTREG(DEFAULT_SC_BOTTOM_RIGHT, (DEFAULT_SC_RIGHT_MAX |
  1023. DEFAULT_SC_BOTTOM_MAX));
  1024. temp = radeon_get_dstbpp(rinfo->depth);
  1025. rinfo->dp_gui_master_cntl = ((temp << 8) | GMC_CLR_CMP_CNTL_DIS);
  1026. radeon_fifo_wait (1);
  1027. OUTREG(DP_GUI_MASTER_CNTL, (rinfo->dp_gui_master_cntl |
  1028. GMC_BRUSH_SOLID_COLOR |
  1029. GMC_SRC_DATATYPE_COLOR));
  1030. radeon_fifo_wait (7);
  1031. /* clear line drawing regs */
  1032. OUTREG(DST_LINE_START, 0);
  1033. OUTREG(DST_LINE_END, 0);
  1034. /* set brush color regs */
  1035. OUTREG(DP_BRUSH_FRGD_CLR, 0xffffffff);
  1036. OUTREG(DP_BRUSH_BKGD_CLR, 0x00000000);
  1037. /* set source color regs */
  1038. OUTREG(DP_SRC_FRGD_CLR, 0xffffffff);
  1039. OUTREG(DP_SRC_BKGD_CLR, 0x00000000);
  1040. /* default write mask */
  1041. OUTREG(DP_WRITE_MSK, 0xffffffff);
  1042. radeon_engine_idle ();
  1043. }
  1044. static int __devinit radeon_init_disp (struct radeonfb_info *rinfo)
  1045. {
  1046. struct fb_info *info = &rinfo->info;
  1047. struct fb_var_screeninfo var;
  1048. var = radeonfb_default_var;
  1049. if ((radeon_init_disp_var(rinfo, &var)) < 0)
  1050. return -1;
  1051. rinfo->depth = var_to_depth(&var);
  1052. rinfo->bpp = var.bits_per_pixel;
  1053. info->var = var;
  1054. fb_alloc_cmap(&info->cmap, 256, 0);
  1055. var.activate = FB_ACTIVATE_NOW;
  1056. return 0;
  1057. }
  1058. static int radeon_init_disp_var (struct radeonfb_info *rinfo,
  1059. struct fb_var_screeninfo *var)
  1060. {
  1061. #ifndef MODULE
  1062. if (mode_option)
  1063. fb_find_mode (var, &rinfo->info, mode_option,
  1064. NULL, 0, NULL, 8);
  1065. else
  1066. #endif
  1067. if (rinfo->use_default_var)
  1068. /* We will use the modified default far */
  1069. *var = radeonfb_default_var;
  1070. else
  1071. fb_find_mode (var, &rinfo->info, "640x480-8@60",
  1072. NULL, 0, NULL, 0);
  1073. if (noaccel)
  1074. var->accel_flags &= ~FB_ACCELF_TEXT;
  1075. else
  1076. var->accel_flags |= FB_ACCELF_TEXT;
  1077. return 0;
  1078. }
  1079. static int radeon_do_maximize(struct radeonfb_info *rinfo,
  1080. struct fb_var_screeninfo *var,
  1081. struct fb_var_screeninfo *v,
  1082. int nom, int den)
  1083. {
  1084. static struct {
  1085. int xres, yres;
  1086. } modes[] = {
  1087. {1600, 1280},
  1088. {1280, 1024},
  1089. {1024, 768},
  1090. {800, 600},
  1091. {640, 480},
  1092. {-1, -1}
  1093. };
  1094. int i;
  1095. /* use highest possible virtual resolution */
  1096. if (v->xres_virtual == -1 && v->yres_virtual == -1) {
  1097. printk("radeonfb: using max available virtual resolution\n");
  1098. for (i=0; modes[i].xres != -1; i++) {
  1099. if (modes[i].xres * nom / den * modes[i].yres <
  1100. rinfo->video_ram / 2)
  1101. break;
  1102. }
  1103. if (modes[i].xres == -1) {
  1104. printk("radeonfb: could not find virtual resolution that fits into video memory!\n");
  1105. return -EINVAL;
  1106. }
  1107. v->xres_virtual = modes[i].xres;
  1108. v->yres_virtual = modes[i].yres;
  1109. printk("radeonfb: virtual resolution set to max of %dx%d\n",
  1110. v->xres_virtual, v->yres_virtual);
  1111. } else if (v->xres_virtual == -1) {
  1112. v->xres_virtual = (rinfo->video_ram * den /
  1113. (nom * v->yres_virtual * 2)) & ~15;
  1114. } else if (v->yres_virtual == -1) {
  1115. v->xres_virtual = (v->xres_virtual + 15) & ~15;
  1116. v->yres_virtual = rinfo->video_ram * den /
  1117. (nom * v->xres_virtual *2);
  1118. } else {
  1119. if (v->xres_virtual * nom / den * v->yres_virtual >
  1120. rinfo->video_ram) {
  1121. return -EINVAL;
  1122. }
  1123. }
  1124. if (v->xres_virtual * nom / den >= 8192) {
  1125. v->xres_virtual = 8192 * den / nom - 16;
  1126. }
  1127. if (v->xres_virtual < v->xres)
  1128. return -EINVAL;
  1129. if (v->yres_virtual < v->yres)
  1130. return -EINVAL;
  1131. return 0;
  1132. }
  1133. static int radeonfb_check_var (struct fb_var_screeninfo *var, struct fb_info *info)
  1134. {
  1135. struct radeonfb_info *rinfo = (struct radeonfb_info *) info->par;
  1136. struct fb_var_screeninfo v;
  1137. int nom, den;
  1138. memcpy (&v, var, sizeof (v));
  1139. switch (v.bits_per_pixel) {
  1140. case 0 ... 8:
  1141. v.bits_per_pixel = 8;
  1142. break;
  1143. case 9 ... 16:
  1144. v.bits_per_pixel = 16;
  1145. break;
  1146. case 17 ... 24:
  1147. #if 0 /* Doesn't seem to work */
  1148. v.bits_per_pixel = 24;
  1149. break;
  1150. #endif
  1151. return -EINVAL;
  1152. case 25 ... 32:
  1153. v.bits_per_pixel = 32;
  1154. break;
  1155. default:
  1156. return -EINVAL;
  1157. }
  1158. switch (var_to_depth(&v)) {
  1159. case 8:
  1160. nom = den = 1;
  1161. v.red.offset = v.green.offset = v.blue.offset = 0;
  1162. v.red.length = v.green.length = v.blue.length = 8;
  1163. v.transp.offset = v.transp.length = 0;
  1164. break;
  1165. case 15:
  1166. nom = 2;
  1167. den = 1;
  1168. v.red.offset = 10;
  1169. v.green.offset = 5;
  1170. v.blue.offset = 0;
  1171. v.red.length = v.green.length = v.blue.length = 5;
  1172. v.transp.offset = v.transp.length = 0;
  1173. break;
  1174. case 16:
  1175. nom = 2;
  1176. den = 1;
  1177. v.red.offset = 11;
  1178. v.green.offset = 5;
  1179. v.blue.offset = 0;
  1180. v.red.length = 5;
  1181. v.green.length = 6;
  1182. v.blue.length = 5;
  1183. v.transp.offset = v.transp.length = 0;
  1184. break;
  1185. case 24:
  1186. nom = 4;
  1187. den = 1;
  1188. v.red.offset = 16;
  1189. v.green.offset = 8;
  1190. v.blue.offset = 0;
  1191. v.red.length = v.blue.length = v.green.length = 8;
  1192. v.transp.offset = v.transp.length = 0;
  1193. break;
  1194. case 32:
  1195. nom = 4;
  1196. den = 1;
  1197. v.red.offset = 16;
  1198. v.green.offset = 8;
  1199. v.blue.offset = 0;
  1200. v.red.length = v.blue.length = v.green.length = 8;
  1201. v.transp.offset = 24;
  1202. v.transp.length = 8;
  1203. break;
  1204. default:
  1205. printk ("radeonfb: mode %dx%dx%d rejected, color depth invalid\n",
  1206. var->xres, var->yres, var->bits_per_pixel);
  1207. return -EINVAL;
  1208. }
  1209. if (radeon_do_maximize(rinfo, var, &v, nom, den) < 0)
  1210. return -EINVAL;
  1211. if (v.xoffset < 0)
  1212. v.xoffset = 0;
  1213. if (v.yoffset < 0)
  1214. v.yoffset = 0;
  1215. if (v.xoffset > v.xres_virtual - v.xres)
  1216. v.xoffset = v.xres_virtual - v.xres - 1;
  1217. if (v.yoffset > v.yres_virtual - v.yres)
  1218. v.yoffset = v.yres_virtual - v.yres - 1;
  1219. v.red.msb_right = v.green.msb_right = v.blue.msb_right =
  1220. v.transp.offset = v.transp.length =
  1221. v.transp.msb_right = 0;
  1222. if (noaccel)
  1223. v.accel_flags = 0;
  1224. memcpy(var, &v, sizeof(v));
  1225. return 0;
  1226. }
  1227. static int radeonfb_pan_display (struct fb_var_screeninfo *var,
  1228. struct fb_info *info)
  1229. {
  1230. struct radeonfb_info *rinfo = (struct radeonfb_info *) info;
  1231. if ((var->xoffset + var->xres > var->xres_virtual)
  1232. || (var->yoffset + var->yres > var->yres_virtual))
  1233. return -EINVAL;
  1234. if (rinfo->asleep)
  1235. return 0;
  1236. OUTREG(CRTC_OFFSET, ((var->yoffset * var->xres_virtual + var->xoffset)
  1237. * var->bits_per_pixel / 8) & ~7);
  1238. return 0;
  1239. }
  1240. static int radeonfb_ioctl (struct inode *inode, struct file *file, unsigned int cmd,
  1241. unsigned long arg, struct fb_info *info)
  1242. {
  1243. struct radeonfb_info *rinfo = (struct radeonfb_info *) info;
  1244. unsigned int tmp;
  1245. u32 value = 0;
  1246. int rc;
  1247. switch (cmd) {
  1248. /*
  1249. * TODO: set mirror accordingly for non-Mobility chipsets with 2 CRTC's
  1250. */
  1251. case FBIO_RADEON_SET_MIRROR:
  1252. switch (rinfo->arch) {
  1253. case RADEON_R100:
  1254. case RADEON_RV100:
  1255. case RADEON_R200:
  1256. case RADEON_RV200:
  1257. case RADEON_RV250:
  1258. case RADEON_R300:
  1259. return -EINVAL;
  1260. default:
  1261. /* RADEON M6, RADEON_M7, RADEON_M9 */
  1262. break;
  1263. }
  1264. rc = get_user(value, (__u32 __user *)arg);
  1265. if (rc)
  1266. return rc;
  1267. if (value & 0x01) {
  1268. tmp = INREG(LVDS_GEN_CNTL);
  1269. tmp |= (LVDS_ON | LVDS_BLON);
  1270. } else {
  1271. tmp = INREG(LVDS_GEN_CNTL);
  1272. tmp &= ~(LVDS_ON | LVDS_BLON);
  1273. }
  1274. OUTREG(LVDS_GEN_CNTL, tmp);
  1275. if (value & 0x02) {
  1276. tmp = INREG(CRTC_EXT_CNTL);
  1277. tmp |= CRTC_CRT_ON;
  1278. mirror = 1;
  1279. } else {
  1280. tmp = INREG(CRTC_EXT_CNTL);
  1281. tmp &= ~CRTC_CRT_ON;
  1282. mirror = 0;
  1283. }
  1284. OUTREG(CRTC_EXT_CNTL, tmp);
  1285. break;
  1286. case FBIO_RADEON_GET_MIRROR:
  1287. switch (rinfo->arch) {
  1288. case RADEON_R100:
  1289. case RADEON_RV100:
  1290. case RADEON_R200:
  1291. case RADEON_RV200:
  1292. case RADEON_RV250:
  1293. case RADEON_R300:
  1294. return -EINVAL;
  1295. default:
  1296. /* RADEON M6, RADEON_M7, RADEON_M9 */
  1297. break;
  1298. }
  1299. tmp = INREG(LVDS_GEN_CNTL);
  1300. if ((LVDS_ON | LVDS_BLON) & tmp)
  1301. value |= 0x01;
  1302. tmp = INREG(CRTC_EXT_CNTL);
  1303. if (CRTC_CRT_ON & tmp)
  1304. value |= 0x02;
  1305. return put_user(value, (__u32 __user *)arg);
  1306. default:
  1307. return -EINVAL;
  1308. }
  1309. return -EINVAL;
  1310. }
  1311. static int radeonfb_blank (int blank, struct fb_info *info)
  1312. {
  1313. struct radeonfb_info *rinfo = (struct radeonfb_info *) info;
  1314. u32 val = INREG(CRTC_EXT_CNTL);
  1315. u32 val2 = INREG(LVDS_GEN_CNTL);
  1316. if (rinfo->asleep)
  1317. return 0;
  1318. #ifdef CONFIG_PMAC_BACKLIGHT
  1319. if (rinfo->dviDisp_type == MT_LCD && _machine == _MACH_Pmac) {
  1320. set_backlight_enable(!blank);
  1321. return 0;
  1322. }
  1323. #endif
  1324. /* reset it */
  1325. val &= ~(CRTC_DISPLAY_DIS | CRTC_HSYNC_DIS |
  1326. CRTC_VSYNC_DIS);
  1327. val2 &= ~(LVDS_DISPLAY_DIS);
  1328. switch (blank) {
  1329. case FB_BLANK_UNBLANK:
  1330. case FB_BLANK_NORMAL:
  1331. break;
  1332. case FB_BLANK_VSYNC_SUSPEND:
  1333. val |= (CRTC_DISPLAY_DIS | CRTC_VSYNC_DIS);
  1334. break;
  1335. case FB_BLANK_HSYNC_SUSPEND:
  1336. val |= (CRTC_DISPLAY_DIS | CRTC_HSYNC_DIS);
  1337. break;
  1338. case FB_BLANK_POWERDOWN:
  1339. val |= (CRTC_DISPLAY_DIS | CRTC_VSYNC_DIS |
  1340. CRTC_HSYNC_DIS);
  1341. val2 |= (LVDS_DISPLAY_DIS);
  1342. break;
  1343. }
  1344. switch (rinfo->dviDisp_type) {
  1345. case MT_LCD:
  1346. OUTREG(LVDS_GEN_CNTL, val2);
  1347. break;
  1348. case MT_CRT:
  1349. default:
  1350. OUTREG(CRTC_EXT_CNTL, val);
  1351. break;
  1352. }
  1353. /* let fbcon do a soft blank for us */
  1354. return (blank == FB_BLANK_NORMAL) ? 1 : 0;
  1355. }
  1356. static int radeonfb_setcolreg (unsigned regno, unsigned red, unsigned green,
  1357. unsigned blue, unsigned transp, struct fb_info *info)
  1358. {
  1359. struct radeonfb_info *rinfo = (struct radeonfb_info *) info;
  1360. u32 pindex, vclk_cntl;
  1361. unsigned int i;
  1362. if (regno > 255)
  1363. return 1;
  1364. red >>= 8;
  1365. green >>= 8;
  1366. blue >>= 8;
  1367. rinfo->palette[regno].red = red;
  1368. rinfo->palette[regno].green = green;
  1369. rinfo->palette[regno].blue = blue;
  1370. /* default */
  1371. pindex = regno;
  1372. if (!rinfo->asleep) {
  1373. vclk_cntl = INPLL(VCLK_ECP_CNTL);
  1374. OUTPLL(VCLK_ECP_CNTL, vclk_cntl & ~PIXCLK_DAC_ALWAYS_ONb);
  1375. if (rinfo->bpp == 16) {
  1376. pindex = regno * 8;
  1377. if (rinfo->depth == 16 && regno > 63)
  1378. return 1;
  1379. if (rinfo->depth == 15 && regno > 31)
  1380. return 1;
  1381. /* For 565, the green component is mixed one order below */
  1382. if (rinfo->depth == 16) {
  1383. OUTREG(PALETTE_INDEX, pindex>>1);
  1384. OUTREG(PALETTE_DATA, (rinfo->palette[regno>>1].red << 16) |
  1385. (green << 8) | (rinfo->palette[regno>>1].blue));
  1386. green = rinfo->palette[regno<<1].green;
  1387. }
  1388. }
  1389. if (rinfo->depth != 16 || regno < 32) {
  1390. OUTREG(PALETTE_INDEX, pindex);
  1391. OUTREG(PALETTE_DATA, (red << 16) | (green << 8) | blue);
  1392. }
  1393. OUTPLL(VCLK_ECP_CNTL, vclk_cntl);
  1394. }
  1395. if (regno < 16) {
  1396. switch (rinfo->depth) {
  1397. case 15:
  1398. ((u16 *) (info->pseudo_palette))[regno] =
  1399. (regno << 10) | (regno << 5) | regno;
  1400. break;
  1401. case 16:
  1402. ((u16 *) (info->pseudo_palette))[regno] =
  1403. (regno << 11) | (regno << 6) | regno;
  1404. break;
  1405. case 24:
  1406. ((u32 *) (info->pseudo_palette))[regno] =
  1407. (regno << 16) | (regno << 8) | regno;
  1408. break;
  1409. case 32:
  1410. i = (regno << 8) | regno;
  1411. ((u32 *) (info->pseudo_palette))[regno] =
  1412. (i << 16) | i;
  1413. break;
  1414. }
  1415. }
  1416. return 0;
  1417. }
  1418. static void radeon_save_state (struct radeonfb_info *rinfo,
  1419. struct radeon_regs *save)
  1420. {
  1421. /* CRTC regs */
  1422. save->crtc_gen_cntl = INREG(CRTC_GEN_CNTL);
  1423. save->crtc_ext_cntl = INREG(CRTC_EXT_CNTL);
  1424. save->dac_cntl = INREG(DAC_CNTL);
  1425. save->crtc_h_total_disp = INREG(CRTC_H_TOTAL_DISP);
  1426. save->crtc_h_sync_strt_wid = INREG(CRTC_H_SYNC_STRT_WID);
  1427. save->crtc_v_total_disp = INREG(CRTC_V_TOTAL_DISP);
  1428. save->crtc_v_sync_strt_wid = INREG(CRTC_V_SYNC_STRT_WID);
  1429. save->crtc_pitch = INREG(CRTC_PITCH);
  1430. #if defined(__BIG_ENDIAN)
  1431. save->surface_cntl = INREG(SURFACE_CNTL);
  1432. #endif
  1433. /* FP regs */
  1434. save->fp_crtc_h_total_disp = INREG(FP_CRTC_H_TOTAL_DISP);
  1435. save->fp_crtc_v_total_disp = INREG(FP_CRTC_V_TOTAL_DISP);
  1436. save->fp_gen_cntl = INREG(FP_GEN_CNTL);
  1437. save->fp_h_sync_strt_wid = INREG(FP_H_SYNC_STRT_WID);
  1438. save->fp_horz_stretch = INREG(FP_HORZ_STRETCH);
  1439. save->fp_v_sync_strt_wid = INREG(FP_V_SYNC_STRT_WID);
  1440. save->fp_vert_stretch = INREG(FP_VERT_STRETCH);
  1441. save->lvds_gen_cntl = INREG(LVDS_GEN_CNTL);
  1442. save->lvds_pll_cntl = INREG(LVDS_PLL_CNTL);
  1443. save->tmds_crc = INREG(TMDS_CRC);
  1444. save->tmds_transmitter_cntl = INREG(TMDS_TRANSMITTER_CNTL);
  1445. save->vclk_ecp_cntl = INPLL(VCLK_ECP_CNTL);
  1446. }
  1447. static int radeonfb_set_par (struct fb_info *info)
  1448. {
  1449. struct radeonfb_info *rinfo = (struct radeonfb_info *)info->par;
  1450. struct fb_var_screeninfo *mode = &info->var;
  1451. struct radeon_regs newmode;
  1452. int hTotal, vTotal, hSyncStart, hSyncEnd,
  1453. hSyncPol, vSyncStart, vSyncEnd, vSyncPol, cSync;
  1454. u8 hsync_adj_tab[] = {0, 0x12, 9, 9, 6, 5};
  1455. u8 hsync_fudge_fp[] = {2, 2, 0, 0, 5, 5};
  1456. u32 dotClock = 1000000000 / mode->pixclock,
  1457. sync, h_sync_pol, v_sync_pol;
  1458. int freq = dotClock / 10; /* x 100 */
  1459. int xclk_freq, vclk_freq, xclk_per_trans, xclk_per_trans_precise;
  1460. int useable_precision, roff, ron;
  1461. int min_bits, format = 0;
  1462. int hsync_start, hsync_fudge, bytpp, hsync_wid, vsync_wid;
  1463. int primary_mon = PRIMARY_MONITOR(rinfo);
  1464. int depth = var_to_depth(mode);
  1465. int accel = (mode->accel_flags & FB_ACCELF_TEXT) != 0;
  1466. rinfo->xres = mode->xres;
  1467. rinfo->yres = mode->yres;
  1468. rinfo->xres_virtual = mode->xres_virtual;
  1469. rinfo->yres_virtual = mode->yres_virtual;
  1470. rinfo->pixclock = mode->pixclock;
  1471. hSyncStart = mode->xres + mode->right_margin;
  1472. hSyncEnd = hSyncStart + mode->hsync_len;
  1473. hTotal = hSyncEnd + mode->left_margin;
  1474. vSyncStart = mode->yres + mode->lower_margin;
  1475. vSyncEnd = vSyncStart + mode->vsync_len;
  1476. vTotal = vSyncEnd + mode->upper_margin;
  1477. if ((primary_mon == MT_DFP) || (primary_mon == MT_LCD)) {
  1478. if (rinfo->panel_xres < mode->xres)
  1479. rinfo->xres = mode->xres = rinfo->panel_xres;
  1480. if (rinfo->panel_yres < mode->yres)
  1481. rinfo->yres = mode->yres = rinfo->panel_yres;
  1482. hTotal = mode->xres + rinfo->hblank;
  1483. hSyncStart = mode->xres + rinfo->hOver_plus;
  1484. hSyncEnd = hSyncStart + rinfo->hSync_width;
  1485. vTotal = mode->yres + rinfo->vblank;
  1486. vSyncStart = mode->yres + rinfo->vOver_plus;
  1487. vSyncEnd = vSyncStart + rinfo->vSync_width;
  1488. }
  1489. sync = mode->sync;
  1490. h_sync_pol = sync & FB_SYNC_HOR_HIGH_ACT ? 0 : 1;
  1491. v_sync_pol = sync & FB_SYNC_VERT_HIGH_ACT ? 0 : 1;
  1492. RTRACE("hStart = %d, hEnd = %d, hTotal = %d\n",
  1493. hSyncStart, hSyncEnd, hTotal);
  1494. RTRACE("vStart = %d, vEnd = %d, vTotal = %d\n",
  1495. vSyncStart, vSyncEnd, vTotal);
  1496. hsync_wid = (hSyncEnd - hSyncStart) / 8;
  1497. vsync_wid = vSyncEnd - vSyncStart;
  1498. if (hsync_wid == 0)
  1499. hsync_wid = 1;
  1500. else if (hsync_wid > 0x3f) /* max */
  1501. hsync_wid = 0x3f;
  1502. if (vsync_wid == 0)
  1503. vsync_wid = 1;
  1504. else if (vsync_wid > 0x1f) /* max */
  1505. vsync_wid = 0x1f;
  1506. hSyncPol = mode->sync & FB_SYNC_HOR_HIGH_ACT ? 0 : 1;
  1507. vSyncPol = mode->sync & FB_SYNC_VERT_HIGH_ACT ? 0 : 1;
  1508. cSync = mode->sync & FB_SYNC_COMP_HIGH_ACT ? (1 << 4) : 0;
  1509. format = radeon_get_dstbpp(depth);
  1510. bytpp = mode->bits_per_pixel >> 3;
  1511. if ((primary_mon == MT_DFP) || (primary_mon == MT_LCD))
  1512. hsync_fudge = hsync_fudge_fp[format-1];
  1513. else
  1514. hsync_fudge = hsync_adj_tab[format-1];
  1515. hsync_start = hSyncStart - 8 + hsync_fudge;
  1516. newmode.crtc_gen_cntl = CRTC_EXT_DISP_EN | CRTC_EN |
  1517. (format << 8);
  1518. if ((primary_mon == MT_DFP) || (primary_mon == MT_LCD)) {
  1519. newmode.crtc_ext_cntl = VGA_ATI_LINEAR | XCRT_CNT_EN;
  1520. if (mirror)
  1521. newmode.crtc_ext_cntl |= CRTC_CRT_ON;
  1522. newmode.crtc_gen_cntl &= ~(CRTC_DBL_SCAN_EN |
  1523. CRTC_INTERLACE_EN);
  1524. } else {
  1525. newmode.crtc_ext_cntl = VGA_ATI_LINEAR | XCRT_CNT_EN |
  1526. CRTC_CRT_ON;
  1527. }
  1528. newmode.dac_cntl = /* INREG(DAC_CNTL) | */ DAC_MASK_ALL | DAC_VGA_ADR_EN |
  1529. DAC_8BIT_EN;
  1530. newmode.crtc_h_total_disp = ((((hTotal / 8) - 1) & 0x3ff) |
  1531. (((mode->xres / 8) - 1) << 16));
  1532. newmode.crtc_h_sync_strt_wid = ((hsync_start & 0x1fff) |
  1533. (hsync_wid << 16) | (h_sync_pol << 23));
  1534. newmode.crtc_v_total_disp = ((vTotal - 1) & 0xffff) |
  1535. ((mode->yres - 1) << 16);
  1536. newmode.crtc_v_sync_strt_wid = (((vSyncStart - 1) & 0xfff) |
  1537. (vsync_wid << 16) | (v_sync_pol << 23));
  1538. if (accel) {
  1539. /* We first calculate the engine pitch */
  1540. rinfo->pitch = ((mode->xres_virtual * ((mode->bits_per_pixel + 1) / 8) + 0x3f)
  1541. & ~(0x3f)) >> 6;
  1542. /* Then, re-multiply it to get the CRTC pitch */
  1543. newmode.crtc_pitch = (rinfo->pitch << 3) / ((mode->bits_per_pixel + 1) / 8);
  1544. } else
  1545. newmode.crtc_pitch = (mode->xres_virtual >> 3);
  1546. newmode.crtc_pitch |= (newmode.crtc_pitch << 16);
  1547. #if defined(__BIG_ENDIAN)
  1548. /*
  1549. * It looks like recent chips have a problem with SURFACE_CNTL,
  1550. * setting SURF_TRANSLATION_DIS completely disables the
  1551. * swapper as well, so we leave it unset now.
  1552. */
  1553. newmode.surface_cntl = 0;
  1554. /* Setup swapping on both apertures, though we currently
  1555. * only use aperture 0, enabling swapper on aperture 1
  1556. * won't harm
  1557. */
  1558. switch (mode->bits_per_pixel) {
  1559. case 16:
  1560. newmode.surface_cntl |= NONSURF_AP0_SWP_16BPP;
  1561. newmode.surface_cntl |= NONSURF_AP1_SWP_16BPP;
  1562. break;
  1563. case 24:
  1564. case 32:
  1565. newmode.surface_cntl |= NONSURF_AP0_SWP_32BPP;
  1566. newmode.surface_cntl |= NONSURF_AP1_SWP_32BPP;
  1567. break;
  1568. }
  1569. #endif
  1570. rinfo->pitch = ((mode->xres_virtual * ((mode->bits_per_pixel + 1) / 8) + 0x3f)
  1571. & ~(0x3f)) / 64;
  1572. RTRACE("h_total_disp = 0x%x\t hsync_strt_wid = 0x%x\n",
  1573. newmode.crtc_h_total_disp, newmode.crtc_h_sync_strt_wid);
  1574. RTRACE("v_total_disp = 0x%x\t vsync_strt_wid = 0x%x\n",
  1575. newmode.crtc_v_total_disp, newmode.crtc_v_sync_strt_wid);
  1576. newmode.xres = mode->xres;
  1577. newmode.yres = mode->yres;
  1578. rinfo->bpp = mode->bits_per_pixel;
  1579. rinfo->depth = depth;
  1580. if (freq > rinfo->pll.ppll_max)
  1581. freq = rinfo->pll.ppll_max;
  1582. if (freq*12 < rinfo->pll.ppll_min)
  1583. freq = rinfo->pll.ppll_min / 12;
  1584. {
  1585. struct {
  1586. int divider;
  1587. int bitvalue;
  1588. } *post_div,
  1589. post_divs[] = {
  1590. { 1, 0 },
  1591. { 2, 1 },
  1592. { 4, 2 },
  1593. { 8, 3 },
  1594. { 3, 4 },
  1595. { 16, 5 },
  1596. { 6, 6 },
  1597. { 12, 7 },
  1598. { 0, 0 },
  1599. };
  1600. for (post_div = &post_divs[0]; post_div->divider; ++post_div) {
  1601. rinfo->pll_output_freq = post_div->divider * freq;
  1602. if (rinfo->pll_output_freq >= rinfo->pll.ppll_min &&
  1603. rinfo->pll_output_freq <= rinfo->pll.ppll_max)
  1604. break;
  1605. }
  1606. rinfo->post_div = post_div->divider;
  1607. rinfo->fb_div = round_div(rinfo->pll.ref_div*rinfo->pll_output_freq,
  1608. rinfo->pll.ref_clk);
  1609. newmode.ppll_ref_div = rinfo->pll.ref_div;
  1610. newmode.ppll_div_3 = rinfo->fb_div | (post_div->bitvalue << 16);
  1611. }
  1612. newmode.vclk_ecp_cntl = rinfo->init_state.vclk_ecp_cntl;
  1613. #ifdef CONFIG_PPC_OF
  1614. /* Gross hack for iBook with M7 until I find out a proper fix */
  1615. if (machine_is_compatible("PowerBook4,3") && rinfo->arch == RADEON_M7)
  1616. newmode.ppll_div_3 = 0x000600ad;
  1617. #endif /* CONFIG_PPC_OF */
  1618. RTRACE("post div = 0x%x\n", rinfo->post_div);
  1619. RTRACE("fb_div = 0x%x\n", rinfo->fb_div);
  1620. RTRACE("ppll_div_3 = 0x%x\n", newmode.ppll_div_3);
  1621. /* DDA */
  1622. vclk_freq = round_div(rinfo->pll.ref_clk * rinfo->fb_div,
  1623. rinfo->pll.ref_div * rinfo->post_div);
  1624. xclk_freq = rinfo->pll.xclk;
  1625. xclk_per_trans = round_div(xclk_freq * 128, vclk_freq * mode->bits_per_pixel);
  1626. min_bits = min_bits_req(xclk_per_trans);
  1627. useable_precision = min_bits + 1;
  1628. xclk_per_trans_precise = round_div((xclk_freq * 128) << (11 - useable_precision),
  1629. vclk_freq * mode->bits_per_pixel);
  1630. ron = (4 * rinfo->ram.mb + 3 * _max(rinfo->ram.trcd - 2, 0) +
  1631. 2 * rinfo->ram.trp + rinfo->ram.twr + rinfo->ram.cl + rinfo->ram.tr2w +
  1632. xclk_per_trans) << (11 - useable_precision);
  1633. roff = xclk_per_trans_precise * (32 - 4);
  1634. RTRACE("ron = %d, roff = %d\n", ron, roff);
  1635. RTRACE("vclk_freq = %d, per = %d\n", vclk_freq, xclk_per_trans_precise);
  1636. if ((ron + rinfo->ram.rloop) >= roff) {
  1637. printk("radeonfb: error ron out of range\n");
  1638. return -EINVAL;
  1639. }
  1640. newmode.dda_config = (xclk_per_trans_precise |
  1641. (useable_precision << 16) |
  1642. (rinfo->ram.rloop << 20));
  1643. newmode.dda_on_off = (ron << 16) | roff;
  1644. if ((primary_mon == MT_DFP) || (primary_mon == MT_LCD)) {
  1645. unsigned int hRatio, vRatio;
  1646. /* We force the pixel clock to be always enabled. Allowing it
  1647. * to be power managed during blanking would save power, but has
  1648. * nasty interactions with the 2D engine & sleep code that haven't
  1649. * been solved yet. --BenH
  1650. */
  1651. newmode.vclk_ecp_cntl &= ~PIXCLK_DAC_ALWAYS_ONb;
  1652. if (mode->xres > rinfo->panel_xres)
  1653. mode->xres = rinfo->panel_xres;
  1654. if (mode->yres > rinfo->panel_yres)
  1655. mode->yres = rinfo->panel_yres;
  1656. newmode.fp_horz_stretch = (((rinfo->panel_xres / 8) - 1)
  1657. << HORZ_PANEL_SHIFT);
  1658. newmode.fp_vert_stretch = ((rinfo->panel_yres - 1)
  1659. << VERT_PANEL_SHIFT);
  1660. if (mode->xres != rinfo->panel_xres) {
  1661. hRatio = round_div(mode->xres * HORZ_STRETCH_RATIO_MAX,
  1662. rinfo->panel_xres);
  1663. newmode.fp_horz_stretch = (((((unsigned long)hRatio) & HORZ_STRETCH_RATIO_MASK)) |
  1664. (newmode.fp_horz_stretch &
  1665. (HORZ_PANEL_SIZE | HORZ_FP_LOOP_STRETCH |
  1666. HORZ_AUTO_RATIO_INC)));
  1667. newmode.fp_horz_stretch |= (HORZ_STRETCH_BLEND |
  1668. HORZ_STRETCH_ENABLE);
  1669. }
  1670. newmode.fp_horz_stretch &= ~HORZ_AUTO_RATIO;
  1671. if (mode->yres != rinfo->panel_yres) {
  1672. vRatio = round_div(mode->yres * VERT_STRETCH_RATIO_MAX,
  1673. rinfo->panel_yres);
  1674. newmode.fp_vert_stretch = (((((unsigned long)vRatio) & VERT_STRETCH_RATIO_MASK)) |
  1675. (newmode.fp_vert_stretch &
  1676. (VERT_PANEL_SIZE | VERT_STRETCH_RESERVED)));
  1677. newmode.fp_vert_stretch |= (VERT_STRETCH_BLEND |
  1678. VERT_STRETCH_ENABLE);
  1679. }
  1680. newmode.fp_vert_stretch &= ~VERT_AUTO_RATIO_EN;
  1681. newmode.fp_gen_cntl = (rinfo->init_state.fp_gen_cntl & (u32)
  1682. ~(FP_SEL_CRTC2 |
  1683. FP_RMX_HVSYNC_CONTROL_EN |
  1684. FP_DFP_SYNC_SEL |
  1685. FP_CRT_SYNC_SEL |
  1686. FP_CRTC_LOCK_8DOT |
  1687. FP_USE_SHADOW_EN |
  1688. FP_CRTC_USE_SHADOW_VEND |
  1689. FP_CRT_SYNC_ALT));
  1690. newmode.fp_gen_cntl |= (FP_CRTC_DONT_SHADOW_VPAR |
  1691. FP_CRTC_DONT_SHADOW_HEND);
  1692. newmode.lvds_gen_cntl = rinfo->init_state.lvds_gen_cntl;
  1693. newmode.lvds_pll_cntl = rinfo->init_state.lvds_pll_cntl;
  1694. newmode.tmds_crc = rinfo->init_state.tmds_crc;
  1695. newmode.tmds_transmitter_cntl = rinfo->init_state.tmds_transmitter_cntl;
  1696. if (primary_mon == MT_LCD) {
  1697. newmode.lvds_gen_cntl |= (LVDS_ON | LVDS_BLON);
  1698. newmode.fp_gen_cntl &= ~(FP_FPON | FP_TMDS_EN);
  1699. } else {
  1700. /* DFP */
  1701. newmode.fp_gen_cntl |= (FP_FPON | FP_TMDS_EN);
  1702. newmode.tmds_transmitter_cntl = (TMDS_RAN_PAT_RST |
  1703. TMDS_ICHCSEL | TMDS_PLL_EN) &
  1704. ~(TMDS_PLLRST);
  1705. newmode.crtc_ext_cntl &= ~CRTC_CRT_ON;
  1706. }
  1707. newmode.fp_crtc_h_total_disp = (((rinfo->hblank / 8) & 0x3ff) |
  1708. (((mode->xres / 8) - 1) << 16));
  1709. newmode.fp_crtc_v_total_disp = (rinfo->vblank & 0xffff) |
  1710. ((mode->yres - 1) << 16);
  1711. newmode.fp_h_sync_strt_wid = ((rinfo->hOver_plus & 0x1fff) |
  1712. (hsync_wid << 16) | (h_sync_pol << 23));
  1713. newmode.fp_v_sync_strt_wid = ((rinfo->vOver_plus & 0xfff) |
  1714. (vsync_wid << 16) | (v_sync_pol << 23));
  1715. }
  1716. /* do it! */
  1717. if (!rinfo->asleep) {
  1718. radeon_write_mode (rinfo, &newmode);
  1719. /* (re)initialize the engine */
  1720. if (noaccel)
  1721. radeon_engine_init (rinfo);
  1722. }
  1723. /* Update fix */
  1724. if (accel)
  1725. info->fix.line_length = rinfo->pitch*64;
  1726. else
  1727. info->fix.line_length = mode->xres_virtual * ((mode->bits_per_pixel + 1) / 8);
  1728. info->fix.visual = rinfo->depth == 8 ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_DIRECTCOLOR;
  1729. #ifdef CONFIG_BOOTX_TEXT
  1730. /* Update debug text engine */
  1731. btext_update_display(rinfo->fb_base_phys, mode->xres, mode->yres,
  1732. rinfo->depth, info->fix.line_length);
  1733. #endif
  1734. return 0;
  1735. }
  1736. static void radeon_write_mode (struct radeonfb_info *rinfo,
  1737. struct radeon_regs *mode)
  1738. {
  1739. int i;
  1740. int primary_mon = PRIMARY_MONITOR(rinfo);
  1741. radeonfb_blank(VESA_POWERDOWN, (struct fb_info *)rinfo);
  1742. if (rinfo->arch == RADEON_M6) {
  1743. for (i=0; i<7; i++)
  1744. OUTREG(common_regs_m6[i].reg, common_regs_m6[i].val);
  1745. } else {
  1746. for (i=0; i<9; i++)
  1747. OUTREG(common_regs[i].reg, common_regs[i].val);
  1748. }
  1749. OUTREG(CRTC_GEN_CNTL, mode->crtc_gen_cntl);
  1750. OUTREGP(CRTC_EXT_CNTL, mode->crtc_ext_cntl,
  1751. CRTC_HSYNC_DIS | CRTC_VSYNC_DIS | CRTC_DISPLAY_DIS);
  1752. OUTREGP(DAC_CNTL, mode->dac_cntl, DAC_RANGE_CNTL | DAC_BLANKING);
  1753. OUTREG(CRTC_H_TOTAL_DISP, mode->crtc_h_total_disp);
  1754. OUTREG(CRTC_H_SYNC_STRT_WID, mode->crtc_h_sync_strt_wid);
  1755. OUTREG(CRTC_V_TOTAL_DISP, mode->crtc_v_total_disp);
  1756. OUTREG(CRTC_V_SYNC_STRT_WID, mode->crtc_v_sync_strt_wid);
  1757. OUTREG(CRTC_OFFSET, 0);
  1758. OUTREG(CRTC_OFFSET_CNTL, 0);
  1759. OUTREG(CRTC_PITCH, mode->crtc_pitch);
  1760. #if defined(__BIG_ENDIAN)
  1761. OUTREG(SURFACE_CNTL, mode->surface_cntl);
  1762. #endif
  1763. while ((INREG(CLOCK_CNTL_INDEX) & PPLL_DIV_SEL_MASK) !=
  1764. PPLL_DIV_SEL_MASK) {
  1765. OUTREGP(CLOCK_CNTL_INDEX, PPLL_DIV_SEL_MASK, 0xffff);
  1766. }
  1767. OUTPLLP(PPLL_CNTL, PPLL_RESET, 0xffff);
  1768. while ((INPLL(PPLL_REF_DIV) & PPLL_REF_DIV_MASK) !=
  1769. (mode->ppll_ref_div & PPLL_REF_DIV_MASK)) {
  1770. OUTPLLP(PPLL_REF_DIV, mode->ppll_ref_div, ~PPLL_REF_DIV_MASK);
  1771. }
  1772. while ((INPLL(PPLL_DIV_3) & PPLL_FB3_DIV_MASK) !=
  1773. (mode->ppll_div_3 & PPLL_FB3_DIV_MASK)) {
  1774. OUTPLLP(PPLL_DIV_3, mode->ppll_div_3, ~PPLL_FB3_DIV_MASK);
  1775. }
  1776. while ((INPLL(PPLL_DIV_3) & PPLL_POST3_DIV_MASK) !=
  1777. (mode->ppll_div_3 & PPLL_POST3_DIV_MASK)) {
  1778. OUTPLLP(PPLL_DIV_3, mode->ppll_div_3, ~PPLL_POST3_DIV_MASK);
  1779. }
  1780. OUTPLL(HTOTAL_CNTL, 0);
  1781. OUTPLLP(PPLL_CNTL, 0, ~PPLL_RESET);
  1782. // OUTREG(DDA_CONFIG, mode->dda_config);
  1783. // OUTREG(DDA_ON_OFF, mode->dda_on_off);
  1784. if ((primary_mon == MT_DFP) || (primary_mon == MT_LCD)) {
  1785. OUTREG(FP_CRTC_H_TOTAL_DISP, mode->fp_crtc_h_total_disp);
  1786. OUTREG(FP_CRTC_V_TOTAL_DISP, mode->fp_crtc_v_total_disp);
  1787. OUTREG(FP_H_SYNC_STRT_WID, mode->fp_h_sync_strt_wid);
  1788. OUTREG(FP_V_SYNC_STRT_WID, mode->fp_v_sync_strt_wid);
  1789. OUTREG(FP_HORZ_STRETCH, mode->fp_horz_stretch);
  1790. OUTREG(FP_VERT_STRETCH, mode->fp_vert_stretch);
  1791. OUTREG(FP_GEN_CNTL, mode->fp_gen_cntl);
  1792. OUTREG(TMDS_CRC, mode->tmds_crc);
  1793. OUTREG(TMDS_TRANSMITTER_CNTL, mode->tmds_transmitter_cntl);
  1794. if (primary_mon == MT_LCD) {
  1795. unsigned int tmp = INREG(LVDS_GEN_CNTL);
  1796. mode->lvds_gen_cntl &= ~LVDS_STATE_MASK;
  1797. mode->lvds_gen_cntl |= (rinfo->init_state.lvds_gen_cntl & LVDS_STATE_MASK);
  1798. if ((tmp & (LVDS_ON | LVDS_BLON)) ==
  1799. (mode->lvds_gen_cntl & (LVDS_ON | LVDS_BLON))) {
  1800. OUTREG(LVDS_GEN_CNTL, mode->lvds_gen_cntl);
  1801. } else {
  1802. if (mode->lvds_gen_cntl & (LVDS_ON | LVDS_BLON)) {
  1803. udelay(1000);
  1804. OUTREG(LVDS_GEN_CNTL, mode->lvds_gen_cntl);
  1805. } else {
  1806. OUTREG(LVDS_GEN_CNTL, mode->lvds_gen_cntl |
  1807. LVDS_BLON);
  1808. udelay(1000);
  1809. OUTREG(LVDS_GEN_CNTL, mode->lvds_gen_cntl);
  1810. }
  1811. }
  1812. }
  1813. }
  1814. radeonfb_blank(VESA_NO_BLANKING, (struct fb_info *)rinfo);
  1815. OUTPLL(VCLK_ECP_CNTL, mode->vclk_ecp_cntl);
  1816. return;
  1817. }
  1818. static struct fb_ops radeonfb_ops = {
  1819. .owner = THIS_MODULE,
  1820. .fb_check_var = radeonfb_check_var,
  1821. .fb_set_par = radeonfb_set_par,
  1822. .fb_setcolreg = radeonfb_setcolreg,
  1823. .fb_pan_display = radeonfb_pan_display,
  1824. .fb_blank = radeonfb_blank,
  1825. .fb_ioctl = radeonfb_ioctl,
  1826. #if 0
  1827. .fb_fillrect = radeonfb_fillrect,
  1828. .fb_copyarea = radeonfb_copyarea,
  1829. .fb_imageblit = radeonfb_imageblit,
  1830. .fb_rasterimg = radeonfb_rasterimg,
  1831. #else
  1832. .fb_fillrect = cfb_fillrect,
  1833. .fb_copyarea = cfb_copyarea,
  1834. .fb_imageblit = cfb_imageblit,
  1835. #endif
  1836. .fb_cursor = soft_cursor,
  1837. };
  1838. static int __devinit radeon_set_fbinfo (struct radeonfb_info *rinfo)
  1839. {
  1840. struct fb_info *info;
  1841. info = &rinfo->info;
  1842. info->par = rinfo;
  1843. info->pseudo_palette = rinfo->pseudo_palette;
  1844. info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
  1845. info->fbops = &radeonfb_ops;
  1846. info->screen_base = rinfo->fb_base;
  1847. /* Fill fix common fields */
  1848. strlcpy(info->fix.id, rinfo->name, sizeof(info->fix.id));
  1849. info->fix.smem_start = rinfo->fb_base_phys;
  1850. info->fix.smem_len = rinfo->video_ram;
  1851. info->fix.type = FB_TYPE_PACKED_PIXELS;
  1852. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  1853. info->fix.xpanstep = 8;
  1854. info->fix.ypanstep = 1;
  1855. info->fix.ywrapstep = 0;
  1856. info->fix.type_aux = 0;
  1857. info->fix.mmio_start = rinfo->mmio_base_phys;
  1858. info->fix.mmio_len = RADEON_REGSIZE;
  1859. if (noaccel)
  1860. info->fix.accel = FB_ACCEL_NONE;
  1861. else
  1862. info->fix.accel = FB_ACCEL_ATI_RADEON;
  1863. if (radeon_init_disp (rinfo) < 0)
  1864. return -1;
  1865. return 0;
  1866. }
  1867. #ifdef CONFIG_PMAC_BACKLIGHT
  1868. /* TODO: Dbl check these tables, we don't go up to full ON backlight
  1869. * in these, possibly because we noticed MacOS doesn't, but I'd prefer
  1870. * having some more official numbers from ATI
  1871. */
  1872. static int backlight_conv_m6[] = {
  1873. 0xff, 0xc0, 0xb5, 0xaa, 0x9f, 0x94, 0x89, 0x7e,
  1874. 0x73, 0x68, 0x5d, 0x52, 0x47, 0x3c, 0x31, 0x24
  1875. };
  1876. static int backlight_conv_m7[] = {
  1877. 0x00, 0x3f, 0x4a, 0x55, 0x60, 0x6b, 0x76, 0x81,
  1878. 0x8c, 0x97, 0xa2, 0xad, 0xb8, 0xc3, 0xce, 0xd9
  1879. };
  1880. #define BACKLIGHT_LVDS_OFF
  1881. #undef BACKLIGHT_DAC_OFF
  1882. /* We turn off the LCD completely instead of just dimming the backlight.
  1883. * This provides some greater power saving and the display is useless
  1884. * without backlight anyway.
  1885. */
  1886. static int radeon_set_backlight_enable(int on, int level, void *data)
  1887. {
  1888. struct radeonfb_info *rinfo = (struct radeonfb_info *)data;
  1889. unsigned int lvds_gen_cntl = INREG(LVDS_GEN_CNTL);
  1890. int* conv_table;
  1891. /* Pardon me for that hack... maybe some day we can figure
  1892. * out in what direction backlight should work on a given
  1893. * panel ?
  1894. */
  1895. if ((rinfo->arch == RADEON_M7 || rinfo->arch == RADEON_M9)
  1896. && !machine_is_compatible("PowerBook4,3"))
  1897. conv_table = backlight_conv_m7;
  1898. else
  1899. conv_table = backlight_conv_m6;
  1900. lvds_gen_cntl |= (LVDS_BL_MOD_EN | LVDS_BLON);
  1901. if (on && (level > BACKLIGHT_OFF)) {
  1902. lvds_gen_cntl |= LVDS_DIGON;
  1903. if (!(lvds_gen_cntl & LVDS_ON)) {
  1904. lvds_gen_cntl &= ~LVDS_BLON;
  1905. OUTREG(LVDS_GEN_CNTL, lvds_gen_cntl);
  1906. (void)INREG(LVDS_GEN_CNTL);
  1907. mdelay(10);
  1908. lvds_gen_cntl |= LVDS_BLON;
  1909. OUTREG(LVDS_GEN_CNTL, lvds_gen_cntl);
  1910. }
  1911. lvds_gen_cntl &= ~LVDS_BL_MOD_LEVEL_MASK;
  1912. lvds_gen_cntl |= (conv_table[level] <<
  1913. LVDS_BL_MOD_LEVEL_SHIFT);
  1914. lvds_gen_cntl |= (LVDS_ON | LVDS_EN);
  1915. lvds_gen_cntl &= ~LVDS_DISPLAY_DIS;
  1916. } else {
  1917. lvds_gen_cntl &= ~LVDS_BL_MOD_LEVEL_MASK;
  1918. lvds_gen_cntl |= (conv_table[0] <<
  1919. LVDS_BL_MOD_LEVEL_SHIFT);
  1920. lvds_gen_cntl |= LVDS_DISPLAY_DIS;
  1921. OUTREG(LVDS_GEN_CNTL, lvds_gen_cntl);
  1922. udelay(10);
  1923. lvds_gen_cntl &= ~(LVDS_ON | LVDS_EN | LVDS_BLON | LVDS_DIGON);
  1924. }
  1925. OUTREG(LVDS_GEN_CNTL, lvds_gen_cntl);
  1926. rinfo->init_state.lvds_gen_cntl &= ~LVDS_STATE_MASK;
  1927. rinfo->init_state.lvds_gen_cntl |= (lvds_gen_cntl & LVDS_STATE_MASK);
  1928. return 0;
  1929. }
  1930. static int radeon_set_backlight_level(int level, void *data)
  1931. {
  1932. return radeon_set_backlight_enable(1, level, data);
  1933. }
  1934. #endif /* CONFIG_PMAC_BACKLIGHT */
  1935. #ifdef CONFIG_PMAC_PBOOK
  1936. static u32 dbg_clk;
  1937. /*
  1938. * Radeon M6 Power Management code. This code currently only supports
  1939. * the mobile chips, it's based from some informations provided by ATI
  1940. * along with hours of tracing of MacOS drivers
  1941. */
  1942. static void radeon_pm_save_regs(struct radeonfb_info *rinfo)
  1943. {
  1944. rinfo->save_regs[0] = INPLL(PLL_PWRMGT_CNTL);
  1945. rinfo->save_regs[1] = INPLL(CLK_PWRMGT_CNTL);
  1946. rinfo->save_regs[2] = INPLL(MCLK_CNTL);
  1947. rinfo->save_regs[3] = INPLL(SCLK_CNTL);
  1948. rinfo->save_regs[4] = INPLL(CLK_PIN_CNTL);
  1949. rinfo->save_regs[5] = INPLL(VCLK_ECP_CNTL);
  1950. rinfo->save_regs[6] = INPLL(PIXCLKS_CNTL);
  1951. rinfo->save_regs[7] = INPLL(MCLK_MISC);
  1952. rinfo->save_regs[8] = INPLL(P2PLL_CNTL);
  1953. rinfo->save_regs[9] = INREG(DISP_MISC_CNTL);
  1954. rinfo->save_regs[10] = INREG(DISP_PWR_MAN);
  1955. rinfo->save_regs[11] = INREG(LVDS_GEN_CNTL);
  1956. rinfo->save_regs[12] = INREG(LVDS_PLL_CNTL);
  1957. rinfo->save_regs[13] = INREG(TV_DAC_CNTL);
  1958. rinfo->save_regs[14] = INREG(BUS_CNTL1);
  1959. rinfo->save_regs[15] = INREG(CRTC_OFFSET_CNTL);
  1960. rinfo->save_regs[16] = INREG(AGP_CNTL);
  1961. rinfo->save_regs[17] = (INREG(CRTC_GEN_CNTL) & 0xfdffffff) | 0x04000000;
  1962. rinfo->save_regs[18] = (INREG(CRTC2_GEN_CNTL) & 0xfdffffff) | 0x04000000;
  1963. rinfo->save_regs[19] = INREG(GPIOPAD_A);
  1964. rinfo->save_regs[20] = INREG(GPIOPAD_EN);
  1965. rinfo->save_regs[21] = INREG(GPIOPAD_MASK);
  1966. rinfo->save_regs[22] = INREG(ZV_LCDPAD_A);
  1967. rinfo->save_regs[23] = INREG(ZV_LCDPAD_EN);
  1968. rinfo->save_regs[24] = INREG(ZV_LCDPAD_MASK);
  1969. rinfo->save_regs[25] = INREG(GPIO_VGA_DDC);
  1970. rinfo->save_regs[26] = INREG(GPIO_DVI_DDC);
  1971. rinfo->save_regs[27] = INREG(GPIO_MONID);
  1972. rinfo->save_regs[28] = INREG(GPIO_CRT2_DDC);
  1973. rinfo->save_regs[29] = INREG(SURFACE_CNTL);
  1974. rinfo->save_regs[30] = INREG(MC_FB_LOCATION);
  1975. rinfo->save_regs[31] = INREG(DISPLAY_BASE_ADDR);
  1976. rinfo->save_regs[32] = INREG(MC_AGP_LOCATION);
  1977. rinfo->save_regs[33] = INREG(CRTC2_DISPLAY_BASE_ADDR);
  1978. }
  1979. static void radeon_pm_restore_regs(struct radeonfb_info *rinfo)
  1980. {
  1981. OUTPLL(P2PLL_CNTL, rinfo->save_regs[8] & 0xFFFFFFFE); /* First */
  1982. OUTPLL(PLL_PWRMGT_CNTL, rinfo->save_regs[0]);
  1983. OUTPLL(CLK_PWRMGT_CNTL, rinfo->save_regs[1]);
  1984. OUTPLL(MCLK_CNTL, rinfo->save_regs[2]);
  1985. OUTPLL(SCLK_CNTL, rinfo->save_regs[3]);
  1986. OUTPLL(CLK_PIN_CNTL, rinfo->save_regs[4]);
  1987. OUTPLL(VCLK_ECP_CNTL, rinfo->save_regs[5]);
  1988. OUTPLL(PIXCLKS_CNTL, rinfo->save_regs[6]);
  1989. OUTPLL(MCLK_MISC, rinfo->save_regs[7]);
  1990. OUTREG(DISP_MISC_CNTL, rinfo->save_regs[9]);
  1991. OUTREG(DISP_PWR_MAN, rinfo->save_regs[10]);
  1992. OUTREG(LVDS_GEN_CNTL, rinfo->save_regs[11]);
  1993. OUTREG(LVDS_PLL_CNTL,rinfo->save_regs[12]);
  1994. OUTREG(TV_DAC_CNTL, rinfo->save_regs[13]);
  1995. OUTREG(BUS_CNTL1, rinfo->save_regs[14]);
  1996. OUTREG(CRTC_OFFSET_CNTL, rinfo->save_regs[15]);
  1997. OUTREG(AGP_CNTL, rinfo->save_regs[16]);
  1998. OUTREG(CRTC_GEN_CNTL, rinfo->save_regs[17]);
  1999. OUTREG(CRTC2_GEN_CNTL, rinfo->save_regs[18]);
  2000. // wait VBL before that one ?
  2001. OUTPLL(P2PLL_CNTL, rinfo->save_regs[8]);
  2002. OUTREG(GPIOPAD_A, rinfo->save_regs[19]);
  2003. OUTREG(GPIOPAD_EN, rinfo->save_regs[20]);
  2004. OUTREG(GPIOPAD_MASK, rinfo->save_regs[21]);
  2005. OUTREG(ZV_LCDPAD_A, rinfo->save_regs[22]);
  2006. OUTREG(ZV_LCDPAD_EN, rinfo->save_regs[23]);
  2007. OUTREG(ZV_LCDPAD_MASK, rinfo->save_regs[24]);
  2008. OUTREG(GPIO_VGA_DDC, rinfo->save_regs[25]);
  2009. OUTREG(GPIO_DVI_DDC, rinfo->save_regs[26]);
  2010. OUTREG(GPIO_MONID, rinfo->save_regs[27]);
  2011. OUTREG(GPIO_CRT2_DDC, rinfo->save_regs[28]);
  2012. }
  2013. static void radeon_pm_disable_iopad(struct radeonfb_info *rinfo)
  2014. {
  2015. OUTREG(GPIOPAD_MASK, 0x0001ffff);
  2016. OUTREG(GPIOPAD_EN, 0x00000400);
  2017. OUTREG(GPIOPAD_A, 0x00000000);
  2018. OUTREG(ZV_LCDPAD_MASK, 0x00000000);
  2019. OUTREG(ZV_LCDPAD_EN, 0x00000000);
  2020. OUTREG(ZV_LCDPAD_A, 0x00000000);
  2021. OUTREG(GPIO_VGA_DDC, 0x00030000);
  2022. OUTREG(GPIO_DVI_DDC, 0x00000000);
  2023. OUTREG(GPIO_MONID, 0x00030000);
  2024. OUTREG(GPIO_CRT2_DDC, 0x00000000);
  2025. }
  2026. static void radeon_pm_program_v2clk(struct radeonfb_info *rinfo)
  2027. {
  2028. //
  2029. // u32 reg;
  2030. //
  2031. // OUTPLL(P2PLL_REF_DIV, 0x0c);
  2032. //
  2033. // .../... figure out what macos does here
  2034. }
  2035. static void radeon_pm_low_current(struct radeonfb_info *rinfo)
  2036. {
  2037. u32 reg;
  2038. reg = INREG(BUS_CNTL1);
  2039. reg &= ~BUS_CNTL1_MOBILE_PLATFORM_SEL_MASK;
  2040. reg |= BUS_CNTL1_AGPCLK_VALID | (1<<BUS_CNTL1_MOBILE_PLATFORM_SEL_SHIFT);
  2041. OUTREG(BUS_CNTL1, reg);
  2042. reg = INPLL(PLL_PWRMGT_CNTL);
  2043. reg |= PLL_PWRMGT_CNTL_SPLL_TURNOFF | PLL_PWRMGT_CNTL_PPLL_TURNOFF |
  2044. PLL_PWRMGT_CNTL_P2PLL_TURNOFF | PLL_PWRMGT_CNTL_TVPLL_TURNOFF;
  2045. reg &= ~PLL_PWRMGT_CNTL_SU_MCLK_USE_BCLK;
  2046. reg &= ~PLL_PWRMGT_CNTL_MOBILE_SU;
  2047. OUTPLL(PLL_PWRMGT_CNTL, reg);
  2048. // reg = INPLL(TV_PLL_CNTL1);
  2049. // reg |= TV_PLL_CNTL1__TVPLL_RESET | TV_PLL_CNTL1__TVPLL_SLEEP;
  2050. // OUTPLL(TV_PLL_CNTL1, reg);
  2051. reg = INREG(TV_DAC_CNTL);
  2052. reg &= ~(TV_DAC_CNTL_BGADJ_MASK |TV_DAC_CNTL_DACADJ_MASK);
  2053. reg |=TV_DAC_CNTL_BGSLEEP | TV_DAC_CNTL_RDACPD | TV_DAC_CNTL_GDACPD |
  2054. TV_DAC_CNTL_BDACPD |
  2055. (8<<TV_DAC_CNTL_BGADJ__SHIFT) | (8<<TV_DAC_CNTL_DACADJ__SHIFT);
  2056. OUTREG(TV_DAC_CNTL, reg);
  2057. reg = INREG(TMDS_TRANSMITTER_CNTL);
  2058. reg &= ~(TMDS_PLL_EN |TMDS_PLLRST);
  2059. OUTREG(TMDS_TRANSMITTER_CNTL, reg);
  2060. // lvds_pll_cntl = regr32(g, LVDS_PLL_CNTL);
  2061. // lvds_pll_cntl &= ~LVDS_PLL_CNTL__LVDS_PLL_EN;
  2062. // lvds_pll_cntl |= LVDS_PLL_CNTL__LVDS_PLL_RESET;
  2063. // regw32(g, LVDS_PLL_CNTL, lvds_pll_cntl);
  2064. reg = INREG(DAC_CNTL);
  2065. reg &= ~DAC_CMP_EN;
  2066. OUTREG(DAC_CNTL, reg);
  2067. reg = INREG(DAC_CNTL2);
  2068. reg &= ~DAC2_CMP_EN;
  2069. OUTREG(DAC_CNTL2, reg);
  2070. reg = INREG(TV_DAC_CNTL);
  2071. reg &= ~TV_DAC_CNTL_DETECT;
  2072. OUTREG(TV_DAC_CNTL, reg);
  2073. }
  2074. static void radeon_pm_setup_for_suspend(struct radeonfb_info *rinfo)
  2075. {
  2076. /* This code is disabled. It does what is in the pm_init
  2077. * function of the MacOS driver code ATI sent me. However,
  2078. * it doesn't fix my sleep problem, and is causing other issues
  2079. * on wakeup (bascially the machine dying when switching consoles
  2080. * I haven't had time to investigate this yet
  2081. */
  2082. #if 0
  2083. u32 disp_misc_cntl;
  2084. u32 disp_pwr_man;
  2085. u32 temp;
  2086. // set SPLL, MPLL, PPLL, P2PLL, TVPLL, SCLK, MCLK, PCLK, P2CLK,
  2087. // TCLK and TEST_MODE to 0
  2088. temp = INPLL(CLK_PWRMGT_CNTL);
  2089. OUTPLL(CLK_PWRMGT_CNTL , temp & ~0xc00002ff);
  2090. // Turn on Power Management
  2091. temp = INPLL(CLK_PWRMGT_CNTL);
  2092. OUTPLL(CLK_PWRMGT_CNTL , temp | 0x00000400);
  2093. // Turn off display clock if using mobile chips
  2094. temp = INPLL(CLK_PWRMGT_CNTL);
  2095. OUTREG(CLK_PWRMGT_CNTL , temp | 0x00100000);
  2096. // Force PIXCLK_ALWAYS_ON and PIXCLK_DAC_ALWAYS_ON
  2097. temp = INPLL(VCLK_ECP_CNTL);
  2098. OUTPLL(VCLK_ECP_CNTL, temp & ~0x000000c0);
  2099. // Force ECP_FORCE_ON to 1
  2100. temp = INPLL(VCLK_ECP_CNTL);
  2101. OUTPLL(VCLK_ECP_CNTL, temp | 0x00040000);
  2102. // Force PIXCLK_BLEND_ALWAYS_ON and PIXCLK_GV_ALWAYS_ON
  2103. temp = INPLL(PIXCLKS_CNTL);
  2104. OUTPLL(PIXCLKS_CNTL, temp & ~0x00001800);
  2105. // Forcing SCLK_CNTL to ON
  2106. OUTPLL(SCLK_CNTL, (INPLL(SCLK_CNTL)& 0x00000007) | 0xffff8000 );
  2107. // Set PM control over XTALIN pad
  2108. temp = INPLL(CLK_PIN_CNTL);
  2109. OUTPLL(CLK_PIN_CNTL, temp | 0x00080000);
  2110. // Force MCLK and YCLK and MC as dynamic
  2111. temp = INPLL(MCLK_CNTL);
  2112. OUTPLL(MCLK_CNTL, temp & 0xffeaffff);
  2113. // PLL_TURNOFF
  2114. temp = INPLL(PLL_PWRMGT_CNTL);
  2115. OUTPLL(PLL_PWRMGT_CNTL, temp | 0x0000001f);
  2116. // set MOBILE_SU to 1 if M6 or DDR64 is detected
  2117. temp = INPLL(PLL_PWRMGT_CNTL);
  2118. OUTPLL(PLL_PWRMGT_CNTL, temp | 0x00010000);
  2119. // select PM access mode (PM_MODE_SEL) (use ACPI mode)
  2120. // temp = INPLL(PLL_PWRMGT_CNTL);
  2121. // OUTPLL(PLL_PWRMGT_CNTL, temp | 0x00002000);
  2122. temp = INPLL(PLL_PWRMGT_CNTL);
  2123. OUTPLL(PLL_PWRMGT_CNTL, temp & ~0x00002000);
  2124. // set DISP_MISC_CNTL register
  2125. disp_misc_cntl = INREG(DISP_MISC_CNTL);
  2126. disp_misc_cntl &= ~( DISP_MISC_CNTL_SOFT_RESET_GRPH_PP |
  2127. DISP_MISC_CNTL_SOFT_RESET_SUBPIC_PP |
  2128. DISP_MISC_CNTL_SOFT_RESET_OV0_PP |
  2129. DISP_MISC_CNTL_SOFT_RESET_GRPH_SCLK |
  2130. DISP_MISC_CNTL_SOFT_RESET_SUBPIC_SCLK |
  2131. DISP_MISC_CNTL_SOFT_RESET_OV0_SCLK |
  2132. DISP_MISC_CNTL_SOFT_RESET_GRPH2_PP |
  2133. DISP_MISC_CNTL_SOFT_RESET_GRPH2_SCLK |
  2134. DISP_MISC_CNTL_SOFT_RESET_LVDS |
  2135. DISP_MISC_CNTL_SOFT_RESET_TMDS |
  2136. DISP_MISC_CNTL_SOFT_RESET_DIG_TMDS |
  2137. DISP_MISC_CNTL_SOFT_RESET_TV);
  2138. OUTREG(DISP_MISC_CNTL, disp_misc_cntl);
  2139. // set DISP_PWR_MAN register
  2140. disp_pwr_man = INREG(DISP_PWR_MAN);
  2141. // clau - 9.29.2000 - changes made to bit23:18 to set to 1 as requested by George
  2142. disp_pwr_man |= (DISP_PWR_MAN_DIG_TMDS_ENABLE_RST |
  2143. DISP_PWR_MAN_TV_ENABLE_RST |
  2144. // DISP_PWR_MAN_AUTO_PWRUP_EN |
  2145. DISP_PWR_MAN_DISP_D3_GRPH_RST |
  2146. DISP_PWR_MAN_DISP_D3_SUBPIC_RST |
  2147. DISP_PWR_MAN_DISP_D3_OV0_RST |
  2148. DISP_PWR_MAN_DISP_D1D2_GRPH_RST |
  2149. DISP_PWR_MAN_DISP_D1D2_SUBPIC_RST |
  2150. DISP_PWR_MAN_DISP_D1D2_OV0_RST);
  2151. disp_pwr_man &= ~(DISP_PWR_MAN_DISP_PWR_MAN_D3_CRTC_EN |
  2152. DISP_PWR_MAN_DISP2_PWR_MAN_D3_CRTC2_EN|
  2153. DISP_PWR_MAN_DISP_D3_RST |
  2154. DISP_PWR_MAN_DISP_D3_REG_RST);
  2155. OUTREG(DISP_PWR_MAN, disp_pwr_man);
  2156. // clau - 10.24.2000
  2157. // - add in setting for BUS_CNTL1 b27:26 = 0x01 and b31 = 0x1
  2158. // - add in setting for AGP_CNTL b7:0 = 0x20
  2159. // - add in setting for DVI_DDC_DATA_OUT_EN b17:16 = 0x0
  2160. // the following settings (two lines) are applied at a later part of this function, only on mobile platform
  2161. // requres -mobile flag
  2162. OUTREG(BUS_CNTL1, (INREG(BUS_CNTL1) & 0xf3ffffff) | 0x04000000);
  2163. OUTREG(BUS_CNTL1, INREG(BUS_CNTL1) | 0x80000000);
  2164. OUTREG(AGP_CNTL, (INREG(AGP_CNTL) & 0xffffff00) | 0x20);
  2165. OUTREG(GPIO_DVI_DDC, INREG(GPIO_DVI_DDC) & 0xfffcffff);
  2166. // yulee - 12.12.2000
  2167. // A12 only
  2168. // EN_MCLK_TRISTATE_IN_SUSPEND@MCLK_MISC = 1
  2169. // ACCESS_REGS_IN_SUSPEND@CLK_PIN_CNTL = 0
  2170. // only on mobile platform
  2171. OUTPLL(MCLK_MISC, INPLL(MCLK_MISC) | 0x00040000 );
  2172. // yulee -12.12.2000
  2173. // AGPCLK_VALID@BUS_CNTL1 = 1
  2174. // MOBILE_PLATFORM_SEL@BUS_CNTL1 = 01
  2175. // CRTC_STEREO_SYNC_OUT_EN@CRTC_OFFSET_CNTL = 0
  2176. // CG_CLK_TO_OUTPIN@CLK_PIN_CNTL = 0
  2177. // only on mobile platform
  2178. OUTPLL(CLK_PIN_CNTL, INPLL(CLK_PIN_CNTL ) & 0xFFFFF7FF );
  2179. OUTREG(BUS_CNTL1, (INREG(BUS_CNTL1 ) & 0xF3FFFFFF) | 0x84000000 );
  2180. OUTREG(CRTC_OFFSET_CNTL, INREG(CRTC_OFFSET_CNTL ) & 0xFFEFFFFF );
  2181. mdelay(100);
  2182. #endif
  2183. /* Disable CRTCs */
  2184. OUTREG(CRTC_GEN_CNTL, (INREG(CRTC_GEN_CNTL) & ~CRTC_EN) | CRTC_DISP_REQ_EN_B);
  2185. OUTREG(CRTC2_GEN_CNTL, (INREG(CRTC2_GEN_CNTL) & ~CRTC2_EN) | CRTC2_DISP_REQ_EN_B);
  2186. (void)INREG(CRTC2_GEN_CNTL);
  2187. mdelay(17);
  2188. }
  2189. static void radeon_set_suspend(struct radeonfb_info *rinfo, int suspend)
  2190. {
  2191. u16 pwr_cmd;
  2192. if (!rinfo->pm_reg)
  2193. return;
  2194. /* Set the chip into appropriate suspend mode (we use D2,
  2195. * D3 would require a compete re-initialization of the chip,
  2196. * including PCI config registers, clocks, AGP conf, ...)
  2197. */
  2198. if (suspend) {
  2199. /* According to ATI, we should program V2CLK here, I have
  2200. * to verify what's up exactly
  2201. */
  2202. /* Save some registers */
  2203. radeon_pm_save_regs(rinfo);
  2204. /* Check that on M7 too, might work might not. M7 may also
  2205. * need explicit enabling of PM
  2206. */
  2207. if (rinfo->arch == RADEON_M6) {
  2208. /* Program V2CLK */
  2209. radeon_pm_program_v2clk(rinfo);
  2210. /* Disable IO PADs */
  2211. radeon_pm_disable_iopad(rinfo);
  2212. /* Set low current */
  2213. radeon_pm_low_current(rinfo);
  2214. /* Prepare chip for power management */
  2215. radeon_pm_setup_for_suspend(rinfo);
  2216. /* Reset the MDLL */
  2217. OUTPLL(MDLL_CKO, INPLL(MDLL_CKO) | MCKOA_RESET);
  2218. (void)INPLL(MDLL_RDCKA);
  2219. OUTPLL(MDLL_CKO, INPLL(MDLL_CKO) & ~MCKOA_RESET);
  2220. (void)INPLL(MDLL_RDCKA);
  2221. }
  2222. /* Switch PCI power managment to D2. */
  2223. for (;;) {
  2224. pci_read_config_word(
  2225. rinfo->pdev, rinfo->pm_reg+PCI_PM_CTRL,
  2226. &pwr_cmd);
  2227. if (pwr_cmd & 2)
  2228. break;
  2229. pci_write_config_word(
  2230. rinfo->pdev, rinfo->pm_reg+PCI_PM_CTRL,
  2231. (pwr_cmd & ~PCI_PM_CTRL_STATE_MASK) | 2);
  2232. mdelay(500);
  2233. }
  2234. } else {
  2235. /* Switch back PCI powermanagment to D0 */
  2236. mdelay(200);
  2237. pci_write_config_word(rinfo->pdev, rinfo->pm_reg+PCI_PM_CTRL, 0);
  2238. mdelay(500);
  2239. dbg_clk = INPLL(1);
  2240. /* Do we need that on M7 ? */
  2241. if (rinfo->arch == RADEON_M6) {
  2242. /* Restore the MDLL */
  2243. OUTPLL(MDLL_CKO, INPLL(MDLL_CKO) & ~MCKOA_RESET);
  2244. (void)INPLL(MDLL_CKO);
  2245. }
  2246. /* Restore some registers */
  2247. radeon_pm_restore_regs(rinfo);
  2248. }
  2249. }
  2250. /*
  2251. * Save the contents of the framebuffer when we go to sleep,
  2252. * and restore it when we wake up again.
  2253. */
  2254. int radeon_sleep_notify(struct pmu_sleep_notifier *self, int when)
  2255. {
  2256. struct radeonfb_info *rinfo;
  2257. for (rinfo = board_list; rinfo != NULL; rinfo = rinfo->next) {
  2258. struct fb_fix_screeninfo fix;
  2259. int nb;
  2260. struct display *disp;
  2261. disp = (rinfo->currcon < 0) ? rinfo->info.disp : &fb_display[rinfo->currcon];
  2262. switch (rinfo->arch) {
  2263. case RADEON_M6:
  2264. case RADEON_M7:
  2265. case RADEON_M9:
  2266. break;
  2267. default:
  2268. return PBOOK_SLEEP_REFUSE;
  2269. }
  2270. radeonfb_get_fix(&fix, fg_console, (struct fb_info *)rinfo);
  2271. nb = fb_display[fg_console].var.yres * fix.line_length;
  2272. switch (when) {
  2273. case PBOOK_SLEEP_NOW:
  2274. acquire_console_sem();
  2275. disp->dispsw = &fbcon_dummy;
  2276. if (!noaccel) {
  2277. /* Make sure engine is reset */
  2278. radeon_engine_reset();
  2279. radeon_engine_idle();
  2280. }
  2281. /* Blank display and LCD */
  2282. radeonfb_blank(VESA_POWERDOWN+1,
  2283. (struct fb_info *)rinfo);
  2284. /* Sleep */
  2285. rinfo->asleep = 1;
  2286. radeon_set_suspend(rinfo, 1);
  2287. release_console_sem();
  2288. break;
  2289. case PBOOK_WAKE:
  2290. acquire_console_sem();
  2291. /* Wakeup */
  2292. radeon_set_suspend(rinfo, 0);
  2293. if (!noaccel)
  2294. radeon_engine_init(rinfo);
  2295. rinfo->asleep = 0;
  2296. radeon_set_dispsw(rinfo, disp);
  2297. radeon_load_video_mode(rinfo, &disp->var);
  2298. do_install_cmap(rinfo->currcon < 0 ? 0 : rinfo->currcon,
  2299. (struct fb_info *)rinfo);
  2300. radeonfb_blank(0, (struct fb_info *)rinfo);
  2301. release_console_sem();
  2302. printk("CLK_PIN_CNTL on wakeup was: %08x\n", dbg_clk);
  2303. break;
  2304. }
  2305. }
  2306. return PBOOK_SLEEP_OK;
  2307. }
  2308. #endif /* CONFIG_PMAC_PBOOK */
  2309. static int radeonfb_pci_register (struct pci_dev *pdev,
  2310. const struct pci_device_id *ent)
  2311. {
  2312. struct radeonfb_info *rinfo;
  2313. struct radeon_chip_info *rci = &radeon_chip_info[ent->driver_data];
  2314. u32 tmp;
  2315. RTRACE("radeonfb_pci_register BEGIN\n");
  2316. /* Enable device in PCI config */
  2317. if (pci_enable_device(pdev) != 0) {
  2318. printk(KERN_ERR "radeonfb: Cannot enable PCI device\n");
  2319. return -ENODEV;
  2320. }
  2321. rinfo = kmalloc (sizeof (struct radeonfb_info), GFP_KERNEL);
  2322. if (!rinfo) {
  2323. printk ("radeonfb: could not allocate memory\n");
  2324. return -ENODEV;
  2325. }
  2326. memset (rinfo, 0, sizeof (struct radeonfb_info));
  2327. //info = &rinfo->info;
  2328. rinfo->pdev = pdev;
  2329. strcpy(rinfo->name, rci->name);
  2330. rinfo->arch = rci->arch;
  2331. /* Set base addrs */
  2332. rinfo->fb_base_phys = pci_resource_start (pdev, 0);
  2333. rinfo->mmio_base_phys = pci_resource_start (pdev, 2);
  2334. /* request the mem regions */
  2335. if (!request_mem_region (rinfo->fb_base_phys,
  2336. pci_resource_len(pdev, 0), "radeonfb")) {
  2337. printk ("radeonfb: cannot reserve FB region\n");
  2338. kfree (rinfo);
  2339. return -ENODEV;
  2340. }
  2341. if (!request_mem_region (rinfo->mmio_base_phys,
  2342. pci_resource_len(pdev, 2), "radeonfb")) {
  2343. printk ("radeonfb: cannot reserve MMIO region\n");
  2344. release_mem_region (rinfo->fb_base_phys,
  2345. pci_resource_len(pdev, 0));
  2346. kfree (rinfo);
  2347. return -ENODEV;
  2348. }
  2349. /* map the regions */
  2350. rinfo->mmio_base = ioremap (rinfo->mmio_base_phys, RADEON_REGSIZE);
  2351. if (!rinfo->mmio_base) {
  2352. printk ("radeonfb: cannot map MMIO\n");
  2353. release_mem_region (rinfo->mmio_base_phys,
  2354. pci_resource_len(pdev, 2));
  2355. release_mem_region (rinfo->fb_base_phys,
  2356. pci_resource_len(pdev, 0));
  2357. kfree (rinfo);
  2358. return -ENODEV;
  2359. }
  2360. rinfo->chipset = pdev->device;
  2361. switch (rinfo->arch) {
  2362. case RADEON_R100:
  2363. rinfo->hasCRTC2 = 0;
  2364. break;
  2365. default:
  2366. /* all the rest have it */
  2367. rinfo->hasCRTC2 = 1;
  2368. break;
  2369. }
  2370. #if 0
  2371. if (rinfo->arch == RADEON_M7) {
  2372. /*
  2373. * Noticed some errors in accel with M7, will have to work these out...
  2374. */
  2375. noaccel = 1;
  2376. }
  2377. #endif
  2378. if (mirror)
  2379. printk("radeonfb: mirroring display to CRT\n");
  2380. /* framebuffer size */
  2381. tmp = INREG(CONFIG_MEMSIZE);
  2382. /* mem size is bits [28:0], mask off the rest */
  2383. rinfo->video_ram = tmp & CONFIG_MEMSIZE_MASK;
  2384. /* ram type */
  2385. tmp = INREG(MEM_SDRAM_MODE_REG);
  2386. switch ((MEM_CFG_TYPE & tmp) >> 30) {
  2387. case 0:
  2388. /* SDR SGRAM (2:1) */
  2389. strcpy(rinfo->ram_type, "SDR SGRAM");
  2390. rinfo->ram.ml = 4;
  2391. rinfo->ram.mb = 4;
  2392. rinfo->ram.trcd = 1;
  2393. rinfo->ram.trp = 2;
  2394. rinfo->ram.twr = 1;
  2395. rinfo->ram.cl = 2;
  2396. rinfo->ram.loop_latency = 16;
  2397. rinfo->ram.rloop = 16;
  2398. break;
  2399. case 1:
  2400. /* DDR SGRAM */
  2401. strcpy(rinfo->ram_type, "DDR SGRAM");
  2402. rinfo->ram.ml = 4;
  2403. rinfo->ram.mb = 4;
  2404. rinfo->ram.trcd = 3;
  2405. rinfo->ram.trp = 3;
  2406. rinfo->ram.twr = 2;
  2407. rinfo->ram.cl = 3;
  2408. rinfo->ram.tr2w = 1;
  2409. rinfo->ram.loop_latency = 16;
  2410. rinfo->ram.rloop = 16;
  2411. break;
  2412. default:
  2413. /* 64-bit SDR SGRAM */
  2414. strcpy(rinfo->ram_type, "SDR SGRAM 64");
  2415. rinfo->ram.ml = 4;
  2416. rinfo->ram.mb = 8;
  2417. rinfo->ram.trcd = 3;
  2418. rinfo->ram.trp = 3;
  2419. rinfo->ram.twr = 1;
  2420. rinfo->ram.cl = 3;
  2421. rinfo->ram.tr2w = 1;
  2422. rinfo->ram.loop_latency = 17;
  2423. rinfo->ram.rloop = 17;
  2424. break;
  2425. }
  2426. rinfo->bios_seg = radeon_find_rom(rinfo);
  2427. radeon_get_pllinfo(rinfo, rinfo->bios_seg);
  2428. /*
  2429. * Hack to get around some busted production M6's
  2430. * reporting no ram
  2431. */
  2432. if (rinfo->video_ram == 0) {
  2433. switch (pdev->device) {
  2434. case PCI_DEVICE_ID_ATI_RADEON_LY:
  2435. case PCI_DEVICE_ID_ATI_RADEON_LZ:
  2436. rinfo->video_ram = 8192 * 1024;
  2437. break;
  2438. default:
  2439. break;
  2440. }
  2441. }
  2442. RTRACE("radeonfb: probed %s %dk videoram\n", (rinfo->ram_type), (rinfo->video_ram/1024));
  2443. #if !defined(__powerpc__)
  2444. radeon_get_moninfo(rinfo);
  2445. #else
  2446. switch (pdev->device) {
  2447. case PCI_DEVICE_ID_ATI_RADEON_LW:
  2448. case PCI_DEVICE_ID_ATI_RADEON_LX:
  2449. case PCI_DEVICE_ID_ATI_RADEON_LY:
  2450. case PCI_DEVICE_ID_ATI_RADEON_LZ:
  2451. rinfo->dviDisp_type = MT_LCD;
  2452. break;
  2453. default:
  2454. radeon_get_moninfo(rinfo);
  2455. break;
  2456. }
  2457. #endif
  2458. radeon_get_EDID(rinfo);
  2459. if ((rinfo->dviDisp_type == MT_DFP) || (rinfo->dviDisp_type == MT_LCD) ||
  2460. (rinfo->crtDisp_type == MT_DFP)) {
  2461. if (!radeon_get_dfpinfo(rinfo)) {
  2462. iounmap(rinfo->mmio_base);
  2463. release_mem_region (rinfo->mmio_base_phys,
  2464. pci_resource_len(pdev, 2));
  2465. release_mem_region (rinfo->fb_base_phys,
  2466. pci_resource_len(pdev, 0));
  2467. kfree (rinfo);
  2468. return -ENODEV;
  2469. }
  2470. }
  2471. rinfo->fb_base = ioremap (rinfo->fb_base_phys, rinfo->video_ram);
  2472. if (!rinfo->fb_base) {
  2473. printk ("radeonfb: cannot map FB\n");
  2474. iounmap(rinfo->mmio_base);
  2475. release_mem_region (rinfo->mmio_base_phys,
  2476. pci_resource_len(pdev, 2));
  2477. release_mem_region (rinfo->fb_base_phys,
  2478. pci_resource_len(pdev, 0));
  2479. kfree (rinfo);
  2480. return -ENODEV;
  2481. }
  2482. /* I SHOULD FIX THAT CRAP ! I should probably mimmic XFree DRI
  2483. * driver setup here.
  2484. *
  2485. * On PPC, OF based cards setup the internal memory
  2486. * mapping in strange ways. We change it so that the
  2487. * framebuffer is mapped at 0 and given half of the card's
  2488. * address space (2Gb). AGP is mapped high (0xe0000000) and
  2489. * can use up to 512Mb. Once DRI is fully implemented, we
  2490. * will have to setup the PCI remapper to remap the agp_special_page
  2491. * memory page somewhere between those regions so that the card
  2492. * use a normal PCI bus master cycle to access the ring read ptr.
  2493. * --BenH.
  2494. */
  2495. #ifdef CONFIG_ALL_PPC
  2496. if (rinfo->hasCRTC2)
  2497. OUTREG(CRTC2_GEN_CNTL,
  2498. (INREG(CRTC2_GEN_CNTL) & ~CRTC2_EN) | CRTC2_DISP_REQ_EN_B);
  2499. OUTREG(CRTC_EXT_CNTL, INREG(CRTC_EXT_CNTL) | CRTC_DISPLAY_DIS);
  2500. OUTREG(MC_FB_LOCATION, 0x7fff0000);
  2501. OUTREG(MC_AGP_LOCATION, 0xffffe000);
  2502. OUTREG(DISPLAY_BASE_ADDR, 0x00000000);
  2503. if (rinfo->hasCRTC2)
  2504. OUTREG(CRTC2_DISPLAY_BASE_ADDR, 0x00000000);
  2505. OUTREG(SRC_OFFSET, 0x00000000);
  2506. OUTREG(DST_OFFSET, 0x00000000);
  2507. mdelay(10);
  2508. OUTREG(CRTC_EXT_CNTL, INREG(CRTC_EXT_CNTL) & ~CRTC_DISPLAY_DIS);
  2509. #endif /* CONFIG_ALL_PPC */
  2510. /* save current mode regs before we switch into the new one
  2511. * so we can restore this upon __exit
  2512. */
  2513. radeon_save_state (rinfo, &rinfo->init_state);
  2514. /* set all the vital stuff */
  2515. radeon_set_fbinfo (rinfo);
  2516. pci_set_drvdata(pdev, rinfo);
  2517. rinfo->next = board_list;
  2518. board_list = rinfo;
  2519. ((struct fb_info *) rinfo)->device = &pdev->dev;
  2520. if (register_framebuffer ((struct fb_info *) rinfo) < 0) {
  2521. printk ("radeonfb: could not register framebuffer\n");
  2522. iounmap(rinfo->fb_base);
  2523. iounmap(rinfo->mmio_base);
  2524. release_mem_region (rinfo->mmio_base_phys,
  2525. pci_resource_len(pdev, 2));
  2526. release_mem_region (rinfo->fb_base_phys,
  2527. pci_resource_len(pdev, 0));
  2528. kfree (rinfo);
  2529. return -ENODEV;
  2530. }
  2531. #ifdef CONFIG_MTRR
  2532. rinfo->mtrr_hdl = nomtrr ? -1 : mtrr_add(rinfo->fb_base_phys,
  2533. rinfo->video_ram,
  2534. MTRR_TYPE_WRCOMB, 1);
  2535. #endif
  2536. #ifdef CONFIG_PMAC_BACKLIGHT
  2537. if (rinfo->dviDisp_type == MT_LCD)
  2538. register_backlight_controller(&radeon_backlight_controller,
  2539. rinfo, "ati");
  2540. #endif
  2541. #ifdef CONFIG_PMAC_PBOOK
  2542. if (rinfo->dviDisp_type == MT_LCD) {
  2543. rinfo->pm_reg = pci_find_capability(pdev, PCI_CAP_ID_PM);
  2544. pmu_register_sleep_notifier(&radeon_sleep_notifier);
  2545. }
  2546. #endif
  2547. printk ("radeonfb: ATI Radeon %s %s %d MB\n", rinfo->name, rinfo->ram_type,
  2548. (rinfo->video_ram/(1024*1024)));
  2549. if (rinfo->hasCRTC2) {
  2550. printk("radeonfb: DVI port %s monitor connected\n",
  2551. GET_MON_NAME(rinfo->dviDisp_type));
  2552. printk("radeonfb: CRT port %s monitor connected\n",
  2553. GET_MON_NAME(rinfo->crtDisp_type));
  2554. } else {
  2555. printk("radeonfb: CRT port %s monitor connected\n",
  2556. GET_MON_NAME(rinfo->crtDisp_type));
  2557. }
  2558. RTRACE("radeonfb_pci_register END\n");
  2559. return 0;
  2560. }
  2561. static void __devexit radeonfb_pci_unregister (struct pci_dev *pdev)
  2562. {
  2563. struct radeonfb_info *rinfo = pci_get_drvdata(pdev);
  2564. if (!rinfo)
  2565. return;
  2566. /* restore original state
  2567. *
  2568. * Doesn't quite work yet, possibly because of the PPC hacking
  2569. * I do on startup, disable for now. --BenH
  2570. */
  2571. radeon_write_mode (rinfo, &rinfo->init_state);
  2572. #ifdef CONFIG_MTRR
  2573. if (rinfo->mtrr_hdl >= 0)
  2574. mtrr_del(rinfo->mtrr_hdl, 0, 0);
  2575. #endif
  2576. unregister_framebuffer ((struct fb_info *) rinfo);
  2577. iounmap(rinfo->mmio_base);
  2578. iounmap(rinfo->fb_base);
  2579. release_mem_region (rinfo->mmio_base_phys,
  2580. pci_resource_len(pdev, 2));
  2581. release_mem_region (rinfo->fb_base_phys,
  2582. pci_resource_len(pdev, 0));
  2583. kfree (rinfo);
  2584. }
  2585. static struct pci_driver radeonfb_driver = {
  2586. .name = "radeonfb",
  2587. .id_table = radeonfb_pci_table,
  2588. .probe = radeonfb_pci_register,
  2589. .remove = __devexit_p(radeonfb_pci_unregister),
  2590. };
  2591. #ifndef MODULE
  2592. static int __init radeonfb_old_setup (char *options)
  2593. {
  2594. char *this_opt;
  2595. if (!options || !*options)
  2596. return 0;
  2597. while ((this_opt = strsep (&options, ",")) != NULL) {
  2598. if (!*this_opt)
  2599. continue;
  2600. if (!strncmp(this_opt, "noaccel", 7)) {
  2601. noaccel = 1;
  2602. } else if (!strncmp(this_opt, "mirror", 6)) {
  2603. mirror = 1;
  2604. } else if (!strncmp(this_opt, "dfp", 3)) {
  2605. force_dfp = 1;
  2606. } else if (!strncmp(this_opt, "panel_yres:", 11)) {
  2607. panel_yres = simple_strtoul((this_opt+11), NULL, 0);
  2608. } else if (!strncmp(this_opt, "nomtrr", 6)) {
  2609. nomtrr = 1;
  2610. } else
  2611. mode_option = this_opt;
  2612. }
  2613. return 0;
  2614. }
  2615. #endif /* MODULE */
  2616. static int __init radeonfb_old_init (void)
  2617. {
  2618. #ifndef MODULE
  2619. char *option = NULL;
  2620. if (fb_get_options("radeonfb_old", &option))
  2621. return -ENODEV;
  2622. radeonfb_old_setup(option);
  2623. #endif
  2624. return pci_register_driver (&radeonfb_driver);
  2625. }
  2626. static void __exit radeonfb_old_exit (void)
  2627. {
  2628. pci_unregister_driver (&radeonfb_driver);
  2629. }
  2630. module_init(radeonfb_old_init);
  2631. module_exit(radeonfb_old_exit);
  2632. MODULE_AUTHOR("Ani Joshi");
  2633. MODULE_DESCRIPTION("framebuffer driver for ATI Radeon chipset");
  2634. MODULE_LICENSE("GPL");