radeon_base.c 75 KB

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