radeon_base.c 76 KB

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