fbdev.c 59 KB

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