fbdev.c 59 KB

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