fbdev.c 61 KB

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