fbdev.c 61 KB

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