fbdev.c 59 KB

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