aty128fb.c 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462
  1. /* $Id: aty128fb.c,v 1.1.1.1.36.1 1999/12/11 09:03:05 Exp $
  2. * linux/drivers/video/aty128fb.c -- Frame buffer device for ATI Rage128
  3. *
  4. * Copyright (C) 1999-2003, Brad Douglas <brad@neruo.com>
  5. * Copyright (C) 1999, Anthony Tong <atong@uiuc.edu>
  6. *
  7. * Ani Joshi / Jeff Garzik
  8. * - Code cleanup
  9. *
  10. * Michel Danzer <michdaen@iiic.ethz.ch>
  11. * - 15/16 bit cleanup
  12. * - fix panning
  13. *
  14. * Benjamin Herrenschmidt
  15. * - pmac-specific PM stuff
  16. * - various fixes & cleanups
  17. *
  18. * Andreas Hundt <andi@convergence.de>
  19. * - FB_ACTIVATE fixes
  20. *
  21. * Paul Mackerras <paulus@samba.org>
  22. * - Convert to new framebuffer API,
  23. * fix colormap setting at 16 bits/pixel (565)
  24. *
  25. * Paul Mundt
  26. * - PCI hotplug
  27. *
  28. * Jon Smirl <jonsmirl@yahoo.com>
  29. * - PCI ID update
  30. * - replace ROM BIOS search
  31. *
  32. * Based off of Geert's atyfb.c and vfb.c.
  33. *
  34. * TODO:
  35. * - monitor sensing (DDC)
  36. * - virtual display
  37. * - other platform support (only ppc/x86 supported)
  38. * - hardware cursor support
  39. *
  40. * Please cc: your patches to brad@neruo.com.
  41. */
  42. /*
  43. * A special note of gratitude to ATI's devrel for providing documentation,
  44. * example code and hardware. Thanks Nitya. -atong and brad
  45. */
  46. #include <linux/config.h>
  47. #include <linux/module.h>
  48. #include <linux/moduleparam.h>
  49. #include <linux/kernel.h>
  50. #include <linux/errno.h>
  51. #include <linux/string.h>
  52. #include <linux/mm.h>
  53. #include <linux/tty.h>
  54. #include <linux/slab.h>
  55. #include <linux/vmalloc.h>
  56. #include <linux/delay.h>
  57. #include <linux/interrupt.h>
  58. #include <asm/uaccess.h>
  59. #include <linux/fb.h>
  60. #include <linux/init.h>
  61. #include <linux/pci.h>
  62. #include <linux/ioport.h>
  63. #include <linux/console.h>
  64. #include <asm/io.h>
  65. #ifdef CONFIG_PPC_PMAC
  66. #include <asm/machdep.h>
  67. #include <asm/pmac_feature.h>
  68. #include <asm/prom.h>
  69. #include <asm/pci-bridge.h>
  70. #include "../macmodes.h"
  71. #endif
  72. #ifdef CONFIG_PMAC_BACKLIGHT
  73. #include <asm/backlight.h>
  74. #endif
  75. #ifdef CONFIG_BOOTX_TEXT
  76. #include <asm/btext.h>
  77. #endif /* CONFIG_BOOTX_TEXT */
  78. #ifdef CONFIG_MTRR
  79. #include <asm/mtrr.h>
  80. #endif
  81. #include <video/aty128.h>
  82. /* Debug flag */
  83. #undef DEBUG
  84. #ifdef DEBUG
  85. #define DBG(fmt, args...) printk(KERN_DEBUG "aty128fb: %s " fmt, __FUNCTION__, ##args);
  86. #else
  87. #define DBG(fmt, args...)
  88. #endif
  89. #ifndef CONFIG_PPC_PMAC
  90. /* default mode */
  91. static struct fb_var_screeninfo default_var __initdata = {
  92. /* 640x480, 60 Hz, Non-Interlaced (25.175 MHz dotclock) */
  93. 640, 480, 640, 480, 0, 0, 8, 0,
  94. {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
  95. 0, 0, -1, -1, 0, 39722, 48, 16, 33, 10, 96, 2,
  96. 0, FB_VMODE_NONINTERLACED
  97. };
  98. #else /* CONFIG_PPC_PMAC */
  99. /* default to 1024x768 at 75Hz on PPC - this will work
  100. * on the iMac, the usual 640x480 @ 60Hz doesn't. */
  101. static struct fb_var_screeninfo default_var = {
  102. /* 1024x768, 75 Hz, Non-Interlaced (78.75 MHz dotclock) */
  103. 1024, 768, 1024, 768, 0, 0, 8, 0,
  104. {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
  105. 0, 0, -1, -1, 0, 12699, 160, 32, 28, 1, 96, 3,
  106. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  107. FB_VMODE_NONINTERLACED
  108. };
  109. #endif /* CONFIG_PPC_PMAC */
  110. /* default modedb mode */
  111. /* 640x480, 60 Hz, Non-Interlaced (25.172 MHz dotclock) */
  112. static struct fb_videomode defaultmode __initdata = {
  113. .refresh = 60,
  114. .xres = 640,
  115. .yres = 480,
  116. .pixclock = 39722,
  117. .left_margin = 48,
  118. .right_margin = 16,
  119. .upper_margin = 33,
  120. .lower_margin = 10,
  121. .hsync_len = 96,
  122. .vsync_len = 2,
  123. .sync = 0,
  124. .vmode = FB_VMODE_NONINTERLACED
  125. };
  126. /* Chip generations */
  127. enum {
  128. rage_128,
  129. rage_128_pci,
  130. rage_128_pro,
  131. rage_128_pro_pci,
  132. rage_M3,
  133. rage_M3_pci,
  134. rage_M4,
  135. rage_128_ultra,
  136. };
  137. /* Must match above enum */
  138. static const char *r128_family[] __devinitdata = {
  139. "AGP",
  140. "PCI",
  141. "PRO AGP",
  142. "PRO PCI",
  143. "M3 AGP",
  144. "M3 PCI",
  145. "M4 AGP",
  146. "Ultra AGP",
  147. };
  148. /*
  149. * PCI driver prototypes
  150. */
  151. static int aty128_probe(struct pci_dev *pdev,
  152. const struct pci_device_id *ent);
  153. static void aty128_remove(struct pci_dev *pdev);
  154. static int aty128_pci_suspend(struct pci_dev *pdev, pm_message_t state);
  155. static int aty128_pci_resume(struct pci_dev *pdev);
  156. static int aty128_do_resume(struct pci_dev *pdev);
  157. /* supported Rage128 chipsets */
  158. static struct pci_device_id aty128_pci_tbl[] = {
  159. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_LE,
  160. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_M3_pci },
  161. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_LF,
  162. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_M3 },
  163. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_MF,
  164. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_M4 },
  165. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_ML,
  166. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_M4 },
  167. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_PA,
  168. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128_pro },
  169. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_PB,
  170. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128_pro },
  171. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_PC,
  172. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128_pro },
  173. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_PD,
  174. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128_pro_pci },
  175. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_PE,
  176. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128_pro },
  177. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_PF,
  178. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128_pro },
  179. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_PG,
  180. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128_pro },
  181. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_PH,
  182. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128_pro },
  183. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_PI,
  184. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128_pro },
  185. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_PJ,
  186. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128_pro },
  187. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_PK,
  188. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128_pro },
  189. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_PL,
  190. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128_pro },
  191. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_PM,
  192. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128_pro },
  193. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_PN,
  194. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128_pro },
  195. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_PO,
  196. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128_pro },
  197. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_PP,
  198. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128_pro_pci },
  199. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_PQ,
  200. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128_pro },
  201. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_PR,
  202. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128_pro_pci },
  203. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_PS,
  204. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128_pro },
  205. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_PT,
  206. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128_pro },
  207. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_PU,
  208. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128_pro },
  209. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_PV,
  210. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128_pro },
  211. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_PW,
  212. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128_pro },
  213. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_PX,
  214. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128_pro },
  215. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_RE,
  216. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128_pci },
  217. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_RF,
  218. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128 },
  219. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_RG,
  220. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128 },
  221. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_RK,
  222. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128_pci },
  223. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_RL,
  224. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128 },
  225. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_SE,
  226. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128 },
  227. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_SF,
  228. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128_pci },
  229. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_SG,
  230. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128 },
  231. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_SH,
  232. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128 },
  233. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_SK,
  234. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128 },
  235. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_SL,
  236. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128 },
  237. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_SM,
  238. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128 },
  239. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_SN,
  240. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128 },
  241. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_TF,
  242. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128_ultra },
  243. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_TL,
  244. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128_ultra },
  245. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_TR,
  246. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128_ultra },
  247. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_TS,
  248. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128_ultra },
  249. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_TT,
  250. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128_ultra },
  251. { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_TU,
  252. PCI_ANY_ID, PCI_ANY_ID, 0, 0, rage_128_ultra },
  253. { 0, }
  254. };
  255. MODULE_DEVICE_TABLE(pci, aty128_pci_tbl);
  256. static struct pci_driver aty128fb_driver = {
  257. .name = "aty128fb",
  258. .id_table = aty128_pci_tbl,
  259. .probe = aty128_probe,
  260. .remove = __devexit_p(aty128_remove),
  261. .suspend = aty128_pci_suspend,
  262. .resume = aty128_pci_resume,
  263. };
  264. /* packed BIOS settings */
  265. #ifndef CONFIG_PPC
  266. typedef struct {
  267. u8 clock_chip_type;
  268. u8 struct_size;
  269. u8 accelerator_entry;
  270. u8 VGA_entry;
  271. u16 VGA_table_offset;
  272. u16 POST_table_offset;
  273. u16 XCLK;
  274. u16 MCLK;
  275. u8 num_PLL_blocks;
  276. u8 size_PLL_blocks;
  277. u16 PCLK_ref_freq;
  278. u16 PCLK_ref_divider;
  279. u32 PCLK_min_freq;
  280. u32 PCLK_max_freq;
  281. u16 MCLK_ref_freq;
  282. u16 MCLK_ref_divider;
  283. u32 MCLK_min_freq;
  284. u32 MCLK_max_freq;
  285. u16 XCLK_ref_freq;
  286. u16 XCLK_ref_divider;
  287. u32 XCLK_min_freq;
  288. u32 XCLK_max_freq;
  289. } __attribute__ ((packed)) PLL_BLOCK;
  290. #endif /* !CONFIG_PPC */
  291. /* onboard memory information */
  292. struct aty128_meminfo {
  293. u8 ML;
  294. u8 MB;
  295. u8 Trcd;
  296. u8 Trp;
  297. u8 Twr;
  298. u8 CL;
  299. u8 Tr2w;
  300. u8 LoopLatency;
  301. u8 DspOn;
  302. u8 Rloop;
  303. const char *name;
  304. };
  305. /* various memory configurations */
  306. static const struct aty128_meminfo sdr_128 =
  307. { 4, 4, 3, 3, 1, 3, 1, 16, 30, 16, "128-bit SDR SGRAM (1:1)" };
  308. static const struct aty128_meminfo sdr_64 =
  309. { 4, 8, 3, 3, 1, 3, 1, 17, 46, 17, "64-bit SDR SGRAM (1:1)" };
  310. static const struct aty128_meminfo sdr_sgram =
  311. { 4, 4, 1, 2, 1, 2, 1, 16, 24, 16, "64-bit SDR SGRAM (2:1)" };
  312. static const struct aty128_meminfo ddr_sgram =
  313. { 4, 4, 3, 3, 2, 3, 1, 16, 31, 16, "64-bit DDR SGRAM" };
  314. static struct fb_fix_screeninfo aty128fb_fix __initdata = {
  315. .id = "ATY Rage128",
  316. .type = FB_TYPE_PACKED_PIXELS,
  317. .visual = FB_VISUAL_PSEUDOCOLOR,
  318. .xpanstep = 8,
  319. .ypanstep = 1,
  320. .mmio_len = 0x2000,
  321. .accel = FB_ACCEL_ATI_RAGE128,
  322. };
  323. static char *mode_option __initdata = NULL;
  324. #ifdef CONFIG_PPC_PMAC
  325. static int default_vmode __initdata = VMODE_1024_768_60;
  326. static int default_cmode __initdata = CMODE_8;
  327. #endif
  328. static int default_crt_on __initdata = 0;
  329. static int default_lcd_on __initdata = 1;
  330. #ifdef CONFIG_MTRR
  331. static int mtrr = 1;
  332. #endif
  333. /* PLL constants */
  334. struct aty128_constants {
  335. u32 ref_clk;
  336. u32 ppll_min;
  337. u32 ppll_max;
  338. u32 ref_divider;
  339. u32 xclk;
  340. u32 fifo_width;
  341. u32 fifo_depth;
  342. };
  343. struct aty128_crtc {
  344. u32 gen_cntl;
  345. u32 h_total, h_sync_strt_wid;
  346. u32 v_total, v_sync_strt_wid;
  347. u32 pitch;
  348. u32 offset, offset_cntl;
  349. u32 xoffset, yoffset;
  350. u32 vxres, vyres;
  351. u32 depth, bpp;
  352. };
  353. struct aty128_pll {
  354. u32 post_divider;
  355. u32 feedback_divider;
  356. u32 vclk;
  357. };
  358. struct aty128_ddafifo {
  359. u32 dda_config;
  360. u32 dda_on_off;
  361. };
  362. /* register values for a specific mode */
  363. struct aty128fb_par {
  364. struct aty128_crtc crtc;
  365. struct aty128_pll pll;
  366. struct aty128_ddafifo fifo_reg;
  367. u32 accel_flags;
  368. struct aty128_constants constants; /* PLL and others */
  369. void __iomem *regbase; /* remapped mmio */
  370. u32 vram_size; /* onboard video ram */
  371. int chip_gen;
  372. const struct aty128_meminfo *mem; /* onboard mem info */
  373. #ifdef CONFIG_MTRR
  374. struct { int vram; int vram_valid; } mtrr;
  375. #endif
  376. int blitter_may_be_busy;
  377. int fifo_slots; /* free slots in FIFO (64 max) */
  378. int pm_reg;
  379. int crt_on, lcd_on;
  380. struct pci_dev *pdev;
  381. struct fb_info *next;
  382. int asleep;
  383. int lock_blank;
  384. u8 red[32]; /* see aty128fb_setcolreg */
  385. u8 green[64];
  386. u8 blue[32];
  387. u32 pseudo_palette[16]; /* used for TRUECOLOR */
  388. };
  389. #define round_div(n, d) ((n+(d/2))/d)
  390. static int aty128fb_check_var(struct fb_var_screeninfo *var,
  391. struct fb_info *info);
  392. static int aty128fb_set_par(struct fb_info *info);
  393. static int aty128fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  394. u_int transp, struct fb_info *info);
  395. static int aty128fb_pan_display(struct fb_var_screeninfo *var,
  396. struct fb_info *fb);
  397. static int aty128fb_blank(int blank, struct fb_info *fb);
  398. static int aty128fb_ioctl(struct fb_info *info, u_int cmd, unsigned long arg);
  399. static int aty128fb_sync(struct fb_info *info);
  400. /*
  401. * Internal routines
  402. */
  403. static int aty128_encode_var(struct fb_var_screeninfo *var,
  404. const struct aty128fb_par *par);
  405. static int aty128_decode_var(struct fb_var_screeninfo *var,
  406. struct aty128fb_par *par);
  407. #if 0
  408. static void __init aty128_get_pllinfo(struct aty128fb_par *par,
  409. void __iomem *bios);
  410. static void __init __iomem *aty128_map_ROM(struct pci_dev *pdev, const struct aty128fb_par *par);
  411. #endif
  412. static void aty128_timings(struct aty128fb_par *par);
  413. static void aty128_init_engine(struct aty128fb_par *par);
  414. static void aty128_reset_engine(const struct aty128fb_par *par);
  415. static void aty128_flush_pixel_cache(const struct aty128fb_par *par);
  416. static void do_wait_for_fifo(u16 entries, struct aty128fb_par *par);
  417. static void wait_for_fifo(u16 entries, struct aty128fb_par *par);
  418. static void wait_for_idle(struct aty128fb_par *par);
  419. static u32 depth_to_dst(u32 depth);
  420. #define BIOS_IN8(v) (readb(bios + (v)))
  421. #define BIOS_IN16(v) (readb(bios + (v)) | \
  422. (readb(bios + (v) + 1) << 8))
  423. #define BIOS_IN32(v) (readb(bios + (v)) | \
  424. (readb(bios + (v) + 1) << 8) | \
  425. (readb(bios + (v) + 2) << 16) | \
  426. (readb(bios + (v) + 3) << 24))
  427. static struct fb_ops aty128fb_ops = {
  428. .owner = THIS_MODULE,
  429. .fb_check_var = aty128fb_check_var,
  430. .fb_set_par = aty128fb_set_par,
  431. .fb_setcolreg = aty128fb_setcolreg,
  432. .fb_pan_display = aty128fb_pan_display,
  433. .fb_blank = aty128fb_blank,
  434. .fb_ioctl = aty128fb_ioctl,
  435. .fb_sync = aty128fb_sync,
  436. .fb_fillrect = cfb_fillrect,
  437. .fb_copyarea = cfb_copyarea,
  438. .fb_imageblit = cfb_imageblit,
  439. };
  440. #ifdef CONFIG_PMAC_BACKLIGHT
  441. static int aty128_set_backlight_enable(int on, int level, void* data);
  442. static int aty128_set_backlight_level(int level, void* data);
  443. static struct backlight_controller aty128_backlight_controller = {
  444. aty128_set_backlight_enable,
  445. aty128_set_backlight_level
  446. };
  447. #endif /* CONFIG_PMAC_BACKLIGHT */
  448. /*
  449. * Functions to read from/write to the mmio registers
  450. * - endian conversions may possibly be avoided by
  451. * using the other register aperture. TODO.
  452. */
  453. static inline u32 _aty_ld_le32(volatile unsigned int regindex,
  454. const struct aty128fb_par *par)
  455. {
  456. return readl (par->regbase + regindex);
  457. }
  458. static inline void _aty_st_le32(volatile unsigned int regindex, u32 val,
  459. const struct aty128fb_par *par)
  460. {
  461. writel (val, par->regbase + regindex);
  462. }
  463. static inline u8 _aty_ld_8(unsigned int regindex,
  464. const struct aty128fb_par *par)
  465. {
  466. return readb (par->regbase + regindex);
  467. }
  468. static inline void _aty_st_8(unsigned int regindex, u8 val,
  469. const struct aty128fb_par *par)
  470. {
  471. writeb (val, par->regbase + regindex);
  472. }
  473. #define aty_ld_le32(regindex) _aty_ld_le32(regindex, par)
  474. #define aty_st_le32(regindex, val) _aty_st_le32(regindex, val, par)
  475. #define aty_ld_8(regindex) _aty_ld_8(regindex, par)
  476. #define aty_st_8(regindex, val) _aty_st_8(regindex, val, par)
  477. /*
  478. * Functions to read from/write to the pll registers
  479. */
  480. #define aty_ld_pll(pll_index) _aty_ld_pll(pll_index, par)
  481. #define aty_st_pll(pll_index, val) _aty_st_pll(pll_index, val, par)
  482. static u32 _aty_ld_pll(unsigned int pll_index,
  483. const struct aty128fb_par *par)
  484. {
  485. aty_st_8(CLOCK_CNTL_INDEX, pll_index & 0x3F);
  486. return aty_ld_le32(CLOCK_CNTL_DATA);
  487. }
  488. static void _aty_st_pll(unsigned int pll_index, u32 val,
  489. const struct aty128fb_par *par)
  490. {
  491. aty_st_8(CLOCK_CNTL_INDEX, (pll_index & 0x3F) | PLL_WR_EN);
  492. aty_st_le32(CLOCK_CNTL_DATA, val);
  493. }
  494. /* return true when the PLL has completed an atomic update */
  495. static int aty_pll_readupdate(const struct aty128fb_par *par)
  496. {
  497. return !(aty_ld_pll(PPLL_REF_DIV) & PPLL_ATOMIC_UPDATE_R);
  498. }
  499. static void aty_pll_wait_readupdate(const struct aty128fb_par *par)
  500. {
  501. unsigned long timeout = jiffies + HZ/100; // should be more than enough
  502. int reset = 1;
  503. while (time_before(jiffies, timeout))
  504. if (aty_pll_readupdate(par)) {
  505. reset = 0;
  506. break;
  507. }
  508. if (reset) /* reset engine?? */
  509. printk(KERN_DEBUG "aty128fb: PLL write timeout!\n");
  510. }
  511. /* tell PLL to update */
  512. static void aty_pll_writeupdate(const struct aty128fb_par *par)
  513. {
  514. aty_pll_wait_readupdate(par);
  515. aty_st_pll(PPLL_REF_DIV,
  516. aty_ld_pll(PPLL_REF_DIV) | PPLL_ATOMIC_UPDATE_W);
  517. }
  518. /* write to the scratch register to test r/w functionality */
  519. static int __init register_test(const struct aty128fb_par *par)
  520. {
  521. u32 val;
  522. int flag = 0;
  523. val = aty_ld_le32(BIOS_0_SCRATCH);
  524. aty_st_le32(BIOS_0_SCRATCH, 0x55555555);
  525. if (aty_ld_le32(BIOS_0_SCRATCH) == 0x55555555) {
  526. aty_st_le32(BIOS_0_SCRATCH, 0xAAAAAAAA);
  527. if (aty_ld_le32(BIOS_0_SCRATCH) == 0xAAAAAAAA)
  528. flag = 1;
  529. }
  530. aty_st_le32(BIOS_0_SCRATCH, val); // restore value
  531. return flag;
  532. }
  533. /*
  534. * Accelerator engine functions
  535. */
  536. static void do_wait_for_fifo(u16 entries, struct aty128fb_par *par)
  537. {
  538. int i;
  539. for (;;) {
  540. for (i = 0; i < 2000000; i++) {
  541. par->fifo_slots = aty_ld_le32(GUI_STAT) & 0x0fff;
  542. if (par->fifo_slots >= entries)
  543. return;
  544. }
  545. aty128_reset_engine(par);
  546. }
  547. }
  548. static void wait_for_idle(struct aty128fb_par *par)
  549. {
  550. int i;
  551. do_wait_for_fifo(64, par);
  552. for (;;) {
  553. for (i = 0; i < 2000000; i++) {
  554. if (!(aty_ld_le32(GUI_STAT) & (1 << 31))) {
  555. aty128_flush_pixel_cache(par);
  556. par->blitter_may_be_busy = 0;
  557. return;
  558. }
  559. }
  560. aty128_reset_engine(par);
  561. }
  562. }
  563. static void wait_for_fifo(u16 entries, struct aty128fb_par *par)
  564. {
  565. if (par->fifo_slots < entries)
  566. do_wait_for_fifo(64, par);
  567. par->fifo_slots -= entries;
  568. }
  569. static void aty128_flush_pixel_cache(const struct aty128fb_par *par)
  570. {
  571. int i;
  572. u32 tmp;
  573. tmp = aty_ld_le32(PC_NGUI_CTLSTAT);
  574. tmp &= ~(0x00ff);
  575. tmp |= 0x00ff;
  576. aty_st_le32(PC_NGUI_CTLSTAT, tmp);
  577. for (i = 0; i < 2000000; i++)
  578. if (!(aty_ld_le32(PC_NGUI_CTLSTAT) & PC_BUSY))
  579. break;
  580. }
  581. static void aty128_reset_engine(const struct aty128fb_par *par)
  582. {
  583. u32 gen_reset_cntl, clock_cntl_index, mclk_cntl;
  584. aty128_flush_pixel_cache(par);
  585. clock_cntl_index = aty_ld_le32(CLOCK_CNTL_INDEX);
  586. mclk_cntl = aty_ld_pll(MCLK_CNTL);
  587. aty_st_pll(MCLK_CNTL, mclk_cntl | 0x00030000);
  588. gen_reset_cntl = aty_ld_le32(GEN_RESET_CNTL);
  589. aty_st_le32(GEN_RESET_CNTL, gen_reset_cntl | SOFT_RESET_GUI);
  590. aty_ld_le32(GEN_RESET_CNTL);
  591. aty_st_le32(GEN_RESET_CNTL, gen_reset_cntl & ~(SOFT_RESET_GUI));
  592. aty_ld_le32(GEN_RESET_CNTL);
  593. aty_st_pll(MCLK_CNTL, mclk_cntl);
  594. aty_st_le32(CLOCK_CNTL_INDEX, clock_cntl_index);
  595. aty_st_le32(GEN_RESET_CNTL, gen_reset_cntl);
  596. /* use old pio mode */
  597. aty_st_le32(PM4_BUFFER_CNTL, PM4_BUFFER_CNTL_NONPM4);
  598. DBG("engine reset");
  599. }
  600. static void aty128_init_engine(struct aty128fb_par *par)
  601. {
  602. u32 pitch_value;
  603. wait_for_idle(par);
  604. /* 3D scaler not spoken here */
  605. wait_for_fifo(1, par);
  606. aty_st_le32(SCALE_3D_CNTL, 0x00000000);
  607. aty128_reset_engine(par);
  608. pitch_value = par->crtc.pitch;
  609. if (par->crtc.bpp == 24) {
  610. pitch_value = pitch_value * 3;
  611. }
  612. wait_for_fifo(4, par);
  613. /* setup engine offset registers */
  614. aty_st_le32(DEFAULT_OFFSET, 0x00000000);
  615. /* setup engine pitch registers */
  616. aty_st_le32(DEFAULT_PITCH, pitch_value);
  617. /* set the default scissor register to max dimensions */
  618. aty_st_le32(DEFAULT_SC_BOTTOM_RIGHT, (0x1FFF << 16) | 0x1FFF);
  619. /* set the drawing controls registers */
  620. aty_st_le32(DP_GUI_MASTER_CNTL,
  621. GMC_SRC_PITCH_OFFSET_DEFAULT |
  622. GMC_DST_PITCH_OFFSET_DEFAULT |
  623. GMC_SRC_CLIP_DEFAULT |
  624. GMC_DST_CLIP_DEFAULT |
  625. GMC_BRUSH_SOLIDCOLOR |
  626. (depth_to_dst(par->crtc.depth) << 8) |
  627. GMC_SRC_DSTCOLOR |
  628. GMC_BYTE_ORDER_MSB_TO_LSB |
  629. GMC_DP_CONVERSION_TEMP_6500 |
  630. ROP3_PATCOPY |
  631. GMC_DP_SRC_RECT |
  632. GMC_3D_FCN_EN_CLR |
  633. GMC_DST_CLR_CMP_FCN_CLEAR |
  634. GMC_AUX_CLIP_CLEAR |
  635. GMC_WRITE_MASK_SET);
  636. wait_for_fifo(8, par);
  637. /* clear the line drawing registers */
  638. aty_st_le32(DST_BRES_ERR, 0);
  639. aty_st_le32(DST_BRES_INC, 0);
  640. aty_st_le32(DST_BRES_DEC, 0);
  641. /* set brush color registers */
  642. aty_st_le32(DP_BRUSH_FRGD_CLR, 0xFFFFFFFF); /* white */
  643. aty_st_le32(DP_BRUSH_BKGD_CLR, 0x00000000); /* black */
  644. /* set source color registers */
  645. aty_st_le32(DP_SRC_FRGD_CLR, 0xFFFFFFFF); /* white */
  646. aty_st_le32(DP_SRC_BKGD_CLR, 0x00000000); /* black */
  647. /* default write mask */
  648. aty_st_le32(DP_WRITE_MASK, 0xFFFFFFFF);
  649. /* Wait for all the writes to be completed before returning */
  650. wait_for_idle(par);
  651. }
  652. /* convert depth values to their register representation */
  653. static u32 depth_to_dst(u32 depth)
  654. {
  655. if (depth <= 8)
  656. return DST_8BPP;
  657. else if (depth <= 15)
  658. return DST_15BPP;
  659. else if (depth == 16)
  660. return DST_16BPP;
  661. else if (depth <= 24)
  662. return DST_24BPP;
  663. else if (depth <= 32)
  664. return DST_32BPP;
  665. return -EINVAL;
  666. }
  667. /*
  668. * PLL informations retreival
  669. */
  670. #ifndef __sparc__
  671. static void __iomem * __init aty128_map_ROM(const struct aty128fb_par *par, struct pci_dev *dev)
  672. {
  673. u16 dptr;
  674. u8 rom_type;
  675. void __iomem *bios;
  676. size_t rom_size;
  677. /* Fix from ATI for problem with Rage128 hardware not leaving ROM enabled */
  678. unsigned int temp;
  679. temp = aty_ld_le32(RAGE128_MPP_TB_CONFIG);
  680. temp &= 0x00ffffffu;
  681. temp |= 0x04 << 24;
  682. aty_st_le32(RAGE128_MPP_TB_CONFIG, temp);
  683. temp = aty_ld_le32(RAGE128_MPP_TB_CONFIG);
  684. bios = pci_map_rom(dev, &rom_size);
  685. if (!bios) {
  686. printk(KERN_ERR "aty128fb: ROM failed to map\n");
  687. return NULL;
  688. }
  689. /* Very simple test to make sure it appeared */
  690. if (BIOS_IN16(0) != 0xaa55) {
  691. printk(KERN_DEBUG "aty128fb: Invalid ROM signature %x should "
  692. " be 0xaa55\n", BIOS_IN16(0));
  693. goto failed;
  694. }
  695. /* Look for the PCI data to check the ROM type */
  696. dptr = BIOS_IN16(0x18);
  697. /* Check the PCI data signature. If it's wrong, we still assume a normal x86 ROM
  698. * for now, until I've verified this works everywhere. The goal here is more
  699. * to phase out Open Firmware images.
  700. *
  701. * Currently, we only look at the first PCI data, we could iteratre and deal with
  702. * them all, and we should use fb_bios_start relative to start of image and not
  703. * relative start of ROM, but so far, I never found a dual-image ATI card
  704. *
  705. * typedef struct {
  706. * u32 signature; + 0x00
  707. * u16 vendor; + 0x04
  708. * u16 device; + 0x06
  709. * u16 reserved_1; + 0x08
  710. * u16 dlen; + 0x0a
  711. * u8 drevision; + 0x0c
  712. * u8 class_hi; + 0x0d
  713. * u16 class_lo; + 0x0e
  714. * u16 ilen; + 0x10
  715. * u16 irevision; + 0x12
  716. * u8 type; + 0x14
  717. * u8 indicator; + 0x15
  718. * u16 reserved_2; + 0x16
  719. * } pci_data_t;
  720. */
  721. if (BIOS_IN32(dptr) != (('R' << 24) | ('I' << 16) | ('C' << 8) | 'P')) {
  722. printk(KERN_WARNING "aty128fb: PCI DATA signature in ROM incorrect: %08x\n",
  723. BIOS_IN32(dptr));
  724. goto anyway;
  725. }
  726. rom_type = BIOS_IN8(dptr + 0x14);
  727. switch(rom_type) {
  728. case 0:
  729. printk(KERN_INFO "aty128fb: Found Intel x86 BIOS ROM Image\n");
  730. break;
  731. case 1:
  732. printk(KERN_INFO "aty128fb: Found Open Firmware ROM Image\n");
  733. goto failed;
  734. case 2:
  735. printk(KERN_INFO "aty128fb: Found HP PA-RISC ROM Image\n");
  736. goto failed;
  737. default:
  738. printk(KERN_INFO "aty128fb: Found unknown type %d ROM Image\n", rom_type);
  739. goto failed;
  740. }
  741. anyway:
  742. return bios;
  743. failed:
  744. pci_unmap_rom(dev, bios);
  745. return NULL;
  746. }
  747. static void __init aty128_get_pllinfo(struct aty128fb_par *par, unsigned char __iomem *bios)
  748. {
  749. unsigned int bios_hdr;
  750. unsigned int bios_pll;
  751. bios_hdr = BIOS_IN16(0x48);
  752. bios_pll = BIOS_IN16(bios_hdr + 0x30);
  753. par->constants.ppll_max = BIOS_IN32(bios_pll + 0x16);
  754. par->constants.ppll_min = BIOS_IN32(bios_pll + 0x12);
  755. par->constants.xclk = BIOS_IN16(bios_pll + 0x08);
  756. par->constants.ref_divider = BIOS_IN16(bios_pll + 0x10);
  757. par->constants.ref_clk = BIOS_IN16(bios_pll + 0x0e);
  758. DBG("ppll_max %d ppll_min %d xclk %d ref_divider %d ref clock %d\n",
  759. par->constants.ppll_max, par->constants.ppll_min,
  760. par->constants.xclk, par->constants.ref_divider,
  761. par->constants.ref_clk);
  762. }
  763. #ifdef CONFIG_X86
  764. static void __iomem * __devinit aty128_find_mem_vbios(struct aty128fb_par *par)
  765. {
  766. /* I simplified this code as we used to miss the signatures in
  767. * a lot of case. It's now closer to XFree, we just don't check
  768. * for signatures at all... Something better will have to be done
  769. * if we end up having conflicts
  770. */
  771. u32 segstart;
  772. unsigned char __iomem *rom_base = NULL;
  773. for (segstart=0x000c0000; segstart<0x000f0000; segstart+=0x00001000) {
  774. rom_base = ioremap(segstart, 0x10000);
  775. if (rom_base == NULL)
  776. return NULL;
  777. if (readb(rom_base) == 0x55 && readb(rom_base + 1) == 0xaa)
  778. break;
  779. iounmap(rom_base);
  780. rom_base = NULL;
  781. }
  782. return rom_base;
  783. }
  784. #endif
  785. #endif /* ndef(__sparc__) */
  786. /* fill in known card constants if pll_block is not available */
  787. static void __init aty128_timings(struct aty128fb_par *par)
  788. {
  789. #ifdef CONFIG_PPC_OF
  790. /* instead of a table lookup, assume OF has properly
  791. * setup the PLL registers and use their values
  792. * to set the XCLK values and reference divider values */
  793. u32 x_mpll_ref_fb_div;
  794. u32 xclk_cntl;
  795. u32 Nx, M;
  796. unsigned PostDivSet[] = { 0, 1, 2, 4, 8, 3, 6, 12 };
  797. #endif
  798. if (!par->constants.ref_clk)
  799. par->constants.ref_clk = 2950;
  800. #ifdef CONFIG_PPC_OF
  801. x_mpll_ref_fb_div = aty_ld_pll(X_MPLL_REF_FB_DIV);
  802. xclk_cntl = aty_ld_pll(XCLK_CNTL) & 0x7;
  803. Nx = (x_mpll_ref_fb_div & 0x00ff00) >> 8;
  804. M = x_mpll_ref_fb_div & 0x0000ff;
  805. par->constants.xclk = round_div((2 * Nx * par->constants.ref_clk),
  806. (M * PostDivSet[xclk_cntl]));
  807. par->constants.ref_divider =
  808. aty_ld_pll(PPLL_REF_DIV) & PPLL_REF_DIV_MASK;
  809. #endif
  810. if (!par->constants.ref_divider) {
  811. par->constants.ref_divider = 0x3b;
  812. aty_st_pll(X_MPLL_REF_FB_DIV, 0x004c4c1e);
  813. aty_pll_writeupdate(par);
  814. }
  815. aty_st_pll(PPLL_REF_DIV, par->constants.ref_divider);
  816. aty_pll_writeupdate(par);
  817. /* from documentation */
  818. if (!par->constants.ppll_min)
  819. par->constants.ppll_min = 12500;
  820. if (!par->constants.ppll_max)
  821. par->constants.ppll_max = 25000; /* 23000 on some cards? */
  822. if (!par->constants.xclk)
  823. par->constants.xclk = 0x1d4d; /* same as mclk */
  824. par->constants.fifo_width = 128;
  825. par->constants.fifo_depth = 32;
  826. switch (aty_ld_le32(MEM_CNTL) & 0x3) {
  827. case 0:
  828. par->mem = &sdr_128;
  829. break;
  830. case 1:
  831. par->mem = &sdr_sgram;
  832. break;
  833. case 2:
  834. par->mem = &ddr_sgram;
  835. break;
  836. default:
  837. par->mem = &sdr_sgram;
  838. }
  839. }
  840. /*
  841. * CRTC programming
  842. */
  843. /* Program the CRTC registers */
  844. static void aty128_set_crtc(const struct aty128_crtc *crtc,
  845. const struct aty128fb_par *par)
  846. {
  847. aty_st_le32(CRTC_GEN_CNTL, crtc->gen_cntl);
  848. aty_st_le32(CRTC_H_TOTAL_DISP, crtc->h_total);
  849. aty_st_le32(CRTC_H_SYNC_STRT_WID, crtc->h_sync_strt_wid);
  850. aty_st_le32(CRTC_V_TOTAL_DISP, crtc->v_total);
  851. aty_st_le32(CRTC_V_SYNC_STRT_WID, crtc->v_sync_strt_wid);
  852. aty_st_le32(CRTC_PITCH, crtc->pitch);
  853. aty_st_le32(CRTC_OFFSET, crtc->offset);
  854. aty_st_le32(CRTC_OFFSET_CNTL, crtc->offset_cntl);
  855. /* Disable ATOMIC updating. Is this the right place? */
  856. aty_st_pll(PPLL_CNTL, aty_ld_pll(PPLL_CNTL) & ~(0x00030000));
  857. }
  858. static int aty128_var_to_crtc(const struct fb_var_screeninfo *var,
  859. struct aty128_crtc *crtc,
  860. const struct aty128fb_par *par)
  861. {
  862. u32 xres, yres, vxres, vyres, xoffset, yoffset, bpp, dst;
  863. u32 left, right, upper, lower, hslen, vslen, sync, vmode;
  864. u32 h_total, h_disp, h_sync_strt, h_sync_wid, h_sync_pol;
  865. u32 v_total, v_disp, v_sync_strt, v_sync_wid, v_sync_pol, c_sync;
  866. u32 depth, bytpp;
  867. u8 mode_bytpp[7] = { 0, 0, 1, 2, 2, 3, 4 };
  868. /* input */
  869. xres = var->xres;
  870. yres = var->yres;
  871. vxres = var->xres_virtual;
  872. vyres = var->yres_virtual;
  873. xoffset = var->xoffset;
  874. yoffset = var->yoffset;
  875. bpp = var->bits_per_pixel;
  876. left = var->left_margin;
  877. right = var->right_margin;
  878. upper = var->upper_margin;
  879. lower = var->lower_margin;
  880. hslen = var->hsync_len;
  881. vslen = var->vsync_len;
  882. sync = var->sync;
  883. vmode = var->vmode;
  884. if (bpp != 16)
  885. depth = bpp;
  886. else
  887. depth = (var->green.length == 6) ? 16 : 15;
  888. /* check for mode eligibility
  889. * accept only non interlaced modes */
  890. if ((vmode & FB_VMODE_MASK) != FB_VMODE_NONINTERLACED)
  891. return -EINVAL;
  892. /* convert (and round up) and validate */
  893. xres = (xres + 7) & ~7;
  894. xoffset = (xoffset + 7) & ~7;
  895. if (vxres < xres + xoffset)
  896. vxres = xres + xoffset;
  897. if (vyres < yres + yoffset)
  898. vyres = yres + yoffset;
  899. /* convert depth into ATI register depth */
  900. dst = depth_to_dst(depth);
  901. if (dst == -EINVAL) {
  902. printk(KERN_ERR "aty128fb: Invalid depth or RGBA\n");
  903. return -EINVAL;
  904. }
  905. /* convert register depth to bytes per pixel */
  906. bytpp = mode_bytpp[dst];
  907. /* make sure there is enough video ram for the mode */
  908. if ((u32)(vxres * vyres * bytpp) > par->vram_size) {
  909. printk(KERN_ERR "aty128fb: Not enough memory for mode\n");
  910. return -EINVAL;
  911. }
  912. h_disp = (xres >> 3) - 1;
  913. h_total = (((xres + right + hslen + left) >> 3) - 1) & 0xFFFFL;
  914. v_disp = yres - 1;
  915. v_total = (yres + upper + vslen + lower - 1) & 0xFFFFL;
  916. /* check to make sure h_total and v_total are in range */
  917. if (((h_total >> 3) - 1) > 0x1ff || (v_total - 1) > 0x7FF) {
  918. printk(KERN_ERR "aty128fb: invalid width ranges\n");
  919. return -EINVAL;
  920. }
  921. h_sync_wid = (hslen + 7) >> 3;
  922. if (h_sync_wid == 0)
  923. h_sync_wid = 1;
  924. else if (h_sync_wid > 0x3f) /* 0x3f = max hwidth */
  925. h_sync_wid = 0x3f;
  926. h_sync_strt = (h_disp << 3) + right;
  927. v_sync_wid = vslen;
  928. if (v_sync_wid == 0)
  929. v_sync_wid = 1;
  930. else if (v_sync_wid > 0x1f) /* 0x1f = max vwidth */
  931. v_sync_wid = 0x1f;
  932. v_sync_strt = v_disp + lower;
  933. h_sync_pol = sync & FB_SYNC_HOR_HIGH_ACT ? 0 : 1;
  934. v_sync_pol = sync & FB_SYNC_VERT_HIGH_ACT ? 0 : 1;
  935. c_sync = sync & FB_SYNC_COMP_HIGH_ACT ? (1 << 4) : 0;
  936. crtc->gen_cntl = 0x3000000L | c_sync | (dst << 8);
  937. crtc->h_total = h_total | (h_disp << 16);
  938. crtc->v_total = v_total | (v_disp << 16);
  939. crtc->h_sync_strt_wid = h_sync_strt | (h_sync_wid << 16) |
  940. (h_sync_pol << 23);
  941. crtc->v_sync_strt_wid = v_sync_strt | (v_sync_wid << 16) |
  942. (v_sync_pol << 23);
  943. crtc->pitch = vxres >> 3;
  944. crtc->offset = 0;
  945. if ((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW)
  946. crtc->offset_cntl = 0x00010000;
  947. else
  948. crtc->offset_cntl = 0;
  949. crtc->vxres = vxres;
  950. crtc->vyres = vyres;
  951. crtc->xoffset = xoffset;
  952. crtc->yoffset = yoffset;
  953. crtc->depth = depth;
  954. crtc->bpp = bpp;
  955. return 0;
  956. }
  957. static int aty128_pix_width_to_var(int pix_width, struct fb_var_screeninfo *var)
  958. {
  959. /* fill in pixel info */
  960. var->red.msb_right = 0;
  961. var->green.msb_right = 0;
  962. var->blue.offset = 0;
  963. var->blue.msb_right = 0;
  964. var->transp.offset = 0;
  965. var->transp.length = 0;
  966. var->transp.msb_right = 0;
  967. switch (pix_width) {
  968. case CRTC_PIX_WIDTH_8BPP:
  969. var->bits_per_pixel = 8;
  970. var->red.offset = 0;
  971. var->red.length = 8;
  972. var->green.offset = 0;
  973. var->green.length = 8;
  974. var->blue.length = 8;
  975. break;
  976. case CRTC_PIX_WIDTH_15BPP:
  977. var->bits_per_pixel = 16;
  978. var->red.offset = 10;
  979. var->red.length = 5;
  980. var->green.offset = 5;
  981. var->green.length = 5;
  982. var->blue.length = 5;
  983. break;
  984. case CRTC_PIX_WIDTH_16BPP:
  985. var->bits_per_pixel = 16;
  986. var->red.offset = 11;
  987. var->red.length = 5;
  988. var->green.offset = 5;
  989. var->green.length = 6;
  990. var->blue.length = 5;
  991. break;
  992. case CRTC_PIX_WIDTH_24BPP:
  993. var->bits_per_pixel = 24;
  994. var->red.offset = 16;
  995. var->red.length = 8;
  996. var->green.offset = 8;
  997. var->green.length = 8;
  998. var->blue.length = 8;
  999. break;
  1000. case CRTC_PIX_WIDTH_32BPP:
  1001. var->bits_per_pixel = 32;
  1002. var->red.offset = 16;
  1003. var->red.length = 8;
  1004. var->green.offset = 8;
  1005. var->green.length = 8;
  1006. var->blue.length = 8;
  1007. var->transp.offset = 24;
  1008. var->transp.length = 8;
  1009. break;
  1010. default:
  1011. printk(KERN_ERR "aty128fb: Invalid pixel width\n");
  1012. return -EINVAL;
  1013. }
  1014. return 0;
  1015. }
  1016. static int aty128_crtc_to_var(const struct aty128_crtc *crtc,
  1017. struct fb_var_screeninfo *var)
  1018. {
  1019. u32 xres, yres, left, right, upper, lower, hslen, vslen, sync;
  1020. u32 h_total, h_disp, h_sync_strt, h_sync_dly, h_sync_wid, h_sync_pol;
  1021. u32 v_total, v_disp, v_sync_strt, v_sync_wid, v_sync_pol, c_sync;
  1022. u32 pix_width;
  1023. /* fun with masking */
  1024. h_total = crtc->h_total & 0x1ff;
  1025. h_disp = (crtc->h_total >> 16) & 0xff;
  1026. h_sync_strt = (crtc->h_sync_strt_wid >> 3) & 0x1ff;
  1027. h_sync_dly = crtc->h_sync_strt_wid & 0x7;
  1028. h_sync_wid = (crtc->h_sync_strt_wid >> 16) & 0x3f;
  1029. h_sync_pol = (crtc->h_sync_strt_wid >> 23) & 0x1;
  1030. v_total = crtc->v_total & 0x7ff;
  1031. v_disp = (crtc->v_total >> 16) & 0x7ff;
  1032. v_sync_strt = crtc->v_sync_strt_wid & 0x7ff;
  1033. v_sync_wid = (crtc->v_sync_strt_wid >> 16) & 0x1f;
  1034. v_sync_pol = (crtc->v_sync_strt_wid >> 23) & 0x1;
  1035. c_sync = crtc->gen_cntl & CRTC_CSYNC_EN ? 1 : 0;
  1036. pix_width = crtc->gen_cntl & CRTC_PIX_WIDTH_MASK;
  1037. /* do conversions */
  1038. xres = (h_disp + 1) << 3;
  1039. yres = v_disp + 1;
  1040. left = ((h_total - h_sync_strt - h_sync_wid) << 3) - h_sync_dly;
  1041. right = ((h_sync_strt - h_disp) << 3) + h_sync_dly;
  1042. hslen = h_sync_wid << 3;
  1043. upper = v_total - v_sync_strt - v_sync_wid;
  1044. lower = v_sync_strt - v_disp;
  1045. vslen = v_sync_wid;
  1046. sync = (h_sync_pol ? 0 : FB_SYNC_HOR_HIGH_ACT) |
  1047. (v_sync_pol ? 0 : FB_SYNC_VERT_HIGH_ACT) |
  1048. (c_sync ? FB_SYNC_COMP_HIGH_ACT : 0);
  1049. aty128_pix_width_to_var(pix_width, var);
  1050. var->xres = xres;
  1051. var->yres = yres;
  1052. var->xres_virtual = crtc->vxres;
  1053. var->yres_virtual = crtc->vyres;
  1054. var->xoffset = crtc->xoffset;
  1055. var->yoffset = crtc->yoffset;
  1056. var->left_margin = left;
  1057. var->right_margin = right;
  1058. var->upper_margin = upper;
  1059. var->lower_margin = lower;
  1060. var->hsync_len = hslen;
  1061. var->vsync_len = vslen;
  1062. var->sync = sync;
  1063. var->vmode = FB_VMODE_NONINTERLACED;
  1064. return 0;
  1065. }
  1066. static void aty128_set_crt_enable(struct aty128fb_par *par, int on)
  1067. {
  1068. if (on) {
  1069. aty_st_le32(CRTC_EXT_CNTL, aty_ld_le32(CRTC_EXT_CNTL) | CRT_CRTC_ON);
  1070. aty_st_le32(DAC_CNTL, (aty_ld_le32(DAC_CNTL) | DAC_PALETTE2_SNOOP_EN));
  1071. } else
  1072. aty_st_le32(CRTC_EXT_CNTL, aty_ld_le32(CRTC_EXT_CNTL) & ~CRT_CRTC_ON);
  1073. }
  1074. static void aty128_set_lcd_enable(struct aty128fb_par *par, int on)
  1075. {
  1076. u32 reg;
  1077. if (on) {
  1078. reg = aty_ld_le32(LVDS_GEN_CNTL);
  1079. reg |= LVDS_ON | LVDS_EN | LVDS_BLON | LVDS_DIGION;
  1080. reg &= ~LVDS_DISPLAY_DIS;
  1081. aty_st_le32(LVDS_GEN_CNTL, reg);
  1082. #ifdef CONFIG_PMAC_BACKLIGHT
  1083. aty128_set_backlight_enable(get_backlight_enable(),
  1084. get_backlight_level(), par);
  1085. #endif
  1086. } else {
  1087. #ifdef CONFIG_PMAC_BACKLIGHT
  1088. aty128_set_backlight_enable(0, 0, par);
  1089. #endif
  1090. reg = aty_ld_le32(LVDS_GEN_CNTL);
  1091. reg |= LVDS_DISPLAY_DIS;
  1092. aty_st_le32(LVDS_GEN_CNTL, reg);
  1093. mdelay(100);
  1094. reg &= ~(LVDS_ON /*| LVDS_EN*/);
  1095. aty_st_le32(LVDS_GEN_CNTL, reg);
  1096. }
  1097. }
  1098. static void aty128_set_pll(struct aty128_pll *pll, const struct aty128fb_par *par)
  1099. {
  1100. u32 div3;
  1101. unsigned char post_conv[] = /* register values for post dividers */
  1102. { 2, 0, 1, 4, 2, 2, 6, 2, 3, 2, 2, 2, 7 };
  1103. /* select PPLL_DIV_3 */
  1104. aty_st_le32(CLOCK_CNTL_INDEX, aty_ld_le32(CLOCK_CNTL_INDEX) | (3 << 8));
  1105. /* reset PLL */
  1106. aty_st_pll(PPLL_CNTL,
  1107. aty_ld_pll(PPLL_CNTL) | PPLL_RESET | PPLL_ATOMIC_UPDATE_EN);
  1108. /* write the reference divider */
  1109. aty_pll_wait_readupdate(par);
  1110. aty_st_pll(PPLL_REF_DIV, par->constants.ref_divider & 0x3ff);
  1111. aty_pll_writeupdate(par);
  1112. div3 = aty_ld_pll(PPLL_DIV_3);
  1113. div3 &= ~PPLL_FB3_DIV_MASK;
  1114. div3 |= pll->feedback_divider;
  1115. div3 &= ~PPLL_POST3_DIV_MASK;
  1116. div3 |= post_conv[pll->post_divider] << 16;
  1117. /* write feedback and post dividers */
  1118. aty_pll_wait_readupdate(par);
  1119. aty_st_pll(PPLL_DIV_3, div3);
  1120. aty_pll_writeupdate(par);
  1121. aty_pll_wait_readupdate(par);
  1122. aty_st_pll(HTOTAL_CNTL, 0); /* no horiz crtc adjustment */
  1123. aty_pll_writeupdate(par);
  1124. /* clear the reset, just in case */
  1125. aty_st_pll(PPLL_CNTL, aty_ld_pll(PPLL_CNTL) & ~PPLL_RESET);
  1126. }
  1127. static int aty128_var_to_pll(u32 period_in_ps, struct aty128_pll *pll,
  1128. const struct aty128fb_par *par)
  1129. {
  1130. const struct aty128_constants c = par->constants;
  1131. unsigned char post_dividers[] = {1,2,4,8,3,6,12};
  1132. u32 output_freq;
  1133. u32 vclk; /* in .01 MHz */
  1134. int i = 0;
  1135. u32 n, d;
  1136. vclk = 100000000 / period_in_ps; /* convert units to 10 kHz */
  1137. /* adjust pixel clock if necessary */
  1138. if (vclk > c.ppll_max)
  1139. vclk = c.ppll_max;
  1140. if (vclk * 12 < c.ppll_min)
  1141. vclk = c.ppll_min/12;
  1142. /* now, find an acceptable divider */
  1143. for (i = 0; i < sizeof(post_dividers); i++) {
  1144. output_freq = post_dividers[i] * vclk;
  1145. if (output_freq >= c.ppll_min && output_freq <= c.ppll_max) {
  1146. pll->post_divider = post_dividers[i];
  1147. break;
  1148. }
  1149. }
  1150. /* calculate feedback divider */
  1151. n = c.ref_divider * output_freq;
  1152. d = c.ref_clk;
  1153. pll->feedback_divider = round_div(n, d);
  1154. pll->vclk = vclk;
  1155. DBG("post %d feedback %d vlck %d output %d ref_divider %d "
  1156. "vclk_per: %d\n", pll->post_divider,
  1157. pll->feedback_divider, vclk, output_freq,
  1158. c.ref_divider, period_in_ps);
  1159. return 0;
  1160. }
  1161. static int aty128_pll_to_var(const struct aty128_pll *pll, struct fb_var_screeninfo *var)
  1162. {
  1163. var->pixclock = 100000000 / pll->vclk;
  1164. return 0;
  1165. }
  1166. static void aty128_set_fifo(const struct aty128_ddafifo *dsp,
  1167. const struct aty128fb_par *par)
  1168. {
  1169. aty_st_le32(DDA_CONFIG, dsp->dda_config);
  1170. aty_st_le32(DDA_ON_OFF, dsp->dda_on_off);
  1171. }
  1172. static int aty128_ddafifo(struct aty128_ddafifo *dsp,
  1173. const struct aty128_pll *pll,
  1174. u32 depth,
  1175. const struct aty128fb_par *par)
  1176. {
  1177. const struct aty128_meminfo *m = par->mem;
  1178. u32 xclk = par->constants.xclk;
  1179. u32 fifo_width = par->constants.fifo_width;
  1180. u32 fifo_depth = par->constants.fifo_depth;
  1181. s32 x, b, p, ron, roff;
  1182. u32 n, d, bpp;
  1183. /* round up to multiple of 8 */
  1184. bpp = (depth+7) & ~7;
  1185. n = xclk * fifo_width;
  1186. d = pll->vclk * bpp;
  1187. x = round_div(n, d);
  1188. ron = 4 * m->MB +
  1189. 3 * ((m->Trcd - 2 > 0) ? m->Trcd - 2 : 0) +
  1190. 2 * m->Trp +
  1191. m->Twr +
  1192. m->CL +
  1193. m->Tr2w +
  1194. x;
  1195. DBG("x %x\n", x);
  1196. b = 0;
  1197. while (x) {
  1198. x >>= 1;
  1199. b++;
  1200. }
  1201. p = b + 1;
  1202. ron <<= (11 - p);
  1203. n <<= (11 - p);
  1204. x = round_div(n, d);
  1205. roff = x * (fifo_depth - 4);
  1206. if ((ron + m->Rloop) >= roff) {
  1207. printk(KERN_ERR "aty128fb: Mode out of range!\n");
  1208. return -EINVAL;
  1209. }
  1210. DBG("p: %x rloop: %x x: %x ron: %x roff: %x\n",
  1211. p, m->Rloop, x, ron, roff);
  1212. dsp->dda_config = p << 16 | m->Rloop << 20 | x;
  1213. dsp->dda_on_off = ron << 16 | roff;
  1214. return 0;
  1215. }
  1216. /*
  1217. * This actually sets the video mode.
  1218. */
  1219. static int aty128fb_set_par(struct fb_info *info)
  1220. {
  1221. struct aty128fb_par *par = info->par;
  1222. u32 config;
  1223. int err;
  1224. if ((err = aty128_decode_var(&info->var, par)) != 0)
  1225. return err;
  1226. if (par->blitter_may_be_busy)
  1227. wait_for_idle(par);
  1228. /* clear all registers that may interfere with mode setting */
  1229. aty_st_le32(OVR_CLR, 0);
  1230. aty_st_le32(OVR_WID_LEFT_RIGHT, 0);
  1231. aty_st_le32(OVR_WID_TOP_BOTTOM, 0);
  1232. aty_st_le32(OV0_SCALE_CNTL, 0);
  1233. aty_st_le32(MPP_TB_CONFIG, 0);
  1234. aty_st_le32(MPP_GP_CONFIG, 0);
  1235. aty_st_le32(SUBPIC_CNTL, 0);
  1236. aty_st_le32(VIPH_CONTROL, 0);
  1237. aty_st_le32(I2C_CNTL_1, 0); /* turn off i2c */
  1238. aty_st_le32(GEN_INT_CNTL, 0); /* turn off interrupts */
  1239. aty_st_le32(CAP0_TRIG_CNTL, 0);
  1240. aty_st_le32(CAP1_TRIG_CNTL, 0);
  1241. aty_st_8(CRTC_EXT_CNTL + 1, 4); /* turn video off */
  1242. aty128_set_crtc(&par->crtc, par);
  1243. aty128_set_pll(&par->pll, par);
  1244. aty128_set_fifo(&par->fifo_reg, par);
  1245. config = aty_ld_le32(CONFIG_CNTL) & ~3;
  1246. #if defined(__BIG_ENDIAN)
  1247. if (par->crtc.bpp == 32)
  1248. config |= 2; /* make aperture do 32 bit swapping */
  1249. else if (par->crtc.bpp == 16)
  1250. config |= 1; /* make aperture do 16 bit swapping */
  1251. #endif
  1252. aty_st_le32(CONFIG_CNTL, config);
  1253. aty_st_8(CRTC_EXT_CNTL + 1, 0); /* turn the video back on */
  1254. info->fix.line_length = (par->crtc.vxres * par->crtc.bpp) >> 3;
  1255. info->fix.visual = par->crtc.bpp == 8 ? FB_VISUAL_PSEUDOCOLOR
  1256. : FB_VISUAL_DIRECTCOLOR;
  1257. if (par->chip_gen == rage_M3) {
  1258. aty128_set_crt_enable(par, par->crt_on);
  1259. aty128_set_lcd_enable(par, par->lcd_on);
  1260. }
  1261. if (par->accel_flags & FB_ACCELF_TEXT)
  1262. aty128_init_engine(par);
  1263. #ifdef CONFIG_BOOTX_TEXT
  1264. btext_update_display(info->fix.smem_start,
  1265. (((par->crtc.h_total>>16) & 0xff)+1)*8,
  1266. ((par->crtc.v_total>>16) & 0x7ff)+1,
  1267. par->crtc.bpp,
  1268. par->crtc.vxres*par->crtc.bpp/8);
  1269. #endif /* CONFIG_BOOTX_TEXT */
  1270. return 0;
  1271. }
  1272. /*
  1273. * encode/decode the User Defined Part of the Display
  1274. */
  1275. static int aty128_decode_var(struct fb_var_screeninfo *var, struct aty128fb_par *par)
  1276. {
  1277. int err;
  1278. struct aty128_crtc crtc;
  1279. struct aty128_pll pll;
  1280. struct aty128_ddafifo fifo_reg;
  1281. if ((err = aty128_var_to_crtc(var, &crtc, par)))
  1282. return err;
  1283. if ((err = aty128_var_to_pll(var->pixclock, &pll, par)))
  1284. return err;
  1285. if ((err = aty128_ddafifo(&fifo_reg, &pll, crtc.depth, par)))
  1286. return err;
  1287. par->crtc = crtc;
  1288. par->pll = pll;
  1289. par->fifo_reg = fifo_reg;
  1290. par->accel_flags = var->accel_flags;
  1291. return 0;
  1292. }
  1293. static int aty128_encode_var(struct fb_var_screeninfo *var,
  1294. const struct aty128fb_par *par)
  1295. {
  1296. int err;
  1297. if ((err = aty128_crtc_to_var(&par->crtc, var)))
  1298. return err;
  1299. if ((err = aty128_pll_to_var(&par->pll, var)))
  1300. return err;
  1301. var->nonstd = 0;
  1302. var->activate = 0;
  1303. var->height = -1;
  1304. var->width = -1;
  1305. var->accel_flags = par->accel_flags;
  1306. return 0;
  1307. }
  1308. static int aty128fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  1309. {
  1310. struct aty128fb_par par;
  1311. int err;
  1312. par = *(struct aty128fb_par *)info->par;
  1313. if ((err = aty128_decode_var(var, &par)) != 0)
  1314. return err;
  1315. aty128_encode_var(var, &par);
  1316. return 0;
  1317. }
  1318. /*
  1319. * Pan or Wrap the Display
  1320. */
  1321. static int aty128fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *fb)
  1322. {
  1323. struct aty128fb_par *par = fb->par;
  1324. u32 xoffset, yoffset;
  1325. u32 offset;
  1326. u32 xres, yres;
  1327. xres = (((par->crtc.h_total >> 16) & 0xff) + 1) << 3;
  1328. yres = ((par->crtc.v_total >> 16) & 0x7ff) + 1;
  1329. xoffset = (var->xoffset +7) & ~7;
  1330. yoffset = var->yoffset;
  1331. if (xoffset+xres > par->crtc.vxres || yoffset+yres > par->crtc.vyres)
  1332. return -EINVAL;
  1333. par->crtc.xoffset = xoffset;
  1334. par->crtc.yoffset = yoffset;
  1335. offset = ((yoffset * par->crtc.vxres + xoffset)*(par->crtc.bpp >> 3)) & ~7;
  1336. if (par->crtc.bpp == 24)
  1337. offset += 8 * (offset % 3); /* Must be multiple of 8 and 3 */
  1338. aty_st_le32(CRTC_OFFSET, offset);
  1339. return 0;
  1340. }
  1341. /*
  1342. * Helper function to store a single palette register
  1343. */
  1344. static void aty128_st_pal(u_int regno, u_int red, u_int green, u_int blue,
  1345. struct aty128fb_par *par)
  1346. {
  1347. if (par->chip_gen == rage_M3) {
  1348. #if 0
  1349. /* Note: For now, on M3, we set palette on both heads, which may
  1350. * be useless. Can someone with a M3 check this ?
  1351. *
  1352. * This code would still be useful if using the second CRTC to
  1353. * do mirroring
  1354. */
  1355. aty_st_le32(DAC_CNTL, aty_ld_le32(DAC_CNTL) | DAC_PALETTE_ACCESS_CNTL);
  1356. aty_st_8(PALETTE_INDEX, regno);
  1357. aty_st_le32(PALETTE_DATA, (red<<16)|(green<<8)|blue);
  1358. #endif
  1359. aty_st_le32(DAC_CNTL, aty_ld_le32(DAC_CNTL) & ~DAC_PALETTE_ACCESS_CNTL);
  1360. }
  1361. aty_st_8(PALETTE_INDEX, regno);
  1362. aty_st_le32(PALETTE_DATA, (red<<16)|(green<<8)|blue);
  1363. }
  1364. static int aty128fb_sync(struct fb_info *info)
  1365. {
  1366. struct aty128fb_par *par = info->par;
  1367. if (par->blitter_may_be_busy)
  1368. wait_for_idle(par);
  1369. return 0;
  1370. }
  1371. #ifndef MODULE
  1372. static int __init aty128fb_setup(char *options)
  1373. {
  1374. char *this_opt;
  1375. if (!options || !*options)
  1376. return 0;
  1377. while ((this_opt = strsep(&options, ",")) != NULL) {
  1378. if (!strncmp(this_opt, "lcd:", 4)) {
  1379. default_lcd_on = simple_strtoul(this_opt+4, NULL, 0);
  1380. continue;
  1381. } else if (!strncmp(this_opt, "crt:", 4)) {
  1382. default_crt_on = simple_strtoul(this_opt+4, NULL, 0);
  1383. continue;
  1384. }
  1385. #ifdef CONFIG_MTRR
  1386. if(!strncmp(this_opt, "nomtrr", 6)) {
  1387. mtrr = 0;
  1388. continue;
  1389. }
  1390. #endif
  1391. #ifdef CONFIG_PPC_PMAC
  1392. /* vmode and cmode deprecated */
  1393. if (!strncmp(this_opt, "vmode:", 6)) {
  1394. unsigned int vmode = simple_strtoul(this_opt+6, NULL, 0);
  1395. if (vmode > 0 && vmode <= VMODE_MAX)
  1396. default_vmode = vmode;
  1397. continue;
  1398. } else if (!strncmp(this_opt, "cmode:", 6)) {
  1399. unsigned int cmode = simple_strtoul(this_opt+6, NULL, 0);
  1400. switch (cmode) {
  1401. case 0:
  1402. case 8:
  1403. default_cmode = CMODE_8;
  1404. break;
  1405. case 15:
  1406. case 16:
  1407. default_cmode = CMODE_16;
  1408. break;
  1409. case 24:
  1410. case 32:
  1411. default_cmode = CMODE_32;
  1412. break;
  1413. }
  1414. continue;
  1415. }
  1416. #endif /* CONFIG_PPC_PMAC */
  1417. mode_option = this_opt;
  1418. }
  1419. return 0;
  1420. }
  1421. #endif /* MODULE */
  1422. /*
  1423. * Initialisation
  1424. */
  1425. #ifdef CONFIG_PPC_PMAC
  1426. static void aty128_early_resume(void *data)
  1427. {
  1428. struct aty128fb_par *par = data;
  1429. if (try_acquire_console_sem())
  1430. return;
  1431. aty128_do_resume(par->pdev);
  1432. release_console_sem();
  1433. }
  1434. #endif /* CONFIG_PPC_PMAC */
  1435. static int __init aty128_init(struct pci_dev *pdev, const struct pci_device_id *ent)
  1436. {
  1437. struct fb_info *info = pci_get_drvdata(pdev);
  1438. struct aty128fb_par *par = info->par;
  1439. struct fb_var_screeninfo var;
  1440. char video_card[DEVICE_NAME_SIZE];
  1441. u8 chip_rev;
  1442. u32 dac;
  1443. if (!par->vram_size) /* may have already been probed */
  1444. par->vram_size = aty_ld_le32(CONFIG_MEMSIZE) & 0x03FFFFFF;
  1445. /* Get the chip revision */
  1446. chip_rev = (aty_ld_le32(CONFIG_CNTL) >> 16) & 0x1F;
  1447. strcpy(video_card, "Rage128 XX ");
  1448. video_card[8] = ent->device >> 8;
  1449. video_card[9] = ent->device & 0xFF;
  1450. /* range check to make sure */
  1451. if (ent->driver_data < ARRAY_SIZE(r128_family))
  1452. strncat(video_card, r128_family[ent->driver_data], sizeof(video_card));
  1453. printk(KERN_INFO "aty128fb: %s [chip rev 0x%x] ", video_card, chip_rev);
  1454. if (par->vram_size % (1024 * 1024) == 0)
  1455. printk("%dM %s\n", par->vram_size / (1024*1024), par->mem->name);
  1456. else
  1457. printk("%dk %s\n", par->vram_size / 1024, par->mem->name);
  1458. par->chip_gen = ent->driver_data;
  1459. /* fill in info */
  1460. info->fbops = &aty128fb_ops;
  1461. info->flags = FBINFO_FLAG_DEFAULT;
  1462. par->lcd_on = default_lcd_on;
  1463. par->crt_on = default_crt_on;
  1464. var = default_var;
  1465. #ifdef CONFIG_PPC_PMAC
  1466. if (machine_is(powermac)) {
  1467. /* Indicate sleep capability */
  1468. if (par->chip_gen == rage_M3) {
  1469. pmac_call_feature(PMAC_FTR_DEVICE_CAN_WAKE, NULL, 0, 1);
  1470. pmac_set_early_video_resume(aty128_early_resume, par);
  1471. }
  1472. /* Find default mode */
  1473. if (mode_option) {
  1474. if (!mac_find_mode(&var, info, mode_option, 8))
  1475. var = default_var;
  1476. } else {
  1477. if (default_vmode <= 0 || default_vmode > VMODE_MAX)
  1478. default_vmode = VMODE_1024_768_60;
  1479. /* iMacs need that resolution
  1480. * PowerMac2,1 first r128 iMacs
  1481. * PowerMac2,2 summer 2000 iMacs
  1482. * PowerMac4,1 january 2001 iMacs "flower power"
  1483. */
  1484. if (machine_is_compatible("PowerMac2,1") ||
  1485. machine_is_compatible("PowerMac2,2") ||
  1486. machine_is_compatible("PowerMac4,1"))
  1487. default_vmode = VMODE_1024_768_75;
  1488. /* iBook SE */
  1489. if (machine_is_compatible("PowerBook2,2"))
  1490. default_vmode = VMODE_800_600_60;
  1491. /* PowerBook Firewire (Pismo), iBook Dual USB */
  1492. if (machine_is_compatible("PowerBook3,1") ||
  1493. machine_is_compatible("PowerBook4,1"))
  1494. default_vmode = VMODE_1024_768_60;
  1495. /* PowerBook Titanium */
  1496. if (machine_is_compatible("PowerBook3,2"))
  1497. default_vmode = VMODE_1152_768_60;
  1498. if (default_cmode > 16)
  1499. default_cmode = CMODE_32;
  1500. else if (default_cmode > 8)
  1501. default_cmode = CMODE_16;
  1502. else
  1503. default_cmode = CMODE_8;
  1504. if (mac_vmode_to_var(default_vmode, default_cmode, &var))
  1505. var = default_var;
  1506. }
  1507. } else
  1508. #endif /* CONFIG_PPC_PMAC */
  1509. {
  1510. if (mode_option)
  1511. if (fb_find_mode(&var, info, mode_option, NULL,
  1512. 0, &defaultmode, 8) == 0)
  1513. var = default_var;
  1514. }
  1515. var.accel_flags &= ~FB_ACCELF_TEXT;
  1516. // var.accel_flags |= FB_ACCELF_TEXT;/* FIXME Will add accel later */
  1517. if (aty128fb_check_var(&var, info)) {
  1518. printk(KERN_ERR "aty128fb: Cannot set default mode.\n");
  1519. return 0;
  1520. }
  1521. /* setup the DAC the way we like it */
  1522. dac = aty_ld_le32(DAC_CNTL);
  1523. dac |= (DAC_8BIT_EN | DAC_RANGE_CNTL);
  1524. dac |= DAC_MASK;
  1525. if (par->chip_gen == rage_M3)
  1526. dac |= DAC_PALETTE2_SNOOP_EN;
  1527. aty_st_le32(DAC_CNTL, dac);
  1528. /* turn off bus mastering, just in case */
  1529. aty_st_le32(BUS_CNTL, aty_ld_le32(BUS_CNTL) | BUS_MASTER_DIS);
  1530. info->var = var;
  1531. fb_alloc_cmap(&info->cmap, 256, 0);
  1532. var.activate = FB_ACTIVATE_NOW;
  1533. aty128_init_engine(par);
  1534. if (register_framebuffer(info) < 0)
  1535. return 0;
  1536. #ifdef CONFIG_PMAC_BACKLIGHT
  1537. /* Could be extended to Rage128Pro LVDS output too */
  1538. if (par->chip_gen == rage_M3)
  1539. register_backlight_controller(&aty128_backlight_controller, par, "ati");
  1540. #endif /* CONFIG_PMAC_BACKLIGHT */
  1541. par->pm_reg = pci_find_capability(pdev, PCI_CAP_ID_PM);
  1542. par->pdev = pdev;
  1543. par->asleep = 0;
  1544. par->lock_blank = 0;
  1545. printk(KERN_INFO "fb%d: %s frame buffer device on %s\n",
  1546. info->node, info->fix.id, video_card);
  1547. return 1; /* success! */
  1548. }
  1549. #ifdef CONFIG_PCI
  1550. /* register a card ++ajoshi */
  1551. static int __init aty128_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  1552. {
  1553. unsigned long fb_addr, reg_addr;
  1554. struct aty128fb_par *par;
  1555. struct fb_info *info;
  1556. int err;
  1557. #ifndef __sparc__
  1558. void __iomem *bios = NULL;
  1559. #endif
  1560. /* Enable device in PCI config */
  1561. if ((err = pci_enable_device(pdev))) {
  1562. printk(KERN_ERR "aty128fb: Cannot enable PCI device: %d\n",
  1563. err);
  1564. return -ENODEV;
  1565. }
  1566. fb_addr = pci_resource_start(pdev, 0);
  1567. if (!request_mem_region(fb_addr, pci_resource_len(pdev, 0),
  1568. "aty128fb FB")) {
  1569. printk(KERN_ERR "aty128fb: cannot reserve frame "
  1570. "buffer memory\n");
  1571. return -ENODEV;
  1572. }
  1573. reg_addr = pci_resource_start(pdev, 2);
  1574. if (!request_mem_region(reg_addr, pci_resource_len(pdev, 2),
  1575. "aty128fb MMIO")) {
  1576. printk(KERN_ERR "aty128fb: cannot reserve MMIO region\n");
  1577. goto err_free_fb;
  1578. }
  1579. /* We have the resources. Now virtualize them */
  1580. info = framebuffer_alloc(sizeof(struct aty128fb_par), &pdev->dev);
  1581. if (info == NULL) {
  1582. printk(KERN_ERR "aty128fb: can't alloc fb_info_aty128\n");
  1583. goto err_free_mmio;
  1584. }
  1585. par = info->par;
  1586. info->pseudo_palette = par->pseudo_palette;
  1587. info->fix = aty128fb_fix;
  1588. /* Virtualize mmio region */
  1589. info->fix.mmio_start = reg_addr;
  1590. par->regbase = ioremap(reg_addr, pci_resource_len(pdev, 2));
  1591. if (!par->regbase)
  1592. goto err_free_info;
  1593. /* Grab memory size from the card */
  1594. // How does this relate to the resource length from the PCI hardware?
  1595. par->vram_size = aty_ld_le32(CONFIG_MEMSIZE) & 0x03FFFFFF;
  1596. /* Virtualize the framebuffer */
  1597. info->screen_base = ioremap(fb_addr, par->vram_size);
  1598. if (!info->screen_base)
  1599. goto err_unmap_out;
  1600. /* Set up info->fix */
  1601. info->fix = aty128fb_fix;
  1602. info->fix.smem_start = fb_addr;
  1603. info->fix.smem_len = par->vram_size;
  1604. info->fix.mmio_start = reg_addr;
  1605. /* If we can't test scratch registers, something is seriously wrong */
  1606. if (!register_test(par)) {
  1607. printk(KERN_ERR "aty128fb: Can't write to video register!\n");
  1608. goto err_out;
  1609. }
  1610. #ifndef __sparc__
  1611. bios = aty128_map_ROM(par, pdev);
  1612. #ifdef CONFIG_X86
  1613. if (bios == NULL)
  1614. bios = aty128_find_mem_vbios(par);
  1615. #endif
  1616. if (bios == NULL)
  1617. printk(KERN_INFO "aty128fb: BIOS not located, guessing timings.\n");
  1618. else {
  1619. printk(KERN_INFO "aty128fb: Rage128 BIOS located\n");
  1620. aty128_get_pllinfo(par, bios);
  1621. pci_unmap_rom(pdev, bios);
  1622. }
  1623. #endif /* __sparc__ */
  1624. aty128_timings(par);
  1625. pci_set_drvdata(pdev, info);
  1626. if (!aty128_init(pdev, ent))
  1627. goto err_out;
  1628. #ifdef CONFIG_MTRR
  1629. if (mtrr) {
  1630. par->mtrr.vram = mtrr_add(info->fix.smem_start,
  1631. par->vram_size, MTRR_TYPE_WRCOMB, 1);
  1632. par->mtrr.vram_valid = 1;
  1633. /* let there be speed */
  1634. printk(KERN_INFO "aty128fb: Rage128 MTRR set to ON\n");
  1635. }
  1636. #endif /* CONFIG_MTRR */
  1637. return 0;
  1638. err_out:
  1639. iounmap(info->screen_base);
  1640. err_unmap_out:
  1641. iounmap(par->regbase);
  1642. err_free_info:
  1643. framebuffer_release(info);
  1644. err_free_mmio:
  1645. release_mem_region(pci_resource_start(pdev, 2),
  1646. pci_resource_len(pdev, 2));
  1647. err_free_fb:
  1648. release_mem_region(pci_resource_start(pdev, 0),
  1649. pci_resource_len(pdev, 0));
  1650. return -ENODEV;
  1651. }
  1652. static void __devexit aty128_remove(struct pci_dev *pdev)
  1653. {
  1654. struct fb_info *info = pci_get_drvdata(pdev);
  1655. struct aty128fb_par *par;
  1656. if (!info)
  1657. return;
  1658. par = info->par;
  1659. unregister_framebuffer(info);
  1660. #ifdef CONFIG_MTRR
  1661. if (par->mtrr.vram_valid)
  1662. mtrr_del(par->mtrr.vram, info->fix.smem_start,
  1663. par->vram_size);
  1664. #endif /* CONFIG_MTRR */
  1665. iounmap(par->regbase);
  1666. iounmap(info->screen_base);
  1667. release_mem_region(pci_resource_start(pdev, 0),
  1668. pci_resource_len(pdev, 0));
  1669. release_mem_region(pci_resource_start(pdev, 2),
  1670. pci_resource_len(pdev, 2));
  1671. framebuffer_release(info);
  1672. }
  1673. #endif /* CONFIG_PCI */
  1674. /*
  1675. * Blank the display.
  1676. */
  1677. static int aty128fb_blank(int blank, struct fb_info *fb)
  1678. {
  1679. struct aty128fb_par *par = fb->par;
  1680. u8 state = 0;
  1681. if (par->lock_blank || par->asleep)
  1682. return 0;
  1683. #ifdef CONFIG_PMAC_BACKLIGHT
  1684. if (machine_is(powermac) && blank)
  1685. set_backlight_enable(0);
  1686. #endif /* CONFIG_PMAC_BACKLIGHT */
  1687. if (blank & FB_BLANK_VSYNC_SUSPEND)
  1688. state |= 2;
  1689. if (blank & FB_BLANK_HSYNC_SUSPEND)
  1690. state |= 1;
  1691. if (blank & FB_BLANK_POWERDOWN)
  1692. state |= 4;
  1693. aty_st_8(CRTC_EXT_CNTL+1, state);
  1694. if (par->chip_gen == rage_M3) {
  1695. aty128_set_crt_enable(par, par->crt_on && !blank);
  1696. aty128_set_lcd_enable(par, par->lcd_on && !blank);
  1697. }
  1698. #ifdef CONFIG_PMAC_BACKLIGHT
  1699. if (machine_is(powermac) && !blank)
  1700. set_backlight_enable(1);
  1701. #endif /* CONFIG_PMAC_BACKLIGHT */
  1702. return 0;
  1703. }
  1704. /*
  1705. * Set a single color register. The values supplied are already
  1706. * rounded down to the hardware's capabilities (according to the
  1707. * entries in the var structure). Return != 0 for invalid regno.
  1708. */
  1709. static int aty128fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  1710. u_int transp, struct fb_info *info)
  1711. {
  1712. struct aty128fb_par *par = info->par;
  1713. if (regno > 255
  1714. || (par->crtc.depth == 16 && regno > 63)
  1715. || (par->crtc.depth == 15 && regno > 31))
  1716. return 1;
  1717. red >>= 8;
  1718. green >>= 8;
  1719. blue >>= 8;
  1720. if (regno < 16) {
  1721. int i;
  1722. u32 *pal = info->pseudo_palette;
  1723. switch (par->crtc.depth) {
  1724. case 15:
  1725. pal[regno] = (regno << 10) | (regno << 5) | regno;
  1726. break;
  1727. case 16:
  1728. pal[regno] = (regno << 11) | (regno << 6) | regno;
  1729. break;
  1730. case 24:
  1731. pal[regno] = (regno << 16) | (regno << 8) | regno;
  1732. break;
  1733. case 32:
  1734. i = (regno << 8) | regno;
  1735. pal[regno] = (i << 16) | i;
  1736. break;
  1737. }
  1738. }
  1739. if (par->crtc.depth == 16 && regno > 0) {
  1740. /*
  1741. * With the 5-6-5 split of bits for RGB at 16 bits/pixel, we
  1742. * have 32 slots for R and B values but 64 slots for G values.
  1743. * Thus the R and B values go in one slot but the G value
  1744. * goes in a different slot, and we have to avoid disturbing
  1745. * the other fields in the slots we touch.
  1746. */
  1747. par->green[regno] = green;
  1748. if (regno < 32) {
  1749. par->red[regno] = red;
  1750. par->blue[regno] = blue;
  1751. aty128_st_pal(regno * 8, red, par->green[regno*2],
  1752. blue, par);
  1753. }
  1754. red = par->red[regno/2];
  1755. blue = par->blue[regno/2];
  1756. regno <<= 2;
  1757. } else if (par->crtc.bpp == 16)
  1758. regno <<= 3;
  1759. aty128_st_pal(regno, red, green, blue, par);
  1760. return 0;
  1761. }
  1762. #define ATY_MIRROR_LCD_ON 0x00000001
  1763. #define ATY_MIRROR_CRT_ON 0x00000002
  1764. /* out param: u32* backlight value: 0 to 15 */
  1765. #define FBIO_ATY128_GET_MIRROR _IOR('@', 1, __u32)
  1766. /* in param: u32* backlight value: 0 to 15 */
  1767. #define FBIO_ATY128_SET_MIRROR _IOW('@', 2, __u32)
  1768. static int aty128fb_ioctl(struct fb_info *info, u_int cmd, u_long arg)
  1769. {
  1770. struct aty128fb_par *par = info->par;
  1771. u32 value;
  1772. int rc;
  1773. switch (cmd) {
  1774. case FBIO_ATY128_SET_MIRROR:
  1775. if (par->chip_gen != rage_M3)
  1776. return -EINVAL;
  1777. rc = get_user(value, (__u32 __user *)arg);
  1778. if (rc)
  1779. return rc;
  1780. par->lcd_on = (value & 0x01) != 0;
  1781. par->crt_on = (value & 0x02) != 0;
  1782. if (!par->crt_on && !par->lcd_on)
  1783. par->lcd_on = 1;
  1784. aty128_set_crt_enable(par, par->crt_on);
  1785. aty128_set_lcd_enable(par, par->lcd_on);
  1786. return 0;
  1787. case FBIO_ATY128_GET_MIRROR:
  1788. if (par->chip_gen != rage_M3)
  1789. return -EINVAL;
  1790. value = (par->crt_on << 1) | par->lcd_on;
  1791. return put_user(value, (__u32 __user *)arg);
  1792. }
  1793. return -EINVAL;
  1794. }
  1795. #ifdef CONFIG_PMAC_BACKLIGHT
  1796. static int backlight_conv[] = {
  1797. 0xff, 0xc0, 0xb5, 0xaa, 0x9f, 0x94, 0x89, 0x7e,
  1798. 0x73, 0x68, 0x5d, 0x52, 0x47, 0x3c, 0x31, 0x24
  1799. };
  1800. /* We turn off the LCD completely instead of just dimming the backlight.
  1801. * This provides greater power saving and the display is useless without
  1802. * backlight anyway
  1803. */
  1804. #define BACKLIGHT_LVDS_OFF
  1805. /* That one prevents proper CRT output with LCD off */
  1806. #undef BACKLIGHT_DAC_OFF
  1807. static int aty128_set_backlight_enable(int on, int level, void *data)
  1808. {
  1809. struct aty128fb_par *par = data;
  1810. unsigned int reg = aty_ld_le32(LVDS_GEN_CNTL);
  1811. if (!par->lcd_on)
  1812. on = 0;
  1813. reg |= LVDS_BL_MOD_EN | LVDS_BLON;
  1814. if (on && level > BACKLIGHT_OFF) {
  1815. reg |= LVDS_DIGION;
  1816. if (!(reg & LVDS_ON)) {
  1817. reg &= ~LVDS_BLON;
  1818. aty_st_le32(LVDS_GEN_CNTL, reg);
  1819. (void)aty_ld_le32(LVDS_GEN_CNTL);
  1820. mdelay(10);
  1821. reg |= LVDS_BLON;
  1822. aty_st_le32(LVDS_GEN_CNTL, reg);
  1823. }
  1824. reg &= ~LVDS_BL_MOD_LEVEL_MASK;
  1825. reg |= (backlight_conv[level] << LVDS_BL_MOD_LEVEL_SHIFT);
  1826. #ifdef BACKLIGHT_LVDS_OFF
  1827. reg |= LVDS_ON | LVDS_EN;
  1828. reg &= ~LVDS_DISPLAY_DIS;
  1829. #endif
  1830. aty_st_le32(LVDS_GEN_CNTL, reg);
  1831. #ifdef BACKLIGHT_DAC_OFF
  1832. aty_st_le32(DAC_CNTL, aty_ld_le32(DAC_CNTL) & (~DAC_PDWN));
  1833. #endif
  1834. } else {
  1835. reg &= ~LVDS_BL_MOD_LEVEL_MASK;
  1836. reg |= (backlight_conv[0] << LVDS_BL_MOD_LEVEL_SHIFT);
  1837. #ifdef BACKLIGHT_LVDS_OFF
  1838. reg |= LVDS_DISPLAY_DIS;
  1839. aty_st_le32(LVDS_GEN_CNTL, reg);
  1840. (void)aty_ld_le32(LVDS_GEN_CNTL);
  1841. udelay(10);
  1842. reg &= ~(LVDS_ON | LVDS_EN | LVDS_BLON | LVDS_DIGION);
  1843. #endif
  1844. aty_st_le32(LVDS_GEN_CNTL, reg);
  1845. #ifdef BACKLIGHT_DAC_OFF
  1846. aty_st_le32(DAC_CNTL, aty_ld_le32(DAC_CNTL) | DAC_PDWN);
  1847. #endif
  1848. }
  1849. return 0;
  1850. }
  1851. static int aty128_set_backlight_level(int level, void* data)
  1852. {
  1853. return aty128_set_backlight_enable(1, level, data);
  1854. }
  1855. #endif /* CONFIG_PMAC_BACKLIGHT */
  1856. #if 0
  1857. /*
  1858. * Accelerated functions
  1859. */
  1860. static inline void aty128_rectcopy(int srcx, int srcy, int dstx, int dsty,
  1861. u_int width, u_int height,
  1862. struct fb_info_aty128 *par)
  1863. {
  1864. u32 save_dp_datatype, save_dp_cntl, dstval;
  1865. if (!width || !height)
  1866. return;
  1867. dstval = depth_to_dst(par->current_par.crtc.depth);
  1868. if (dstval == DST_24BPP) {
  1869. srcx *= 3;
  1870. dstx *= 3;
  1871. width *= 3;
  1872. } else if (dstval == -EINVAL) {
  1873. printk("aty128fb: invalid depth or RGBA\n");
  1874. return;
  1875. }
  1876. wait_for_fifo(2, par);
  1877. save_dp_datatype = aty_ld_le32(DP_DATATYPE);
  1878. save_dp_cntl = aty_ld_le32(DP_CNTL);
  1879. wait_for_fifo(6, par);
  1880. aty_st_le32(SRC_Y_X, (srcy << 16) | srcx);
  1881. aty_st_le32(DP_MIX, ROP3_SRCCOPY | DP_SRC_RECT);
  1882. aty_st_le32(DP_CNTL, DST_X_LEFT_TO_RIGHT | DST_Y_TOP_TO_BOTTOM);
  1883. aty_st_le32(DP_DATATYPE, save_dp_datatype | dstval | SRC_DSTCOLOR);
  1884. aty_st_le32(DST_Y_X, (dsty << 16) | dstx);
  1885. aty_st_le32(DST_HEIGHT_WIDTH, (height << 16) | width);
  1886. par->blitter_may_be_busy = 1;
  1887. wait_for_fifo(2, par);
  1888. aty_st_le32(DP_DATATYPE, save_dp_datatype);
  1889. aty_st_le32(DP_CNTL, save_dp_cntl);
  1890. }
  1891. /*
  1892. * Text mode accelerated functions
  1893. */
  1894. static void fbcon_aty128_bmove(struct display *p, int sy, int sx, int dy, int dx,
  1895. int height, int width)
  1896. {
  1897. sx *= fontwidth(p);
  1898. sy *= fontheight(p);
  1899. dx *= fontwidth(p);
  1900. dy *= fontheight(p);
  1901. width *= fontwidth(p);
  1902. height *= fontheight(p);
  1903. aty128_rectcopy(sx, sy, dx, dy, width, height,
  1904. (struct fb_info_aty128 *)p->fb_info);
  1905. }
  1906. #endif /* 0 */
  1907. static void aty128_set_suspend(struct aty128fb_par *par, int suspend)
  1908. {
  1909. u32 pmgt;
  1910. u16 pwr_command;
  1911. struct pci_dev *pdev = par->pdev;
  1912. if (!par->pm_reg)
  1913. return;
  1914. /* Set the chip into the appropriate suspend mode (we use D2,
  1915. * D3 would require a complete re-initialisation of the chip,
  1916. * including PCI config registers, clocks, AGP configuration, ...)
  1917. */
  1918. if (suspend) {
  1919. /* Make sure CRTC2 is reset. Remove that the day we decide to
  1920. * actually use CRTC2 and replace it with real code for disabling
  1921. * the CRTC2 output during sleep
  1922. */
  1923. aty_st_le32(CRTC2_GEN_CNTL, aty_ld_le32(CRTC2_GEN_CNTL) &
  1924. ~(CRTC2_EN));
  1925. /* Set the power management mode to be PCI based */
  1926. /* Use this magic value for now */
  1927. pmgt = 0x0c005407;
  1928. aty_st_pll(POWER_MANAGEMENT, pmgt);
  1929. (void)aty_ld_pll(POWER_MANAGEMENT);
  1930. aty_st_le32(BUS_CNTL1, 0x00000010);
  1931. aty_st_le32(MEM_POWER_MISC, 0x0c830000);
  1932. mdelay(100);
  1933. pci_read_config_word(pdev, par->pm_reg+PCI_PM_CTRL, &pwr_command);
  1934. /* Switch PCI power management to D2 */
  1935. pci_write_config_word(pdev, par->pm_reg+PCI_PM_CTRL,
  1936. (pwr_command & ~PCI_PM_CTRL_STATE_MASK) | 2);
  1937. pci_read_config_word(pdev, par->pm_reg+PCI_PM_CTRL, &pwr_command);
  1938. } else {
  1939. /* Switch back PCI power management to D0 */
  1940. mdelay(100);
  1941. pci_write_config_word(pdev, par->pm_reg+PCI_PM_CTRL, 0);
  1942. pci_read_config_word(pdev, par->pm_reg+PCI_PM_CTRL, &pwr_command);
  1943. mdelay(100);
  1944. }
  1945. }
  1946. static int aty128_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  1947. {
  1948. struct fb_info *info = pci_get_drvdata(pdev);
  1949. struct aty128fb_par *par = info->par;
  1950. /* We don't do anything but D2, for now we return 0, but
  1951. * we may want to change that. How do we know if the BIOS
  1952. * can properly take care of D3 ? Also, with swsusp, we
  1953. * know we'll be rebooted, ...
  1954. */
  1955. #ifndef CONFIG_PPC_PMAC
  1956. /* HACK ALERT ! Once I find a proper way to say to each driver
  1957. * individually what will happen with it's PCI slot, I'll change
  1958. * that. On laptops, the AGP slot is just unclocked, so D2 is
  1959. * expected, while on desktops, the card is powered off
  1960. */
  1961. return 0;
  1962. #endif /* CONFIG_PPC_PMAC */
  1963. if (state.event == pdev->dev.power.power_state.event)
  1964. return 0;
  1965. printk(KERN_DEBUG "aty128fb: suspending...\n");
  1966. acquire_console_sem();
  1967. fb_set_suspend(info, 1);
  1968. /* Make sure engine is reset */
  1969. wait_for_idle(par);
  1970. aty128_reset_engine(par);
  1971. wait_for_idle(par);
  1972. /* Blank display and LCD */
  1973. aty128fb_blank(VESA_POWERDOWN, info);
  1974. /* Sleep */
  1975. par->asleep = 1;
  1976. par->lock_blank = 1;
  1977. #ifdef CONFIG_PPC_PMAC
  1978. /* On powermac, we have hooks to properly suspend/resume AGP now,
  1979. * use them here. We'll ultimately need some generic support here,
  1980. * but the generic code isn't quite ready for that yet
  1981. */
  1982. pmac_suspend_agp_for_card(pdev);
  1983. #endif /* CONFIG_PPC_PMAC */
  1984. /* We need a way to make sure the fbdev layer will _not_ touch the
  1985. * framebuffer before we put the chip to suspend state. On 2.4, I
  1986. * used dummy fb ops, 2.5 need proper support for this at the
  1987. * fbdev level
  1988. */
  1989. if (state.event != PM_EVENT_ON)
  1990. aty128_set_suspend(par, 1);
  1991. release_console_sem();
  1992. pdev->dev.power.power_state = state;
  1993. return 0;
  1994. }
  1995. static int aty128_do_resume(struct pci_dev *pdev)
  1996. {
  1997. struct fb_info *info = pci_get_drvdata(pdev);
  1998. struct aty128fb_par *par = info->par;
  1999. if (pdev->dev.power.power_state.event == PM_EVENT_ON)
  2000. return 0;
  2001. /* Wakeup chip */
  2002. aty128_set_suspend(par, 0);
  2003. par->asleep = 0;
  2004. /* Restore display & engine */
  2005. aty128_reset_engine(par);
  2006. wait_for_idle(par);
  2007. aty128fb_set_par(info);
  2008. fb_pan_display(info, &info->var);
  2009. fb_set_cmap(&info->cmap, info);
  2010. /* Refresh */
  2011. fb_set_suspend(info, 0);
  2012. /* Unblank */
  2013. par->lock_blank = 0;
  2014. aty128fb_blank(0, info);
  2015. #ifdef CONFIG_PPC_PMAC
  2016. /* On powermac, we have hooks to properly suspend/resume AGP now,
  2017. * use them here. We'll ultimately need some generic support here,
  2018. * but the generic code isn't quite ready for that yet
  2019. */
  2020. pmac_resume_agp_for_card(pdev);
  2021. #endif /* CONFIG_PPC_PMAC */
  2022. pdev->dev.power.power_state = PMSG_ON;
  2023. printk(KERN_DEBUG "aty128fb: resumed !\n");
  2024. return 0;
  2025. }
  2026. static int aty128_pci_resume(struct pci_dev *pdev)
  2027. {
  2028. int rc;
  2029. acquire_console_sem();
  2030. rc = aty128_do_resume(pdev);
  2031. release_console_sem();
  2032. return rc;
  2033. }
  2034. static int __init aty128fb_init(void)
  2035. {
  2036. #ifndef MODULE
  2037. char *option = NULL;
  2038. if (fb_get_options("aty128fb", &option))
  2039. return -ENODEV;
  2040. aty128fb_setup(option);
  2041. #endif
  2042. return pci_register_driver(&aty128fb_driver);
  2043. }
  2044. static void __exit aty128fb_exit(void)
  2045. {
  2046. pci_unregister_driver(&aty128fb_driver);
  2047. }
  2048. module_init(aty128fb_init);
  2049. module_exit(aty128fb_exit);
  2050. MODULE_AUTHOR("(c)1999-2003 Brad Douglas <brad@neruo.com>");
  2051. MODULE_DESCRIPTION("FBDev driver for ATI Rage128 / Pro cards");
  2052. MODULE_LICENSE("GPL");
  2053. module_param(mode_option, charp, 0);
  2054. MODULE_PARM_DESC(mode_option, "Specify resolution as \"<xres>x<yres>[-<bpp>][@<refresh>]\" ");
  2055. #ifdef CONFIG_MTRR
  2056. module_param_named(nomtrr, mtrr, invbool, 0);
  2057. MODULE_PARM_DESC(nomtrr, "bool: Disable MTRR support (0 or 1=disabled) (default=0)");
  2058. #endif