radeon_base.c 75 KB

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