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