fbdev.c 58 KB

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