fbdev.c 59 KB

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