fbdev.c 60 KB

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