fbdev.c 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222
  1. /*
  2. * linux/drivers/video/riva/fbdev.c - nVidia RIVA 128/TNT/TNT2 fb driver
  3. *
  4. * Maintained by Ani Joshi <ajoshi@shell.unixbox.com>
  5. *
  6. * Copyright 1999-2000 Jeff Garzik
  7. *
  8. * Contributors:
  9. *
  10. * Ani Joshi: Lots of debugging and cleanup work, really helped
  11. * get the driver going
  12. *
  13. * Ferenc Bakonyi: Bug fixes, cleanup, modularization
  14. *
  15. * Jindrich Makovicka: Accel code help, hw cursor, mtrr
  16. *
  17. * Paul Richards: Bug fixes, updates
  18. *
  19. * Initial template from skeletonfb.c, created 28 Dec 1997 by Geert Uytterhoeven
  20. * Includes riva_hw.c from nVidia, see copyright below.
  21. * KGI code provided the basis for state storage, init, and mode switching.
  22. *
  23. * This file is subject to the terms and conditions of the GNU General Public
  24. * License. See the file COPYING in the main directory of this archive
  25. * for more details.
  26. *
  27. * Known bugs and issues:
  28. * restoring text mode fails
  29. * doublescan modes are broken
  30. */
  31. #include <linux/config.h>
  32. #include <linux/module.h>
  33. #include <linux/kernel.h>
  34. #include <linux/errno.h>
  35. #include <linux/string.h>
  36. #include <linux/mm.h>
  37. #include <linux/tty.h>
  38. #include <linux/slab.h>
  39. #include <linux/delay.h>
  40. #include <linux/fb.h>
  41. #include <linux/init.h>
  42. #include <linux/pci.h>
  43. #ifdef CONFIG_MTRR
  44. #include <asm/mtrr.h>
  45. #endif
  46. #ifdef CONFIG_PPC_OF
  47. #include <asm/prom.h>
  48. #include <asm/pci-bridge.h>
  49. #endif
  50. #ifdef CONFIG_PMAC_BACKLIGHT
  51. #include <asm/backlight.h>
  52. #endif
  53. #include "rivafb.h"
  54. #include "nvreg.h"
  55. #ifndef CONFIG_PCI /* sanity check */
  56. #error This driver requires PCI support.
  57. #endif
  58. /* version number of this driver */
  59. #define RIVAFB_VERSION "0.9.5b"
  60. /* ------------------------------------------------------------------------- *
  61. *
  62. * various helpful macros and constants
  63. *
  64. * ------------------------------------------------------------------------- */
  65. #ifdef CONFIG_FB_RIVA_DEBUG
  66. #define NVTRACE printk
  67. #else
  68. #define NVTRACE if(0) printk
  69. #endif
  70. #define NVTRACE_ENTER(...) NVTRACE("%s START\n", __FUNCTION__)
  71. #define NVTRACE_LEAVE(...) NVTRACE("%s END\n", __FUNCTION__)
  72. #ifdef CONFIG_FB_RIVA_DEBUG
  73. #define assert(expr) \
  74. if(!(expr)) { \
  75. printk( "Assertion failed! %s,%s,%s,line=%d\n",\
  76. #expr,__FILE__,__FUNCTION__,__LINE__); \
  77. BUG(); \
  78. }
  79. #else
  80. #define assert(expr)
  81. #endif
  82. #define PFX "rivafb: "
  83. /* macro that allows you to set overflow bits */
  84. #define SetBitField(value,from,to) SetBF(to,GetBF(value,from))
  85. #define SetBit(n) (1<<(n))
  86. #define Set8Bits(value) ((value)&0xff)
  87. /* HW cursor parameters */
  88. #define MAX_CURS 32
  89. /* ------------------------------------------------------------------------- *
  90. *
  91. * prototypes
  92. *
  93. * ------------------------------------------------------------------------- */
  94. static int rivafb_blank(int blank, struct fb_info *info);
  95. /* ------------------------------------------------------------------------- *
  96. *
  97. * card identification
  98. *
  99. * ------------------------------------------------------------------------- */
  100. static struct pci_device_id rivafb_pci_tbl[] = {
  101. { PCI_VENDOR_ID_NVIDIA_SGS, PCI_DEVICE_ID_NVIDIA_SGS_RIVA128,
  102. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  103. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_TNT,
  104. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  105. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_TNT2,
  106. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  107. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_UTNT2,
  108. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  109. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_VTNT2,
  110. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  111. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_UVTNT2,
  112. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  113. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_ITNT2,
  114. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  115. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_GEFORCE_SDR,
  116. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  117. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_GEFORCE_DDR,
  118. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  119. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_QUADRO,
  120. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  121. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_GEFORCE2_MX,
  122. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  123. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_GEFORCE2_MX2,
  124. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  125. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_GEFORCE2_GO,
  126. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  127. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_QUADRO2_MXR,
  128. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  129. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_GEFORCE2_GTS,
  130. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  131. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_GEFORCE2_GTS2,
  132. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  133. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_GEFORCE2_ULTRA,
  134. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  135. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_QUADRO2_PRO,
  136. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  137. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_GEFORCE4_MX_460,
  138. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  139. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_GEFORCE4_MX_440,
  140. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  141. // NF2/IGP version, GeForce 4 MX, NV18
  142. { PCI_VENDOR_ID_NVIDIA, 0x01f0,
  143. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  144. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_GEFORCE4_MX_420,
  145. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  146. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_GEFORCE4_440_GO,
  147. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  148. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_GEFORCE4_420_GO,
  149. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  150. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_GEFORCE4_420_GO_M32,
  151. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  152. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_QUADRO4_500XGL,
  153. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  154. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_GEFORCE4_440_GO_M64,
  155. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  156. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_QUADRO4_200,
  157. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  158. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_QUADRO4_550XGL,
  159. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  160. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_QUADRO4_500_GOGL,
  161. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  162. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_IGEFORCE2,
  163. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  164. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_GEFORCE3,
  165. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  166. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_GEFORCE3_1,
  167. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  168. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_GEFORCE3_2,
  169. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  170. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_QUADRO_DDC,
  171. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  172. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_GEFORCE4_TI_4600,
  173. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  174. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_GEFORCE4_TI_4400,
  175. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  176. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_GEFORCE4_TI_4200,
  177. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  178. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_QUADRO4_900XGL,
  179. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  180. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_QUADRO4_750XGL,
  181. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  182. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_QUADRO4_700XGL,
  183. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  184. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_GEFORCE_FX_GO_5200,
  185. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  186. { 0, } /* terminate list */
  187. };
  188. MODULE_DEVICE_TABLE(pci, rivafb_pci_tbl);
  189. /* ------------------------------------------------------------------------- *
  190. *
  191. * global variables
  192. *
  193. * ------------------------------------------------------------------------- */
  194. /* command line data, set in rivafb_setup() */
  195. static int flatpanel __devinitdata = -1; /* Autodetect later */
  196. static int forceCRTC __devinitdata = -1;
  197. static int noaccel __devinitdata = 0;
  198. #ifdef CONFIG_MTRR
  199. static int nomtrr __devinitdata = 0;
  200. #endif
  201. static char *mode_option __devinitdata = NULL;
  202. static int strictmode = 0;
  203. static struct fb_fix_screeninfo __devinitdata rivafb_fix = {
  204. .type = FB_TYPE_PACKED_PIXELS,
  205. .xpanstep = 1,
  206. .ypanstep = 1,
  207. };
  208. static struct fb_var_screeninfo __devinitdata rivafb_default_var = {
  209. .xres = 640,
  210. .yres = 480,
  211. .xres_virtual = 640,
  212. .yres_virtual = 480,
  213. .bits_per_pixel = 8,
  214. .red = {0, 8, 0},
  215. .green = {0, 8, 0},
  216. .blue = {0, 8, 0},
  217. .transp = {0, 0, 0},
  218. .activate = FB_ACTIVATE_NOW,
  219. .height = -1,
  220. .width = -1,
  221. .pixclock = 39721,
  222. .left_margin = 40,
  223. .right_margin = 24,
  224. .upper_margin = 32,
  225. .lower_margin = 11,
  226. .hsync_len = 96,
  227. .vsync_len = 2,
  228. .vmode = FB_VMODE_NONINTERLACED
  229. };
  230. /* from GGI */
  231. static const struct riva_regs reg_template = {
  232. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* ATTR */
  233. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  234. 0x41, 0x01, 0x0F, 0x00, 0x00},
  235. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* CRT */
  236. 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
  237. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE3, /* 0x10 */
  238. 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  239. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20 */
  240. 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  241. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30 */
  242. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  243. 0x00, /* 0x40 */
  244. },
  245. {0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F, /* GRA */
  246. 0xFF},
  247. {0x03, 0x01, 0x0F, 0x00, 0x0E}, /* SEQ */
  248. 0xEB /* MISC */
  249. };
  250. /*
  251. * Backlight control
  252. */
  253. #ifdef CONFIG_PMAC_BACKLIGHT
  254. static int riva_backlight_levels[] = {
  255. 0x158,
  256. 0x192,
  257. 0x1c6,
  258. 0x200,
  259. 0x234,
  260. 0x268,
  261. 0x2a2,
  262. 0x2d6,
  263. 0x310,
  264. 0x344,
  265. 0x378,
  266. 0x3b2,
  267. 0x3e6,
  268. 0x41a,
  269. 0x454,
  270. 0x534,
  271. };
  272. static int riva_set_backlight_enable(int on, int level, void *data);
  273. static int riva_set_backlight_level(int level, void *data);
  274. static struct backlight_controller riva_backlight_controller = {
  275. riva_set_backlight_enable,
  276. riva_set_backlight_level
  277. };
  278. #endif /* CONFIG_PMAC_BACKLIGHT */
  279. /* ------------------------------------------------------------------------- *
  280. *
  281. * MMIO access macros
  282. *
  283. * ------------------------------------------------------------------------- */
  284. static inline void CRTCout(struct riva_par *par, unsigned char index,
  285. unsigned char val)
  286. {
  287. VGA_WR08(par->riva.PCIO, 0x3d4, index);
  288. VGA_WR08(par->riva.PCIO, 0x3d5, val);
  289. }
  290. static inline unsigned char CRTCin(struct riva_par *par,
  291. unsigned char index)
  292. {
  293. VGA_WR08(par->riva.PCIO, 0x3d4, index);
  294. return (VGA_RD08(par->riva.PCIO, 0x3d5));
  295. }
  296. static inline void GRAout(struct riva_par *par, unsigned char index,
  297. unsigned char val)
  298. {
  299. VGA_WR08(par->riva.PVIO, 0x3ce, index);
  300. VGA_WR08(par->riva.PVIO, 0x3cf, val);
  301. }
  302. static inline unsigned char GRAin(struct riva_par *par,
  303. unsigned char index)
  304. {
  305. VGA_WR08(par->riva.PVIO, 0x3ce, index);
  306. return (VGA_RD08(par->riva.PVIO, 0x3cf));
  307. }
  308. static inline void SEQout(struct riva_par *par, unsigned char index,
  309. unsigned char val)
  310. {
  311. VGA_WR08(par->riva.PVIO, 0x3c4, index);
  312. VGA_WR08(par->riva.PVIO, 0x3c5, val);
  313. }
  314. static inline unsigned char SEQin(struct riva_par *par,
  315. unsigned char index)
  316. {
  317. VGA_WR08(par->riva.PVIO, 0x3c4, index);
  318. return (VGA_RD08(par->riva.PVIO, 0x3c5));
  319. }
  320. static inline void ATTRout(struct riva_par *par, unsigned char index,
  321. unsigned char val)
  322. {
  323. VGA_WR08(par->riva.PCIO, 0x3c0, index);
  324. VGA_WR08(par->riva.PCIO, 0x3c0, val);
  325. }
  326. static inline unsigned char ATTRin(struct riva_par *par,
  327. unsigned char index)
  328. {
  329. VGA_WR08(par->riva.PCIO, 0x3c0, index);
  330. return (VGA_RD08(par->riva.PCIO, 0x3c1));
  331. }
  332. static inline void MISCout(struct riva_par *par, unsigned char val)
  333. {
  334. VGA_WR08(par->riva.PVIO, 0x3c2, val);
  335. }
  336. static inline unsigned char MISCin(struct riva_par *par)
  337. {
  338. return (VGA_RD08(par->riva.PVIO, 0x3cc));
  339. }
  340. static u8 byte_rev[256] = {
  341. 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
  342. 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
  343. 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
  344. 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
  345. 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
  346. 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
  347. 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
  348. 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
  349. 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
  350. 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
  351. 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
  352. 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
  353. 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
  354. 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
  355. 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
  356. 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
  357. 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
  358. 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
  359. 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
  360. 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
  361. 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
  362. 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
  363. 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
  364. 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
  365. 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
  366. 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
  367. 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
  368. 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
  369. 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
  370. 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
  371. 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
  372. 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff,
  373. };
  374. static inline void reverse_order(u32 *l)
  375. {
  376. u8 *a = (u8 *)l;
  377. *a = byte_rev[*a], a++;
  378. *a = byte_rev[*a], a++;
  379. *a = byte_rev[*a], a++;
  380. *a = byte_rev[*a];
  381. }
  382. /* ------------------------------------------------------------------------- *
  383. *
  384. * cursor stuff
  385. *
  386. * ------------------------------------------------------------------------- */
  387. /**
  388. * rivafb_load_cursor_image - load cursor image to hardware
  389. * @data: address to monochrome bitmap (1 = foreground color, 0 = background)
  390. * @par: pointer to private data
  391. * @w: width of cursor image in pixels
  392. * @h: height of cursor image in scanlines
  393. * @bg: background color (ARGB1555) - alpha bit determines opacity
  394. * @fg: foreground color (ARGB1555)
  395. *
  396. * DESCRIPTiON:
  397. * Loads cursor image based on a monochrome source and mask bitmap. The
  398. * image bits determines the color of the pixel, 0 for background, 1 for
  399. * foreground. Only the affected region (as determined by @w and @h
  400. * parameters) will be updated.
  401. *
  402. * CALLED FROM:
  403. * rivafb_cursor()
  404. */
  405. static void rivafb_load_cursor_image(struct riva_par *par, u8 *data8,
  406. u16 bg, u16 fg, u32 w, u32 h)
  407. {
  408. int i, j, k = 0;
  409. u32 b, tmp;
  410. u32 *data = (u32 *)data8;
  411. bg = le16_to_cpu(bg);
  412. fg = le16_to_cpu(fg);
  413. w = (w + 1) & ~1;
  414. for (i = 0; i < h; i++) {
  415. b = *data++;
  416. reverse_order(&b);
  417. for (j = 0; j < w/2; j++) {
  418. tmp = 0;
  419. #if defined (__BIG_ENDIAN)
  420. tmp = (b & (1 << 31)) ? fg << 16 : bg << 16;
  421. b <<= 1;
  422. tmp |= (b & (1 << 31)) ? fg : bg;
  423. b <<= 1;
  424. #else
  425. tmp = (b & 1) ? fg : bg;
  426. b >>= 1;
  427. tmp |= (b & 1) ? fg << 16 : bg << 16;
  428. b >>= 1;
  429. #endif
  430. writel(tmp, &par->riva.CURSOR[k++]);
  431. }
  432. k += (MAX_CURS - w)/2;
  433. }
  434. }
  435. /* ------------------------------------------------------------------------- *
  436. *
  437. * general utility functions
  438. *
  439. * ------------------------------------------------------------------------- */
  440. /**
  441. * riva_wclut - set CLUT entry
  442. * @chip: pointer to RIVA_HW_INST object
  443. * @regnum: register number
  444. * @red: red component
  445. * @green: green component
  446. * @blue: blue component
  447. *
  448. * DESCRIPTION:
  449. * Sets color register @regnum.
  450. *
  451. * CALLED FROM:
  452. * rivafb_setcolreg()
  453. */
  454. static void riva_wclut(RIVA_HW_INST *chip,
  455. unsigned char regnum, unsigned char red,
  456. unsigned char green, unsigned char blue)
  457. {
  458. VGA_WR08(chip->PDIO, 0x3c8, regnum);
  459. VGA_WR08(chip->PDIO, 0x3c9, red);
  460. VGA_WR08(chip->PDIO, 0x3c9, green);
  461. VGA_WR08(chip->PDIO, 0x3c9, blue);
  462. }
  463. /**
  464. * riva_rclut - read fromCLUT register
  465. * @chip: pointer to RIVA_HW_INST object
  466. * @regnum: register number
  467. * @red: red component
  468. * @green: green component
  469. * @blue: blue component
  470. *
  471. * DESCRIPTION:
  472. * Reads red, green, and blue from color register @regnum.
  473. *
  474. * CALLED FROM:
  475. * rivafb_setcolreg()
  476. */
  477. static void riva_rclut(RIVA_HW_INST *chip,
  478. unsigned char regnum, unsigned char *red,
  479. unsigned char *green, unsigned char *blue)
  480. {
  481. VGA_WR08(chip->PDIO, 0x3c7, regnum);
  482. *red = VGA_RD08(chip->PDIO, 0x3c9);
  483. *green = VGA_RD08(chip->PDIO, 0x3c9);
  484. *blue = VGA_RD08(chip->PDIO, 0x3c9);
  485. }
  486. /**
  487. * riva_save_state - saves current chip state
  488. * @par: pointer to riva_par object containing info for current riva board
  489. * @regs: pointer to riva_regs object
  490. *
  491. * DESCRIPTION:
  492. * Saves current chip state to @regs.
  493. *
  494. * CALLED FROM:
  495. * rivafb_probe()
  496. */
  497. /* from GGI */
  498. static void riva_save_state(struct riva_par *par, struct riva_regs *regs)
  499. {
  500. int i;
  501. NVTRACE_ENTER();
  502. par->riva.LockUnlock(&par->riva, 0);
  503. par->riva.UnloadStateExt(&par->riva, &regs->ext);
  504. regs->misc_output = MISCin(par);
  505. for (i = 0; i < NUM_CRT_REGS; i++)
  506. regs->crtc[i] = CRTCin(par, i);
  507. for (i = 0; i < NUM_ATC_REGS; i++)
  508. regs->attr[i] = ATTRin(par, i);
  509. for (i = 0; i < NUM_GRC_REGS; i++)
  510. regs->gra[i] = GRAin(par, i);
  511. for (i = 0; i < NUM_SEQ_REGS; i++)
  512. regs->seq[i] = SEQin(par, i);
  513. NVTRACE_LEAVE();
  514. }
  515. /**
  516. * riva_load_state - loads current chip state
  517. * @par: pointer to riva_par object containing info for current riva board
  518. * @regs: pointer to riva_regs object
  519. *
  520. * DESCRIPTION:
  521. * Loads chip state from @regs.
  522. *
  523. * CALLED FROM:
  524. * riva_load_video_mode()
  525. * rivafb_probe()
  526. * rivafb_remove()
  527. */
  528. /* from GGI */
  529. static void riva_load_state(struct riva_par *par, struct riva_regs *regs)
  530. {
  531. RIVA_HW_STATE *state = &regs->ext;
  532. int i;
  533. NVTRACE_ENTER();
  534. CRTCout(par, 0x11, 0x00);
  535. par->riva.LockUnlock(&par->riva, 0);
  536. par->riva.LoadStateExt(&par->riva, state);
  537. MISCout(par, regs->misc_output);
  538. for (i = 0; i < NUM_CRT_REGS; i++) {
  539. switch (i) {
  540. case 0x19:
  541. case 0x20 ... 0x40:
  542. break;
  543. default:
  544. CRTCout(par, i, regs->crtc[i]);
  545. }
  546. }
  547. for (i = 0; i < NUM_ATC_REGS; i++)
  548. ATTRout(par, i, regs->attr[i]);
  549. for (i = 0; i < NUM_GRC_REGS; i++)
  550. GRAout(par, i, regs->gra[i]);
  551. for (i = 0; i < NUM_SEQ_REGS; i++)
  552. SEQout(par, i, regs->seq[i]);
  553. NVTRACE_LEAVE();
  554. }
  555. /**
  556. * riva_load_video_mode - calculate timings
  557. * @info: pointer to fb_info object containing info for current riva board
  558. *
  559. * DESCRIPTION:
  560. * Calculate some timings and then send em off to riva_load_state().
  561. *
  562. * CALLED FROM:
  563. * rivafb_set_par()
  564. */
  565. static void riva_load_video_mode(struct fb_info *info)
  566. {
  567. int bpp, width, hDisplaySize, hDisplay, hStart,
  568. hEnd, hTotal, height, vDisplay, vStart, vEnd, vTotal, dotClock;
  569. int hBlankStart, hBlankEnd, vBlankStart, vBlankEnd;
  570. struct riva_par *par = (struct riva_par *) info->par;
  571. struct riva_regs newmode;
  572. NVTRACE_ENTER();
  573. /* time to calculate */
  574. rivafb_blank(1, info);
  575. bpp = info->var.bits_per_pixel;
  576. if (bpp == 16 && info->var.green.length == 5)
  577. bpp = 15;
  578. width = info->var.xres_virtual;
  579. hDisplaySize = info->var.xres;
  580. hDisplay = (hDisplaySize / 8) - 1;
  581. hStart = (hDisplaySize + info->var.right_margin) / 8 - 1;
  582. hEnd = (hDisplaySize + info->var.right_margin +
  583. info->var.hsync_len) / 8 - 1;
  584. hTotal = (hDisplaySize + info->var.right_margin +
  585. info->var.hsync_len + info->var.left_margin) / 8 - 5;
  586. hBlankStart = hDisplay;
  587. hBlankEnd = hTotal + 4;
  588. height = info->var.yres_virtual;
  589. vDisplay = info->var.yres - 1;
  590. vStart = info->var.yres + info->var.lower_margin - 1;
  591. vEnd = info->var.yres + info->var.lower_margin +
  592. info->var.vsync_len - 1;
  593. vTotal = info->var.yres + info->var.lower_margin +
  594. info->var.vsync_len + info->var.upper_margin + 2;
  595. vBlankStart = vDisplay;
  596. vBlankEnd = vTotal + 1;
  597. dotClock = 1000000000 / info->var.pixclock;
  598. memcpy(&newmode, &reg_template, sizeof(struct riva_regs));
  599. if ((info->var.vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED)
  600. vTotal |= 1;
  601. if (par->FlatPanel) {
  602. vStart = vTotal - 3;
  603. vEnd = vTotal - 2;
  604. vBlankStart = vStart;
  605. hStart = hTotal - 3;
  606. hEnd = hTotal - 2;
  607. hBlankEnd = hTotal + 4;
  608. }
  609. newmode.crtc[0x0] = Set8Bits (hTotal);
  610. newmode.crtc[0x1] = Set8Bits (hDisplay);
  611. newmode.crtc[0x2] = Set8Bits (hBlankStart);
  612. newmode.crtc[0x3] = SetBitField (hBlankEnd, 4: 0, 4:0) | SetBit (7);
  613. newmode.crtc[0x4] = Set8Bits (hStart);
  614. newmode.crtc[0x5] = SetBitField (hBlankEnd, 5: 5, 7:7)
  615. | SetBitField (hEnd, 4: 0, 4:0);
  616. newmode.crtc[0x6] = SetBitField (vTotal, 7: 0, 7:0);
  617. newmode.crtc[0x7] = SetBitField (vTotal, 8: 8, 0:0)
  618. | SetBitField (vDisplay, 8: 8, 1:1)
  619. | SetBitField (vStart, 8: 8, 2:2)
  620. | SetBitField (vBlankStart, 8: 8, 3:3)
  621. | SetBit (4)
  622. | SetBitField (vTotal, 9: 9, 5:5)
  623. | SetBitField (vDisplay, 9: 9, 6:6)
  624. | SetBitField (vStart, 9: 9, 7:7);
  625. newmode.crtc[0x9] = SetBitField (vBlankStart, 9: 9, 5:5)
  626. | SetBit (6);
  627. newmode.crtc[0x10] = Set8Bits (vStart);
  628. newmode.crtc[0x11] = SetBitField (vEnd, 3: 0, 3:0)
  629. | SetBit (5);
  630. newmode.crtc[0x12] = Set8Bits (vDisplay);
  631. newmode.crtc[0x13] = (width / 8) * ((bpp + 1) / 8);
  632. newmode.crtc[0x15] = Set8Bits (vBlankStart);
  633. newmode.crtc[0x16] = Set8Bits (vBlankEnd);
  634. newmode.ext.screen = SetBitField(hBlankEnd,6:6,4:4)
  635. | SetBitField(vBlankStart,10:10,3:3)
  636. | SetBitField(vStart,10:10,2:2)
  637. | SetBitField(vDisplay,10:10,1:1)
  638. | SetBitField(vTotal,10:10,0:0);
  639. newmode.ext.horiz = SetBitField(hTotal,8:8,0:0)
  640. | SetBitField(hDisplay,8:8,1:1)
  641. | SetBitField(hBlankStart,8:8,2:2)
  642. | SetBitField(hStart,8:8,3:3);
  643. newmode.ext.extra = SetBitField(vTotal,11:11,0:0)
  644. | SetBitField(vDisplay,11:11,2:2)
  645. | SetBitField(vStart,11:11,4:4)
  646. | SetBitField(vBlankStart,11:11,6:6);
  647. if ((info->var.vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) {
  648. int tmp = (hTotal >> 1) & ~1;
  649. newmode.ext.interlace = Set8Bits(tmp);
  650. newmode.ext.horiz |= SetBitField(tmp, 8:8,4:4);
  651. } else
  652. newmode.ext.interlace = 0xff; /* interlace off */
  653. if (par->riva.Architecture >= NV_ARCH_10)
  654. par->riva.CURSOR = (U032 __iomem *)(info->screen_base + par->riva.CursorStart);
  655. if (info->var.sync & FB_SYNC_HOR_HIGH_ACT)
  656. newmode.misc_output &= ~0x40;
  657. else
  658. newmode.misc_output |= 0x40;
  659. if (info->var.sync & FB_SYNC_VERT_HIGH_ACT)
  660. newmode.misc_output &= ~0x80;
  661. else
  662. newmode.misc_output |= 0x80;
  663. par->riva.CalcStateExt(&par->riva, &newmode.ext, bpp, width,
  664. hDisplaySize, height, dotClock);
  665. newmode.ext.scale = NV_RD32(par->riva.PRAMDAC, 0x00000848) &
  666. 0xfff000ff;
  667. if (par->FlatPanel == 1) {
  668. newmode.ext.pixel |= (1 << 7);
  669. newmode.ext.scale |= (1 << 8);
  670. }
  671. if (par->SecondCRTC) {
  672. newmode.ext.head = NV_RD32(par->riva.PCRTC0, 0x00000860) &
  673. ~0x00001000;
  674. newmode.ext.head2 = NV_RD32(par->riva.PCRTC0, 0x00002860) |
  675. 0x00001000;
  676. newmode.ext.crtcOwner = 3;
  677. newmode.ext.pllsel |= 0x20000800;
  678. newmode.ext.vpll2 = newmode.ext.vpll;
  679. } else if (par->riva.twoHeads) {
  680. newmode.ext.head = NV_RD32(par->riva.PCRTC0, 0x00000860) |
  681. 0x00001000;
  682. newmode.ext.head2 = NV_RD32(par->riva.PCRTC0, 0x00002860) &
  683. ~0x00001000;
  684. newmode.ext.crtcOwner = 0;
  685. newmode.ext.vpll2 = NV_RD32(par->riva.PRAMDAC0, 0x00000520);
  686. }
  687. if (par->FlatPanel == 1) {
  688. newmode.ext.pixel |= (1 << 7);
  689. newmode.ext.scale |= (1 << 8);
  690. }
  691. newmode.ext.cursorConfig = 0x02000100;
  692. par->current_state = newmode;
  693. riva_load_state(par, &par->current_state);
  694. par->riva.LockUnlock(&par->riva, 0); /* important for HW cursor */
  695. rivafb_blank(0, info);
  696. NVTRACE_LEAVE();
  697. }
  698. static void riva_update_var(struct fb_var_screeninfo *var, struct fb_videomode *modedb)
  699. {
  700. NVTRACE_ENTER();
  701. var->xres = var->xres_virtual = modedb->xres;
  702. var->yres = modedb->yres;
  703. if (var->yres_virtual < var->yres)
  704. var->yres_virtual = var->yres;
  705. var->xoffset = var->yoffset = 0;
  706. var->pixclock = modedb->pixclock;
  707. var->left_margin = modedb->left_margin;
  708. var->right_margin = modedb->right_margin;
  709. var->upper_margin = modedb->upper_margin;
  710. var->lower_margin = modedb->lower_margin;
  711. var->hsync_len = modedb->hsync_len;
  712. var->vsync_len = modedb->vsync_len;
  713. var->sync = modedb->sync;
  714. var->vmode = modedb->vmode;
  715. NVTRACE_LEAVE();
  716. }
  717. /**
  718. * rivafb_do_maximize -
  719. * @info: pointer to fb_info object containing info for current riva board
  720. * @var:
  721. * @nom:
  722. * @den:
  723. *
  724. * DESCRIPTION:
  725. * .
  726. *
  727. * RETURNS:
  728. * -EINVAL on failure, 0 on success
  729. *
  730. *
  731. * CALLED FROM:
  732. * rivafb_check_var()
  733. */
  734. static int rivafb_do_maximize(struct fb_info *info,
  735. struct fb_var_screeninfo *var,
  736. int nom, int den)
  737. {
  738. static struct {
  739. int xres, yres;
  740. } modes[] = {
  741. {1600, 1280},
  742. {1280, 1024},
  743. {1024, 768},
  744. {800, 600},
  745. {640, 480},
  746. {-1, -1}
  747. };
  748. int i;
  749. NVTRACE_ENTER();
  750. /* use highest possible virtual resolution */
  751. if (var->xres_virtual == -1 && var->yres_virtual == -1) {
  752. printk(KERN_WARNING PFX
  753. "using maximum available virtual resolution\n");
  754. for (i = 0; modes[i].xres != -1; i++) {
  755. if (modes[i].xres * nom / den * modes[i].yres <
  756. info->fix.smem_len)
  757. break;
  758. }
  759. if (modes[i].xres == -1) {
  760. printk(KERN_ERR PFX
  761. "could not find a virtual resolution that fits into video memory!!\n");
  762. NVTRACE("EXIT - EINVAL error\n");
  763. return -EINVAL;
  764. }
  765. var->xres_virtual = modes[i].xres;
  766. var->yres_virtual = modes[i].yres;
  767. printk(KERN_INFO PFX
  768. "virtual resolution set to maximum of %dx%d\n",
  769. var->xres_virtual, var->yres_virtual);
  770. } else if (var->xres_virtual == -1) {
  771. var->xres_virtual = (info->fix.smem_len * den /
  772. (nom * var->yres_virtual)) & ~15;
  773. printk(KERN_WARNING PFX
  774. "setting virtual X resolution to %d\n", var->xres_virtual);
  775. } else if (var->yres_virtual == -1) {
  776. var->xres_virtual = (var->xres_virtual + 15) & ~15;
  777. var->yres_virtual = info->fix.smem_len * den /
  778. (nom * var->xres_virtual);
  779. printk(KERN_WARNING PFX
  780. "setting virtual Y resolution to %d\n", var->yres_virtual);
  781. } else {
  782. var->xres_virtual = (var->xres_virtual + 15) & ~15;
  783. if (var->xres_virtual * nom / den * var->yres_virtual > info->fix.smem_len) {
  784. printk(KERN_ERR PFX
  785. "mode %dx%dx%d rejected...resolution too high to fit into video memory!\n",
  786. var->xres, var->yres, var->bits_per_pixel);
  787. NVTRACE("EXIT - EINVAL error\n");
  788. return -EINVAL;
  789. }
  790. }
  791. if (var->xres_virtual * nom / den >= 8192) {
  792. printk(KERN_WARNING PFX
  793. "virtual X resolution (%d) is too high, lowering to %d\n",
  794. var->xres_virtual, 8192 * den / nom - 16);
  795. var->xres_virtual = 8192 * den / nom - 16;
  796. }
  797. if (var->xres_virtual < var->xres) {
  798. printk(KERN_ERR PFX
  799. "virtual X resolution (%d) is smaller than real\n", var->xres_virtual);
  800. return -EINVAL;
  801. }
  802. if (var->yres_virtual < var->yres) {
  803. printk(KERN_ERR PFX
  804. "virtual Y resolution (%d) is smaller than real\n", var->yres_virtual);
  805. return -EINVAL;
  806. }
  807. if (var->yres_virtual > 0x7fff/nom)
  808. var->yres_virtual = 0x7fff/nom;
  809. if (var->xres_virtual > 0x7fff/nom)
  810. var->xres_virtual = 0x7fff/nom;
  811. NVTRACE_LEAVE();
  812. return 0;
  813. }
  814. static void
  815. riva_set_pattern(struct riva_par *par, int clr0, int clr1, int pat0, int pat1)
  816. {
  817. RIVA_FIFO_FREE(par->riva, Patt, 4);
  818. NV_WR32(&par->riva.Patt->Color0, 0, clr0);
  819. NV_WR32(&par->riva.Patt->Color1, 0, clr1);
  820. NV_WR32(par->riva.Patt->Monochrome, 0, pat0);
  821. NV_WR32(par->riva.Patt->Monochrome, 4, pat1);
  822. }
  823. /* acceleration routines */
  824. static inline void wait_for_idle(struct riva_par *par)
  825. {
  826. while (par->riva.Busy(&par->riva));
  827. }
  828. /*
  829. * Set ROP. Translate X rop into ROP3. Internal routine.
  830. */
  831. static void
  832. riva_set_rop_solid(struct riva_par *par, int rop)
  833. {
  834. riva_set_pattern(par, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
  835. RIVA_FIFO_FREE(par->riva, Rop, 1);
  836. NV_WR32(&par->riva.Rop->Rop3, 0, rop);
  837. }
  838. static void riva_setup_accel(struct fb_info *info)
  839. {
  840. struct riva_par *par = (struct riva_par *) info->par;
  841. RIVA_FIFO_FREE(par->riva, Clip, 2);
  842. NV_WR32(&par->riva.Clip->TopLeft, 0, 0x0);
  843. NV_WR32(&par->riva.Clip->WidthHeight, 0,
  844. (info->var.xres_virtual & 0xffff) |
  845. (info->var.yres_virtual << 16));
  846. riva_set_rop_solid(par, 0xcc);
  847. wait_for_idle(par);
  848. }
  849. /**
  850. * riva_get_cmap_len - query current color map length
  851. * @var: standard kernel fb changeable data
  852. *
  853. * DESCRIPTION:
  854. * Get current color map length.
  855. *
  856. * RETURNS:
  857. * Length of color map
  858. *
  859. * CALLED FROM:
  860. * rivafb_setcolreg()
  861. */
  862. static int riva_get_cmap_len(const struct fb_var_screeninfo *var)
  863. {
  864. int rc = 256; /* reasonable default */
  865. switch (var->green.length) {
  866. case 8:
  867. rc = 256; /* 256 entries (2^8), 8 bpp and RGB8888 */
  868. break;
  869. case 5:
  870. rc = 32; /* 32 entries (2^5), 16 bpp, RGB555 */
  871. break;
  872. case 6:
  873. rc = 64; /* 64 entries (2^6), 16 bpp, RGB565 */
  874. break;
  875. default:
  876. /* should not occur */
  877. break;
  878. }
  879. return rc;
  880. }
  881. /* ------------------------------------------------------------------------- *
  882. *
  883. * Backlight operations
  884. *
  885. * ------------------------------------------------------------------------- */
  886. #ifdef CONFIG_PMAC_BACKLIGHT
  887. static int riva_set_backlight_enable(int on, int level, void *data)
  888. {
  889. struct riva_par *par = (struct riva_par *)data;
  890. U032 tmp_pcrt, tmp_pmc;
  891. tmp_pmc = par->riva.PMC[0x10F0/4] & 0x0000FFFF;
  892. tmp_pcrt = par->riva.PCRTC0[0x081C/4] & 0xFFFFFFFC;
  893. if(on && (level > BACKLIGHT_OFF)) {
  894. tmp_pcrt |= 0x1;
  895. tmp_pmc |= (1 << 31); // backlight bit
  896. tmp_pmc |= riva_backlight_levels[level-1] << 16; // level
  897. }
  898. par->riva.PCRTC0[0x081C/4] = tmp_pcrt;
  899. par->riva.PMC[0x10F0/4] = tmp_pmc;
  900. return 0;
  901. }
  902. static int riva_set_backlight_level(int level, void *data)
  903. {
  904. return riva_set_backlight_enable(1, level, data);
  905. }
  906. #endif /* CONFIG_PMAC_BACKLIGHT */
  907. /* ------------------------------------------------------------------------- *
  908. *
  909. * framebuffer operations
  910. *
  911. * ------------------------------------------------------------------------- */
  912. static int rivafb_open(struct fb_info *info, int user)
  913. {
  914. struct riva_par *par = (struct riva_par *) info->par;
  915. int cnt = atomic_read(&par->ref_count);
  916. NVTRACE_ENTER();
  917. if (!cnt) {
  918. #ifdef CONFIG_X86
  919. memset(&par->state, 0, sizeof(struct vgastate));
  920. par->state.flags = VGA_SAVE_MODE | VGA_SAVE_FONTS;
  921. /* save the DAC for Riva128 */
  922. if (par->riva.Architecture == NV_ARCH_03)
  923. par->state.flags |= VGA_SAVE_CMAP;
  924. save_vga(&par->state);
  925. #endif
  926. /* vgaHWunlock() + riva unlock (0x7F) */
  927. CRTCout(par, 0x11, 0xFF);
  928. par->riva.LockUnlock(&par->riva, 0);
  929. riva_save_state(par, &par->initial_state);
  930. }
  931. atomic_inc(&par->ref_count);
  932. NVTRACE_LEAVE();
  933. return 0;
  934. }
  935. static int rivafb_release(struct fb_info *info, int user)
  936. {
  937. struct riva_par *par = (struct riva_par *) info->par;
  938. int cnt = atomic_read(&par->ref_count);
  939. NVTRACE_ENTER();
  940. if (!cnt)
  941. return -EINVAL;
  942. if (cnt == 1) {
  943. par->riva.LockUnlock(&par->riva, 0);
  944. par->riva.LoadStateExt(&par->riva, &par->initial_state.ext);
  945. riva_load_state(par, &par->initial_state);
  946. #ifdef CONFIG_X86
  947. restore_vga(&par->state);
  948. #endif
  949. par->riva.LockUnlock(&par->riva, 1);
  950. }
  951. atomic_dec(&par->ref_count);
  952. NVTRACE_LEAVE();
  953. return 0;
  954. }
  955. static int rivafb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  956. {
  957. struct fb_videomode *mode;
  958. struct riva_par *par = (struct riva_par *) info->par;
  959. int nom, den; /* translating from pixels->bytes */
  960. int mode_valid = 0;
  961. NVTRACE_ENTER();
  962. switch (var->bits_per_pixel) {
  963. case 1 ... 8:
  964. var->red.offset = var->green.offset = var->blue.offset = 0;
  965. var->red.length = var->green.length = var->blue.length = 8;
  966. var->bits_per_pixel = 8;
  967. nom = den = 1;
  968. break;
  969. case 9 ... 15:
  970. var->green.length = 5;
  971. /* fall through */
  972. case 16:
  973. var->bits_per_pixel = 16;
  974. /* The Riva128 supports RGB555 only */
  975. if (par->riva.Architecture == NV_ARCH_03)
  976. var->green.length = 5;
  977. if (var->green.length == 5) {
  978. /* 0rrrrrgg gggbbbbb */
  979. var->red.offset = 10;
  980. var->green.offset = 5;
  981. var->blue.offset = 0;
  982. var->red.length = 5;
  983. var->green.length = 5;
  984. var->blue.length = 5;
  985. } else {
  986. /* rrrrrggg gggbbbbb */
  987. var->red.offset = 11;
  988. var->green.offset = 5;
  989. var->blue.offset = 0;
  990. var->red.length = 5;
  991. var->green.length = 6;
  992. var->blue.length = 5;
  993. }
  994. nom = 2;
  995. den = 1;
  996. break;
  997. case 17 ... 32:
  998. var->red.length = var->green.length = var->blue.length = 8;
  999. var->bits_per_pixel = 32;
  1000. var->red.offset = 16;
  1001. var->green.offset = 8;
  1002. var->blue.offset = 0;
  1003. nom = 4;
  1004. den = 1;
  1005. break;
  1006. default:
  1007. printk(KERN_ERR PFX
  1008. "mode %dx%dx%d rejected...color depth not supported.\n",
  1009. var->xres, var->yres, var->bits_per_pixel);
  1010. NVTRACE("EXIT, returning -EINVAL\n");
  1011. return -EINVAL;
  1012. }
  1013. if (!strictmode) {
  1014. if (!info->monspecs.vfmax || !info->monspecs.hfmax ||
  1015. !info->monspecs.dclkmax || !fb_validate_mode(var, info))
  1016. mode_valid = 1;
  1017. }
  1018. /* calculate modeline if supported by monitor */
  1019. if (!mode_valid && info->monspecs.gtf) {
  1020. if (!fb_get_mode(FB_MAXTIMINGS, 0, var, info))
  1021. mode_valid = 1;
  1022. }
  1023. if (!mode_valid) {
  1024. mode = fb_find_best_mode(var, &info->modelist);
  1025. if (mode) {
  1026. riva_update_var(var, mode);
  1027. mode_valid = 1;
  1028. }
  1029. }
  1030. if (!mode_valid && info->monspecs.modedb_len)
  1031. return -EINVAL;
  1032. if (var->xres_virtual < var->xres)
  1033. var->xres_virtual = var->xres;
  1034. if (var->yres_virtual <= var->yres)
  1035. var->yres_virtual = -1;
  1036. if (rivafb_do_maximize(info, var, nom, den) < 0)
  1037. return -EINVAL;
  1038. if (var->xoffset < 0)
  1039. var->xoffset = 0;
  1040. if (var->yoffset < 0)
  1041. var->yoffset = 0;
  1042. /* truncate xoffset and yoffset to maximum if too high */
  1043. if (var->xoffset > var->xres_virtual - var->xres)
  1044. var->xoffset = var->xres_virtual - var->xres - 1;
  1045. if (var->yoffset > var->yres_virtual - var->yres)
  1046. var->yoffset = var->yres_virtual - var->yres - 1;
  1047. var->red.msb_right =
  1048. var->green.msb_right =
  1049. var->blue.msb_right =
  1050. var->transp.offset = var->transp.length = var->transp.msb_right = 0;
  1051. NVTRACE_LEAVE();
  1052. return 0;
  1053. }
  1054. static int rivafb_set_par(struct fb_info *info)
  1055. {
  1056. struct riva_par *par = (struct riva_par *) info->par;
  1057. NVTRACE_ENTER();
  1058. /* vgaHWunlock() + riva unlock (0x7F) */
  1059. CRTCout(par, 0x11, 0xFF);
  1060. par->riva.LockUnlock(&par->riva, 0);
  1061. riva_load_video_mode(info);
  1062. if(!(info->flags & FBINFO_HWACCEL_DISABLED))
  1063. riva_setup_accel(info);
  1064. par->cursor_reset = 1;
  1065. info->fix.line_length = (info->var.xres_virtual * (info->var.bits_per_pixel >> 3));
  1066. info->fix.visual = (info->var.bits_per_pixel == 8) ?
  1067. FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_DIRECTCOLOR;
  1068. if (info->flags & FBINFO_HWACCEL_DISABLED)
  1069. info->pixmap.scan_align = 1;
  1070. else
  1071. info->pixmap.scan_align = 4;
  1072. NVTRACE_LEAVE();
  1073. return 0;
  1074. }
  1075. /**
  1076. * rivafb_pan_display
  1077. * @var: standard kernel fb changeable data
  1078. * @con: TODO
  1079. * @info: pointer to fb_info object containing info for current riva board
  1080. *
  1081. * DESCRIPTION:
  1082. * Pan (or wrap, depending on the `vmode' field) the display using the
  1083. * `xoffset' and `yoffset' fields of the `var' structure.
  1084. * If the values don't fit, return -EINVAL.
  1085. *
  1086. * This call looks only at xoffset, yoffset and the FB_VMODE_YWRAP flag
  1087. */
  1088. static int rivafb_pan_display(struct fb_var_screeninfo *var,
  1089. struct fb_info *info)
  1090. {
  1091. struct riva_par *par = (struct riva_par *)info->par;
  1092. unsigned int base;
  1093. NVTRACE_ENTER();
  1094. if (var->xoffset > (var->xres_virtual - var->xres))
  1095. return -EINVAL;
  1096. if (var->yoffset > (var->yres_virtual - var->yres))
  1097. return -EINVAL;
  1098. if (var->vmode & FB_VMODE_YWRAP) {
  1099. if (var->yoffset < 0
  1100. || var->yoffset >= info->var.yres_virtual
  1101. || var->xoffset) return -EINVAL;
  1102. } else {
  1103. if (var->xoffset + info->var.xres > info->var.xres_virtual ||
  1104. var->yoffset + info->var.yres > info->var.yres_virtual)
  1105. return -EINVAL;
  1106. }
  1107. base = var->yoffset * info->fix.line_length + var->xoffset;
  1108. par->riva.SetStartAddress(&par->riva, base);
  1109. info->var.xoffset = var->xoffset;
  1110. info->var.yoffset = var->yoffset;
  1111. if (var->vmode & FB_VMODE_YWRAP)
  1112. info->var.vmode |= FB_VMODE_YWRAP;
  1113. else
  1114. info->var.vmode &= ~FB_VMODE_YWRAP;
  1115. NVTRACE_LEAVE();
  1116. return 0;
  1117. }
  1118. static int rivafb_blank(int blank, struct fb_info *info)
  1119. {
  1120. struct riva_par *par= (struct riva_par *)info->par;
  1121. unsigned char tmp, vesa;
  1122. tmp = SEQin(par, 0x01) & ~0x20; /* screen on/off */
  1123. vesa = CRTCin(par, 0x1a) & ~0xc0; /* sync on/off */
  1124. NVTRACE_ENTER();
  1125. if (blank)
  1126. tmp |= 0x20;
  1127. switch (blank) {
  1128. case FB_BLANK_UNBLANK:
  1129. case FB_BLANK_NORMAL:
  1130. break;
  1131. case FB_BLANK_VSYNC_SUSPEND:
  1132. vesa |= 0x80;
  1133. break;
  1134. case FB_BLANK_HSYNC_SUSPEND:
  1135. vesa |= 0x40;
  1136. break;
  1137. case FB_BLANK_POWERDOWN:
  1138. vesa |= 0xc0;
  1139. break;
  1140. }
  1141. SEQout(par, 0x01, tmp);
  1142. CRTCout(par, 0x1a, vesa);
  1143. #ifdef CONFIG_PMAC_BACKLIGHT
  1144. if ( par->FlatPanel && _machine == _MACH_Pmac) {
  1145. set_backlight_enable(!blank);
  1146. }
  1147. #endif
  1148. NVTRACE_LEAVE();
  1149. return 0;
  1150. }
  1151. /**
  1152. * rivafb_setcolreg
  1153. * @regno: register index
  1154. * @red: red component
  1155. * @green: green component
  1156. * @blue: blue component
  1157. * @transp: transparency
  1158. * @info: pointer to fb_info object containing info for current riva board
  1159. *
  1160. * DESCRIPTION:
  1161. * Set a single color register. The values supplied have a 16 bit
  1162. * magnitude.
  1163. *
  1164. * RETURNS:
  1165. * Return != 0 for invalid regno.
  1166. *
  1167. * CALLED FROM:
  1168. * fbcmap.c:fb_set_cmap()
  1169. */
  1170. static int rivafb_setcolreg(unsigned regno, unsigned red, unsigned green,
  1171. unsigned blue, unsigned transp,
  1172. struct fb_info *info)
  1173. {
  1174. struct riva_par *par = (struct riva_par *)info->par;
  1175. RIVA_HW_INST *chip = &par->riva;
  1176. int i;
  1177. if (regno >= riva_get_cmap_len(&info->var))
  1178. return -EINVAL;
  1179. if (info->var.grayscale) {
  1180. /* gray = 0.30*R + 0.59*G + 0.11*B */
  1181. red = green = blue =
  1182. (red * 77 + green * 151 + blue * 28) >> 8;
  1183. }
  1184. if (regno < 16 && info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
  1185. ((u32 *) info->pseudo_palette)[regno] =
  1186. (regno << info->var.red.offset) |
  1187. (regno << info->var.green.offset) |
  1188. (regno << info->var.blue.offset);
  1189. /*
  1190. * The Riva128 2D engine requires color information in
  1191. * TrueColor format even if framebuffer is in DirectColor
  1192. */
  1193. if (par->riva.Architecture == NV_ARCH_03) {
  1194. switch (info->var.bits_per_pixel) {
  1195. case 16:
  1196. par->palette[regno] = ((red & 0xf800) >> 1) |
  1197. ((green & 0xf800) >> 6) |
  1198. ((blue & 0xf800) >> 11);
  1199. break;
  1200. case 32:
  1201. par->palette[regno] = ((red & 0xff00) << 8) |
  1202. ((green & 0xff00)) |
  1203. ((blue & 0xff00) >> 8);
  1204. break;
  1205. }
  1206. }
  1207. }
  1208. switch (info->var.bits_per_pixel) {
  1209. case 8:
  1210. /* "transparent" stuff is completely ignored. */
  1211. riva_wclut(chip, regno, red >> 8, green >> 8, blue >> 8);
  1212. break;
  1213. case 16:
  1214. if (info->var.green.length == 5) {
  1215. for (i = 0; i < 8; i++) {
  1216. riva_wclut(chip, regno*8+i, red >> 8,
  1217. green >> 8, blue >> 8);
  1218. }
  1219. } else {
  1220. u8 r, g, b;
  1221. if (regno < 32) {
  1222. for (i = 0; i < 8; i++) {
  1223. riva_wclut(chip, regno*8+i,
  1224. red >> 8, green >> 8,
  1225. blue >> 8);
  1226. }
  1227. }
  1228. riva_rclut(chip, regno*4, &r, &g, &b);
  1229. for (i = 0; i < 4; i++)
  1230. riva_wclut(chip, regno*4+i, r,
  1231. green >> 8, b);
  1232. }
  1233. break;
  1234. case 32:
  1235. riva_wclut(chip, regno, red >> 8, green >> 8, blue >> 8);
  1236. break;
  1237. default:
  1238. /* do nothing */
  1239. break;
  1240. }
  1241. return 0;
  1242. }
  1243. /**
  1244. * rivafb_fillrect - hardware accelerated color fill function
  1245. * @info: pointer to fb_info structure
  1246. * @rect: pointer to fb_fillrect structure
  1247. *
  1248. * DESCRIPTION:
  1249. * This function fills up a region of framebuffer memory with a solid
  1250. * color with a choice of two different ROP's, copy or invert.
  1251. *
  1252. * CALLED FROM:
  1253. * framebuffer hook
  1254. */
  1255. static void rivafb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
  1256. {
  1257. struct riva_par *par = (struct riva_par *) info->par;
  1258. u_int color, rop = 0;
  1259. if ((info->flags & FBINFO_HWACCEL_DISABLED)) {
  1260. cfb_fillrect(info, rect);
  1261. return;
  1262. }
  1263. if (info->var.bits_per_pixel == 8)
  1264. color = rect->color;
  1265. else {
  1266. if (par->riva.Architecture != NV_ARCH_03)
  1267. color = ((u32 *)info->pseudo_palette)[rect->color];
  1268. else
  1269. color = par->palette[rect->color];
  1270. }
  1271. switch (rect->rop) {
  1272. case ROP_XOR:
  1273. rop = 0x66;
  1274. break;
  1275. case ROP_COPY:
  1276. default:
  1277. rop = 0xCC;
  1278. break;
  1279. }
  1280. riva_set_rop_solid(par, rop);
  1281. RIVA_FIFO_FREE(par->riva, Bitmap, 1);
  1282. NV_WR32(&par->riva.Bitmap->Color1A, 0, color);
  1283. RIVA_FIFO_FREE(par->riva, Bitmap, 2);
  1284. NV_WR32(&par->riva.Bitmap->UnclippedRectangle[0].TopLeft, 0,
  1285. (rect->dx << 16) | rect->dy);
  1286. mb();
  1287. NV_WR32(&par->riva.Bitmap->UnclippedRectangle[0].WidthHeight, 0,
  1288. (rect->width << 16) | rect->height);
  1289. mb();
  1290. riva_set_rop_solid(par, 0xcc);
  1291. }
  1292. /**
  1293. * rivafb_copyarea - hardware accelerated blit function
  1294. * @info: pointer to fb_info structure
  1295. * @region: pointer to fb_copyarea structure
  1296. *
  1297. * DESCRIPTION:
  1298. * This copies an area of pixels from one location to another
  1299. *
  1300. * CALLED FROM:
  1301. * framebuffer hook
  1302. */
  1303. static void rivafb_copyarea(struct fb_info *info, const struct fb_copyarea *region)
  1304. {
  1305. struct riva_par *par = (struct riva_par *) info->par;
  1306. if ((info->flags & FBINFO_HWACCEL_DISABLED)) {
  1307. cfb_copyarea(info, region);
  1308. return;
  1309. }
  1310. RIVA_FIFO_FREE(par->riva, Blt, 3);
  1311. NV_WR32(&par->riva.Blt->TopLeftSrc, 0,
  1312. (region->sy << 16) | region->sx);
  1313. NV_WR32(&par->riva.Blt->TopLeftDst, 0,
  1314. (region->dy << 16) | region->dx);
  1315. mb();
  1316. NV_WR32(&par->riva.Blt->WidthHeight, 0,
  1317. (region->height << 16) | region->width);
  1318. mb();
  1319. }
  1320. static inline void convert_bgcolor_16(u32 *col)
  1321. {
  1322. *col = ((*col & 0x0000F800) << 8)
  1323. | ((*col & 0x00007E0) << 5)
  1324. | ((*col & 0x0000001F) << 3)
  1325. | 0xFF000000;
  1326. mb();
  1327. }
  1328. /**
  1329. * rivafb_imageblit: hardware accelerated color expand function
  1330. * @info: pointer to fb_info structure
  1331. * @image: pointer to fb_image structure
  1332. *
  1333. * DESCRIPTION:
  1334. * If the source is a monochrome bitmap, the function fills up a a region
  1335. * of framebuffer memory with pixels whose color is determined by the bit
  1336. * setting of the bitmap, 1 - foreground, 0 - background.
  1337. *
  1338. * If the source is not a monochrome bitmap, color expansion is not done.
  1339. * In this case, it is channeled to a software function.
  1340. *
  1341. * CALLED FROM:
  1342. * framebuffer hook
  1343. */
  1344. static void rivafb_imageblit(struct fb_info *info,
  1345. const struct fb_image *image)
  1346. {
  1347. struct riva_par *par = (struct riva_par *) info->par;
  1348. u32 fgx = 0, bgx = 0, width, tmp;
  1349. u8 *cdat = (u8 *) image->data;
  1350. volatile u32 __iomem *d;
  1351. int i, size;
  1352. if ((info->flags & FBINFO_HWACCEL_DISABLED) || image->depth != 1) {
  1353. cfb_imageblit(info, image);
  1354. return;
  1355. }
  1356. switch (info->var.bits_per_pixel) {
  1357. case 8:
  1358. fgx = image->fg_color;
  1359. bgx = image->bg_color;
  1360. break;
  1361. case 16:
  1362. case 32:
  1363. if (par->riva.Architecture != NV_ARCH_03) {
  1364. fgx = ((u32 *)info->pseudo_palette)[image->fg_color];
  1365. bgx = ((u32 *)info->pseudo_palette)[image->bg_color];
  1366. } else {
  1367. fgx = par->palette[image->fg_color];
  1368. bgx = par->palette[image->bg_color];
  1369. }
  1370. if (info->var.green.length == 6)
  1371. convert_bgcolor_16(&bgx);
  1372. break;
  1373. }
  1374. RIVA_FIFO_FREE(par->riva, Bitmap, 7);
  1375. NV_WR32(&par->riva.Bitmap->ClipE.TopLeft, 0,
  1376. (image->dy << 16) | (image->dx & 0xFFFF));
  1377. NV_WR32(&par->riva.Bitmap->ClipE.BottomRight, 0,
  1378. (((image->dy + image->height) << 16) |
  1379. ((image->dx + image->width) & 0xffff)));
  1380. NV_WR32(&par->riva.Bitmap->Color0E, 0, bgx);
  1381. NV_WR32(&par->riva.Bitmap->Color1E, 0, fgx);
  1382. NV_WR32(&par->riva.Bitmap->WidthHeightInE, 0,
  1383. (image->height << 16) | ((image->width + 31) & ~31));
  1384. NV_WR32(&par->riva.Bitmap->WidthHeightOutE, 0,
  1385. (image->height << 16) | ((image->width + 31) & ~31));
  1386. NV_WR32(&par->riva.Bitmap->PointE, 0,
  1387. (image->dy << 16) | (image->dx & 0xFFFF));
  1388. d = &par->riva.Bitmap->MonochromeData01E;
  1389. width = (image->width + 31)/32;
  1390. size = width * image->height;
  1391. while (size >= 16) {
  1392. RIVA_FIFO_FREE(par->riva, Bitmap, 16);
  1393. for (i = 0; i < 16; i++) {
  1394. tmp = *((u32 *)cdat);
  1395. cdat = (u8 *)((u32 *)cdat + 1);
  1396. reverse_order(&tmp);
  1397. NV_WR32(d, i*4, tmp);
  1398. }
  1399. size -= 16;
  1400. }
  1401. if (size) {
  1402. RIVA_FIFO_FREE(par->riva, Bitmap, size);
  1403. for (i = 0; i < size; i++) {
  1404. tmp = *((u32 *) cdat);
  1405. cdat = (u8 *)((u32 *)cdat + 1);
  1406. reverse_order(&tmp);
  1407. NV_WR32(d, i*4, tmp);
  1408. }
  1409. }
  1410. }
  1411. /**
  1412. * rivafb_cursor - hardware cursor function
  1413. * @info: pointer to info structure
  1414. * @cursor: pointer to fbcursor structure
  1415. *
  1416. * DESCRIPTION:
  1417. * A cursor function that supports displaying a cursor image via hardware.
  1418. * Within the kernel, copy and invert rops are supported. If exported
  1419. * to user space, only the copy rop will be supported.
  1420. *
  1421. * CALLED FROM
  1422. * framebuffer hook
  1423. */
  1424. static int rivafb_cursor(struct fb_info *info, struct fb_cursor *cursor)
  1425. {
  1426. struct riva_par *par = (struct riva_par *) info->par;
  1427. u8 data[MAX_CURS * MAX_CURS/8];
  1428. int i, set = cursor->set;
  1429. u16 fg, bg;
  1430. if (cursor->image.width > MAX_CURS || cursor->image.height > MAX_CURS)
  1431. return -ENXIO;
  1432. par->riva.ShowHideCursor(&par->riva, 0);
  1433. if (par->cursor_reset) {
  1434. set = FB_CUR_SETALL;
  1435. par->cursor_reset = 0;
  1436. }
  1437. if (set & FB_CUR_SETSIZE)
  1438. memset_io(par->riva.CURSOR, 0, MAX_CURS * MAX_CURS * 2);
  1439. if (set & FB_CUR_SETPOS) {
  1440. u32 xx, yy, temp;
  1441. yy = cursor->image.dy - info->var.yoffset;
  1442. xx = cursor->image.dx - info->var.xoffset;
  1443. temp = xx & 0xFFFF;
  1444. temp |= yy << 16;
  1445. NV_WR32(par->riva.PRAMDAC, 0x0000300, temp);
  1446. }
  1447. if (set & (FB_CUR_SETSHAPE | FB_CUR_SETCMAP | FB_CUR_SETIMAGE)) {
  1448. u32 bg_idx = cursor->image.bg_color;
  1449. u32 fg_idx = cursor->image.fg_color;
  1450. u32 s_pitch = (cursor->image.width+7) >> 3;
  1451. u32 d_pitch = MAX_CURS/8;
  1452. u8 *dat = (u8 *) cursor->image.data;
  1453. u8 *msk = (u8 *) cursor->mask;
  1454. u8 *src;
  1455. src = kmalloc(s_pitch * cursor->image.height, GFP_ATOMIC);
  1456. if (src) {
  1457. switch (cursor->rop) {
  1458. case ROP_XOR:
  1459. for (i = 0; i < s_pitch * cursor->image.height; i++)
  1460. src[i] = dat[i] ^ msk[i];
  1461. break;
  1462. case ROP_COPY:
  1463. default:
  1464. for (i = 0; i < s_pitch * cursor->image.height; i++)
  1465. src[i] = dat[i] & msk[i];
  1466. break;
  1467. }
  1468. fb_pad_aligned_buffer(data, d_pitch, src, s_pitch,
  1469. cursor->image.height);
  1470. bg = ((info->cmap.red[bg_idx] & 0xf8) << 7) |
  1471. ((info->cmap.green[bg_idx] & 0xf8) << 2) |
  1472. ((info->cmap.blue[bg_idx] & 0xf8) >> 3) |
  1473. 1 << 15;
  1474. fg = ((info->cmap.red[fg_idx] & 0xf8) << 7) |
  1475. ((info->cmap.green[fg_idx] & 0xf8) << 2) |
  1476. ((info->cmap.blue[fg_idx] & 0xf8) >> 3) |
  1477. 1 << 15;
  1478. par->riva.LockUnlock(&par->riva, 0);
  1479. rivafb_load_cursor_image(par, data, bg, fg,
  1480. cursor->image.width,
  1481. cursor->image.height);
  1482. kfree(src);
  1483. }
  1484. }
  1485. if (cursor->enable)
  1486. par->riva.ShowHideCursor(&par->riva, 1);
  1487. return 0;
  1488. }
  1489. static int rivafb_sync(struct fb_info *info)
  1490. {
  1491. struct riva_par *par = (struct riva_par *)info->par;
  1492. wait_for_idle(par);
  1493. return 0;
  1494. }
  1495. /* ------------------------------------------------------------------------- *
  1496. *
  1497. * initialization helper functions
  1498. *
  1499. * ------------------------------------------------------------------------- */
  1500. /* kernel interface */
  1501. static struct fb_ops riva_fb_ops = {
  1502. .owner = THIS_MODULE,
  1503. .fb_open = rivafb_open,
  1504. .fb_release = rivafb_release,
  1505. .fb_check_var = rivafb_check_var,
  1506. .fb_set_par = rivafb_set_par,
  1507. .fb_setcolreg = rivafb_setcolreg,
  1508. .fb_pan_display = rivafb_pan_display,
  1509. .fb_blank = rivafb_blank,
  1510. .fb_fillrect = rivafb_fillrect,
  1511. .fb_copyarea = rivafb_copyarea,
  1512. .fb_imageblit = rivafb_imageblit,
  1513. .fb_cursor = rivafb_cursor,
  1514. .fb_sync = rivafb_sync,
  1515. };
  1516. static int __devinit riva_set_fbinfo(struct fb_info *info)
  1517. {
  1518. unsigned int cmap_len;
  1519. struct riva_par *par = (struct riva_par *) info->par;
  1520. NVTRACE_ENTER();
  1521. info->flags = FBINFO_DEFAULT
  1522. | FBINFO_HWACCEL_XPAN
  1523. | FBINFO_HWACCEL_YPAN
  1524. | FBINFO_HWACCEL_COPYAREA
  1525. | FBINFO_HWACCEL_FILLRECT
  1526. | FBINFO_HWACCEL_IMAGEBLIT;
  1527. /* Accel seems to not work properly on NV30 yet...*/
  1528. if ((par->riva.Architecture == NV_ARCH_30) || noaccel) {
  1529. printk(KERN_DEBUG PFX "disabling acceleration\n");
  1530. info->flags |= FBINFO_HWACCEL_DISABLED;
  1531. }
  1532. info->var = rivafb_default_var;
  1533. info->fix.visual = (info->var.bits_per_pixel == 8) ?
  1534. FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_DIRECTCOLOR;
  1535. info->pseudo_palette = par->pseudo_palette;
  1536. cmap_len = riva_get_cmap_len(&info->var);
  1537. fb_alloc_cmap(&info->cmap, cmap_len, 0);
  1538. info->pixmap.size = 8 * 1024;
  1539. info->pixmap.buf_align = 4;
  1540. info->pixmap.access_align = 32;
  1541. info->pixmap.flags = FB_PIXMAP_SYSTEM;
  1542. info->var.yres_virtual = -1;
  1543. NVTRACE_LEAVE();
  1544. return (rivafb_check_var(&info->var, info));
  1545. }
  1546. #ifdef CONFIG_PPC_OF
  1547. static int __devinit riva_get_EDID_OF(struct fb_info *info, struct pci_dev *pd)
  1548. {
  1549. struct riva_par *par = (struct riva_par *) info->par;
  1550. struct device_node *dp;
  1551. unsigned char *pedid = NULL;
  1552. unsigned char *disptype = NULL;
  1553. static char *propnames[] = {
  1554. "DFP,EDID", "LCD,EDID", "EDID", "EDID1", "EDID,B", "EDID,A", NULL };
  1555. int i;
  1556. NVTRACE_ENTER();
  1557. dp = pci_device_to_OF_node(pd);
  1558. for (; dp != NULL; dp = dp->child) {
  1559. disptype = (unsigned char *)get_property(dp, "display-type", NULL);
  1560. if (disptype == NULL)
  1561. continue;
  1562. if (strncmp(disptype, "LCD", 3) != 0)
  1563. continue;
  1564. for (i = 0; propnames[i] != NULL; ++i) {
  1565. pedid = (unsigned char *)
  1566. get_property(dp, propnames[i], NULL);
  1567. if (pedid != NULL) {
  1568. par->EDID = pedid;
  1569. NVTRACE("LCD found.\n");
  1570. return 1;
  1571. }
  1572. }
  1573. }
  1574. NVTRACE_LEAVE();
  1575. return 0;
  1576. }
  1577. #endif /* CONFIG_PPC_OF */
  1578. #if defined(CONFIG_FB_RIVA_I2C) && !defined(CONFIG_PPC_OF)
  1579. static int __devinit riva_get_EDID_i2c(struct fb_info *info)
  1580. {
  1581. struct riva_par *par = (struct riva_par *) info->par;
  1582. struct fb_var_screeninfo var;
  1583. int i;
  1584. NVTRACE_ENTER();
  1585. riva_create_i2c_busses(par);
  1586. for (i = 0; i < par->bus; i++) {
  1587. riva_probe_i2c_connector(par, i+1, &par->EDID);
  1588. if (par->EDID && !fb_parse_edid(par->EDID, &var)) {
  1589. printk(PFX "Found EDID Block from BUS %i\n", i);
  1590. break;
  1591. }
  1592. }
  1593. NVTRACE_LEAVE();
  1594. return (par->EDID) ? 1 : 0;
  1595. }
  1596. #endif /* CONFIG_FB_RIVA_I2C */
  1597. static void __devinit riva_update_default_var(struct fb_var_screeninfo *var,
  1598. struct fb_info *info)
  1599. {
  1600. struct fb_monspecs *specs = &info->monspecs;
  1601. struct fb_videomode modedb;
  1602. NVTRACE_ENTER();
  1603. /* respect mode options */
  1604. if (mode_option) {
  1605. fb_find_mode(var, info, mode_option,
  1606. specs->modedb, specs->modedb_len,
  1607. NULL, 8);
  1608. } else if (specs->modedb != NULL) {
  1609. /* get preferred timing */
  1610. if (info->monspecs.misc & FB_MISC_1ST_DETAIL) {
  1611. int i;
  1612. for (i = 0; i < specs->modedb_len; i++) {
  1613. if (specs->modedb[i].flag & FB_MODE_IS_FIRST) {
  1614. modedb = specs->modedb[i];
  1615. break;
  1616. }
  1617. }
  1618. } else {
  1619. /* otherwise, get first mode in database */
  1620. modedb = specs->modedb[0];
  1621. }
  1622. var->bits_per_pixel = 8;
  1623. riva_update_var(var, &modedb);
  1624. }
  1625. NVTRACE_LEAVE();
  1626. }
  1627. static void __devinit riva_get_EDID(struct fb_info *info, struct pci_dev *pdev)
  1628. {
  1629. NVTRACE_ENTER();
  1630. #ifdef CONFIG_PPC_OF
  1631. if (!riva_get_EDID_OF(info, pdev))
  1632. printk(PFX "could not retrieve EDID from OF\n");
  1633. #elif defined(CONFIG_FB_RIVA_I2C)
  1634. if (!riva_get_EDID_i2c(info))
  1635. printk(PFX "could not retrieve EDID from DDC/I2C\n");
  1636. #endif
  1637. NVTRACE_LEAVE();
  1638. }
  1639. static void __devinit riva_get_edidinfo(struct fb_info *info)
  1640. {
  1641. struct fb_var_screeninfo *var = &rivafb_default_var;
  1642. struct riva_par *par = (struct riva_par *) info->par;
  1643. fb_edid_to_monspecs(par->EDID, &info->monspecs);
  1644. fb_videomode_to_modelist(info->monspecs.modedb, info->monspecs.modedb_len,
  1645. &info->modelist);
  1646. riva_update_default_var(var, info);
  1647. /* if user specified flatpanel, we respect that */
  1648. if (info->monspecs.input & FB_DISP_DDI)
  1649. par->FlatPanel = 1;
  1650. }
  1651. /* ------------------------------------------------------------------------- *
  1652. *
  1653. * PCI bus
  1654. *
  1655. * ------------------------------------------------------------------------- */
  1656. static u32 __devinit riva_get_arch(struct pci_dev *pd)
  1657. {
  1658. u32 arch = 0;
  1659. switch (pd->device & 0x0ff0) {
  1660. case 0x0100: /* GeForce 256 */
  1661. case 0x0110: /* GeForce2 MX */
  1662. case 0x0150: /* GeForce2 */
  1663. case 0x0170: /* GeForce4 MX */
  1664. case 0x0180: /* GeForce4 MX (8x AGP) */
  1665. case 0x01A0: /* nForce */
  1666. case 0x01F0: /* nForce2 */
  1667. arch = NV_ARCH_10;
  1668. break;
  1669. case 0x0200: /* GeForce3 */
  1670. case 0x0250: /* GeForce4 Ti */
  1671. case 0x0280: /* GeForce4 Ti (8x AGP) */
  1672. arch = NV_ARCH_20;
  1673. break;
  1674. case 0x0300: /* GeForceFX 5800 */
  1675. case 0x0310: /* GeForceFX 5600 */
  1676. case 0x0320: /* GeForceFX 5200 */
  1677. case 0x0330: /* GeForceFX 5900 */
  1678. case 0x0340: /* GeForceFX 5700 */
  1679. arch = NV_ARCH_30;
  1680. break;
  1681. case 0x0020: /* TNT, TNT2 */
  1682. arch = NV_ARCH_04;
  1683. break;
  1684. case 0x0010: /* Riva128 */
  1685. arch = NV_ARCH_03;
  1686. break;
  1687. default: /* unknown architecture */
  1688. break;
  1689. }
  1690. return arch;
  1691. }
  1692. static int __devinit rivafb_probe(struct pci_dev *pd,
  1693. const struct pci_device_id *ent)
  1694. {
  1695. struct riva_par *default_par;
  1696. struct fb_info *info;
  1697. int ret;
  1698. NVTRACE_ENTER();
  1699. assert(pd != NULL);
  1700. info = framebuffer_alloc(sizeof(struct riva_par), &pd->dev);
  1701. if (!info) {
  1702. printk (KERN_ERR PFX "could not allocate memory\n");
  1703. ret = -ENOMEM;
  1704. goto err_ret;
  1705. }
  1706. default_par = (struct riva_par *) info->par;
  1707. default_par->pdev = pd;
  1708. info->pixmap.addr = kmalloc(8 * 1024, GFP_KERNEL);
  1709. if (info->pixmap.addr == NULL) {
  1710. ret = -ENOMEM;
  1711. goto err_framebuffer_release;
  1712. }
  1713. memset(info->pixmap.addr, 0, 8 * 1024);
  1714. ret = pci_enable_device(pd);
  1715. if (ret < 0) {
  1716. printk(KERN_ERR PFX "cannot enable PCI device\n");
  1717. goto err_free_pixmap;
  1718. }
  1719. ret = pci_request_regions(pd, "rivafb");
  1720. if (ret < 0) {
  1721. printk(KERN_ERR PFX "cannot request PCI regions\n");
  1722. goto err_disable_device;
  1723. }
  1724. default_par->riva.Architecture = riva_get_arch(pd);
  1725. default_par->Chipset = (pd->vendor << 16) | pd->device;
  1726. printk(KERN_INFO PFX "nVidia device/chipset %X\n",default_par->Chipset);
  1727. if(default_par->riva.Architecture == 0) {
  1728. printk(KERN_ERR PFX "unknown NV_ARCH\n");
  1729. ret=-ENODEV;
  1730. goto err_release_region;
  1731. }
  1732. if(default_par->riva.Architecture == NV_ARCH_10 ||
  1733. default_par->riva.Architecture == NV_ARCH_20 ||
  1734. default_par->riva.Architecture == NV_ARCH_30) {
  1735. sprintf(rivafb_fix.id, "NV%x", (pd->device & 0x0ff0) >> 4);
  1736. } else {
  1737. sprintf(rivafb_fix.id, "NV%x", default_par->riva.Architecture);
  1738. }
  1739. default_par->FlatPanel = flatpanel;
  1740. if (flatpanel == 1)
  1741. printk(KERN_INFO PFX "flatpanel support enabled\n");
  1742. default_par->forceCRTC = forceCRTC;
  1743. rivafb_fix.mmio_len = pci_resource_len(pd, 0);
  1744. rivafb_fix.smem_len = pci_resource_len(pd, 1);
  1745. {
  1746. /* enable IO and mem if not already done */
  1747. unsigned short cmd;
  1748. pci_read_config_word(pd, PCI_COMMAND, &cmd);
  1749. cmd |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
  1750. pci_write_config_word(pd, PCI_COMMAND, cmd);
  1751. }
  1752. rivafb_fix.mmio_start = pci_resource_start(pd, 0);
  1753. rivafb_fix.smem_start = pci_resource_start(pd, 1);
  1754. default_par->ctrl_base = ioremap(rivafb_fix.mmio_start,
  1755. rivafb_fix.mmio_len);
  1756. if (!default_par->ctrl_base) {
  1757. printk(KERN_ERR PFX "cannot ioremap MMIO base\n");
  1758. ret = -EIO;
  1759. goto err_release_region;
  1760. }
  1761. switch (default_par->riva.Architecture) {
  1762. case NV_ARCH_03:
  1763. /* Riva128's PRAMIN is in the "framebuffer" space
  1764. * Since these cards were never made with more than 8 megabytes
  1765. * we can safely allocate this separately.
  1766. */
  1767. default_par->riva.PRAMIN = ioremap(rivafb_fix.smem_start + 0x00C00000, 0x00008000);
  1768. if (!default_par->riva.PRAMIN) {
  1769. printk(KERN_ERR PFX "cannot ioremap PRAMIN region\n");
  1770. ret = -EIO;
  1771. goto err_iounmap_ctrl_base;
  1772. }
  1773. break;
  1774. case NV_ARCH_04:
  1775. case NV_ARCH_10:
  1776. case NV_ARCH_20:
  1777. case NV_ARCH_30:
  1778. default_par->riva.PCRTC0 =
  1779. (u32 __iomem *)(default_par->ctrl_base + 0x00600000);
  1780. default_par->riva.PRAMIN =
  1781. (u32 __iomem *)(default_par->ctrl_base + 0x00710000);
  1782. break;
  1783. }
  1784. riva_common_setup(default_par);
  1785. if (default_par->riva.Architecture == NV_ARCH_03) {
  1786. default_par->riva.PCRTC = default_par->riva.PCRTC0
  1787. = default_par->riva.PGRAPH;
  1788. }
  1789. rivafb_fix.smem_len = riva_get_memlen(default_par) * 1024;
  1790. default_par->dclk_max = riva_get_maxdclk(default_par) * 1000;
  1791. info->screen_base = ioremap(rivafb_fix.smem_start,
  1792. rivafb_fix.smem_len);
  1793. if (!info->screen_base) {
  1794. printk(KERN_ERR PFX "cannot ioremap FB base\n");
  1795. ret = -EIO;
  1796. goto err_iounmap_pramin;
  1797. }
  1798. #ifdef CONFIG_MTRR
  1799. if (!nomtrr) {
  1800. default_par->mtrr.vram = mtrr_add(rivafb_fix.smem_start,
  1801. rivafb_fix.smem_len,
  1802. MTRR_TYPE_WRCOMB, 1);
  1803. if (default_par->mtrr.vram < 0) {
  1804. printk(KERN_ERR PFX "unable to setup MTRR\n");
  1805. } else {
  1806. default_par->mtrr.vram_valid = 1;
  1807. /* let there be speed */
  1808. printk(KERN_INFO PFX "RIVA MTRR set to ON\n");
  1809. }
  1810. }
  1811. #endif /* CONFIG_MTRR */
  1812. info->fbops = &riva_fb_ops;
  1813. info->fix = rivafb_fix;
  1814. riva_get_EDID(info, pd);
  1815. riva_get_edidinfo(info);
  1816. ret=riva_set_fbinfo(info);
  1817. if (ret < 0) {
  1818. printk(KERN_ERR PFX "error setting initial video mode\n");
  1819. goto err_iounmap_screen_base;
  1820. }
  1821. fb_destroy_modedb(info->monspecs.modedb);
  1822. info->monspecs.modedb = NULL;
  1823. ret = register_framebuffer(info);
  1824. if (ret < 0) {
  1825. printk(KERN_ERR PFX
  1826. "error registering riva framebuffer\n");
  1827. goto err_iounmap_screen_base;
  1828. }
  1829. pci_set_drvdata(pd, info);
  1830. printk(KERN_INFO PFX
  1831. "PCI nVidia %s framebuffer ver %s (%dMB @ 0x%lX)\n",
  1832. info->fix.id,
  1833. RIVAFB_VERSION,
  1834. info->fix.smem_len / (1024 * 1024),
  1835. info->fix.smem_start);
  1836. #ifdef CONFIG_PMAC_BACKLIGHT
  1837. if (default_par->FlatPanel && _machine == _MACH_Pmac)
  1838. register_backlight_controller(&riva_backlight_controller,
  1839. default_par, "mnca");
  1840. #endif
  1841. NVTRACE_LEAVE();
  1842. return 0;
  1843. err_iounmap_screen_base:
  1844. #ifdef CONFIG_FB_RIVA_I2C
  1845. riva_delete_i2c_busses((struct riva_par *) info->par);
  1846. #endif
  1847. iounmap(info->screen_base);
  1848. err_iounmap_pramin:
  1849. if (default_par->riva.Architecture == NV_ARCH_03)
  1850. iounmap(default_par->riva.PRAMIN);
  1851. err_iounmap_ctrl_base:
  1852. iounmap(default_par->ctrl_base);
  1853. err_release_region:
  1854. pci_release_regions(pd);
  1855. err_disable_device:
  1856. pci_disable_device(pd);
  1857. err_free_pixmap:
  1858. kfree(info->pixmap.addr);
  1859. err_framebuffer_release:
  1860. framebuffer_release(info);
  1861. err_ret:
  1862. return ret;
  1863. }
  1864. static void __exit rivafb_remove(struct pci_dev *pd)
  1865. {
  1866. struct fb_info *info = pci_get_drvdata(pd);
  1867. struct riva_par *par = (struct riva_par *) info->par;
  1868. NVTRACE_ENTER();
  1869. if (!info)
  1870. return;
  1871. #ifdef CONFIG_FB_RIVA_I2C
  1872. riva_delete_i2c_busses(par);
  1873. kfree(par->EDID);
  1874. #endif
  1875. unregister_framebuffer(info);
  1876. #ifdef CONFIG_MTRR
  1877. if (par->mtrr.vram_valid)
  1878. mtrr_del(par->mtrr.vram, info->fix.smem_start,
  1879. info->fix.smem_len);
  1880. #endif /* CONFIG_MTRR */
  1881. iounmap(par->ctrl_base);
  1882. iounmap(info->screen_base);
  1883. if (par->riva.Architecture == NV_ARCH_03)
  1884. iounmap(par->riva.PRAMIN);
  1885. pci_release_regions(pd);
  1886. pci_disable_device(pd);
  1887. kfree(info->pixmap.addr);
  1888. framebuffer_release(info);
  1889. pci_set_drvdata(pd, NULL);
  1890. NVTRACE_LEAVE();
  1891. }
  1892. /* ------------------------------------------------------------------------- *
  1893. *
  1894. * initialization
  1895. *
  1896. * ------------------------------------------------------------------------- */
  1897. #ifndef MODULE
  1898. static int __init rivafb_setup(char *options)
  1899. {
  1900. char *this_opt;
  1901. NVTRACE_ENTER();
  1902. if (!options || !*options)
  1903. return 0;
  1904. while ((this_opt = strsep(&options, ",")) != NULL) {
  1905. if (!strncmp(this_opt, "forceCRTC", 9)) {
  1906. char *p;
  1907. p = this_opt + 9;
  1908. if (!*p || !*(++p)) continue;
  1909. forceCRTC = *p - '0';
  1910. if (forceCRTC < 0 || forceCRTC > 1)
  1911. forceCRTC = -1;
  1912. } else if (!strncmp(this_opt, "flatpanel", 9)) {
  1913. flatpanel = 1;
  1914. #ifdef CONFIG_MTRR
  1915. } else if (!strncmp(this_opt, "nomtrr", 6)) {
  1916. nomtrr = 1;
  1917. #endif
  1918. } else if (!strncmp(this_opt, "strictmode", 10)) {
  1919. strictmode = 1;
  1920. } else if (!strncmp(this_opt, "noaccel", 7)) {
  1921. noaccel = 1;
  1922. } else
  1923. mode_option = this_opt;
  1924. }
  1925. NVTRACE_LEAVE();
  1926. return 0;
  1927. }
  1928. #endif /* !MODULE */
  1929. static struct pci_driver rivafb_driver = {
  1930. .name = "rivafb",
  1931. .id_table = rivafb_pci_tbl,
  1932. .probe = rivafb_probe,
  1933. .remove = __exit_p(rivafb_remove),
  1934. };
  1935. /* ------------------------------------------------------------------------- *
  1936. *
  1937. * modularization
  1938. *
  1939. * ------------------------------------------------------------------------- */
  1940. static int __devinit rivafb_init(void)
  1941. {
  1942. #ifndef MODULE
  1943. char *option = NULL;
  1944. if (fb_get_options("rivafb", &option))
  1945. return -ENODEV;
  1946. rivafb_setup(option);
  1947. #endif
  1948. return pci_register_driver(&rivafb_driver);
  1949. }
  1950. module_init(rivafb_init);
  1951. #ifdef MODULE
  1952. static void __exit rivafb_exit(void)
  1953. {
  1954. pci_unregister_driver(&rivafb_driver);
  1955. }
  1956. module_exit(rivafb_exit);
  1957. #endif /* MODULE */
  1958. module_param(noaccel, bool, 0);
  1959. MODULE_PARM_DESC(noaccel, "bool: disable acceleration");
  1960. module_param(flatpanel, int, 0);
  1961. MODULE_PARM_DESC(flatpanel, "Enables experimental flat panel support for some chipsets. (0 or 1=enabled) (default=0)");
  1962. module_param(forceCRTC, int, 0);
  1963. MODULE_PARM_DESC(forceCRTC, "Forces usage of a particular CRTC in case autodetection fails. (0 or 1) (default=autodetect)");
  1964. #ifdef CONFIG_MTRR
  1965. module_param(nomtrr, bool, 0);
  1966. MODULE_PARM_DESC(nomtrr, "Disables MTRR support (0 or 1=disabled) (default=0)");
  1967. #endif
  1968. module_param(strictmode, bool, 0);
  1969. MODULE_PARM_DESC(strictmode, "Only use video modes from EDID");
  1970. MODULE_AUTHOR("Ani Joshi, maintainer");
  1971. MODULE_DESCRIPTION("Framebuffer driver for nVidia Riva 128, TNT, TNT2, and the GeForce series");
  1972. MODULE_LICENSE("GPL");