fbdev.c 58 KB

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