radeon_base.c 78 KB

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