matroxfb_base.c 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. *
  4. * Hardware accelerated Matrox Millennium I, II, Mystique, G100, G200 and G400
  5. *
  6. * (c) 1998-2002 Petr Vandrovec <vandrove@vc.cvut.cz>
  7. *
  8. * Portions Copyright (c) 2001 Matrox Graphics Inc.
  9. *
  10. * Version: 1.65 2002/08/14
  11. *
  12. * MTRR stuff: 1998 Tom Rini <trini@kernel.crashing.org>
  13. *
  14. * Contributors: "menion?" <menion@mindless.com>
  15. * Betatesting, fixes, ideas
  16. *
  17. * "Kurt Garloff" <garloff@suse.de>
  18. * Betatesting, fixes, ideas, videomodes, videomodes timmings
  19. *
  20. * "Tom Rini" <trini@kernel.crashing.org>
  21. * MTRR stuff, PPC cleanups, betatesting, fixes, ideas
  22. *
  23. * "Bibek Sahu" <scorpio@dodds.net>
  24. * Access device through readb|w|l and write b|w|l
  25. * Extensive debugging stuff
  26. *
  27. * "Daniel Haun" <haund@usa.net>
  28. * Testing, hardware cursor fixes
  29. *
  30. * "Scott Wood" <sawst46+@pitt.edu>
  31. * Fixes
  32. *
  33. * "Gerd Knorr" <kraxel@goldbach.isdn.cs.tu-berlin.de>
  34. * Betatesting
  35. *
  36. * "Kelly French" <targon@hazmat.com>
  37. * "Fernando Herrera" <fherrera@eurielec.etsit.upm.es>
  38. * Betatesting, bug reporting
  39. *
  40. * "Pablo Bianucci" <pbian@pccp.com.ar>
  41. * Fixes, ideas, betatesting
  42. *
  43. * "Inaky Perez Gonzalez" <inaky@peloncho.fis.ucm.es>
  44. * Fixes, enhandcements, ideas, betatesting
  45. *
  46. * "Ryuichi Oikawa" <roikawa@rr.iiij4u.or.jp>
  47. * PPC betatesting, PPC support, backward compatibility
  48. *
  49. * "Paul Womar" <Paul@pwomar.demon.co.uk>
  50. * "Owen Waller" <O.Waller@ee.qub.ac.uk>
  51. * PPC betatesting
  52. *
  53. * "Thomas Pornin" <pornin@bolet.ens.fr>
  54. * Alpha betatesting
  55. *
  56. * "Pieter van Leuven" <pvl@iae.nl>
  57. * "Ulf Jaenicke-Roessler" <ujr@physik.phy.tu-dresden.de>
  58. * G100 testing
  59. *
  60. * "H. Peter Arvin" <hpa@transmeta.com>
  61. * Ideas
  62. *
  63. * "Cort Dougan" <cort@cs.nmt.edu>
  64. * CHRP fixes and PReP cleanup
  65. *
  66. * "Mark Vojkovich" <mvojkovi@ucsd.edu>
  67. * G400 support
  68. *
  69. * "Samuel Hocevar" <sam@via.ecp.fr>
  70. * Fixes
  71. *
  72. * "Anton Altaparmakov" <AntonA@bigfoot.com>
  73. * G400 MAX/non-MAX distinction
  74. *
  75. * "Ken Aaker" <kdaaker@rchland.vnet.ibm.com>
  76. * memtype extension (needed for GXT130P RS/6000 adapter)
  77. *
  78. * "Uns Lider" <unslider@miranda.org>
  79. * G100 PLNWT fixes
  80. *
  81. * "Denis Zaitsev" <zzz@cd-club.ru>
  82. * Fixes
  83. *
  84. * "Mike Pieper" <mike@pieper-family.de>
  85. * TVOut enhandcements, V4L2 control interface.
  86. *
  87. * "Diego Biurrun" <diego@biurrun.de>
  88. * DFP testing
  89. *
  90. * (following author is not in any relation with this code, but his code
  91. * is included in this driver)
  92. *
  93. * Based on framebuffer driver for VBE 2.0 compliant graphic boards
  94. * (c) 1998 Gerd Knorr <kraxel@cs.tu-berlin.de>
  95. *
  96. * (following author is not in any relation with this code, but his ideas
  97. * were used when writing this driver)
  98. *
  99. * FreeVBE/AF (Matrox), "Shawn Hargreaves" <shawn@talula.demon.co.uk>
  100. *
  101. */
  102. #include <linux/aperture.h>
  103. #include <linux/export.h>
  104. #include <linux/version.h>
  105. #include "matroxfb_base.h"
  106. #include "matroxfb_misc.h"
  107. #include "matroxfb_accel.h"
  108. #include "matroxfb_DAC1064.h"
  109. #include "matroxfb_Ti3026.h"
  110. #include "matroxfb_maven.h"
  111. #include "matroxfb_crtc2.h"
  112. #include "matroxfb_g450.h"
  113. #include <linux/matroxfb.h>
  114. #include <linux/interrupt.h>
  115. #include <linux/nvram.h>
  116. #include <linux/slab.h>
  117. #include <linux/uaccess.h>
  118. #ifdef CONFIG_PPC_PMAC
  119. #include <asm/machdep.h>
  120. static int default_vmode = VMODE_NVRAM;
  121. static int default_cmode = CMODE_NVRAM;
  122. #endif
  123. static void matroxfb_unregister_device(struct matrox_fb_info* minfo);
  124. /* --------------------------------------------------------------------- */
  125. /*
  126. * card parameters
  127. */
  128. /* --------------------------------------------------------------------- */
  129. static struct fb_var_screeninfo vesafb_defined = {
  130. 640,480,640,480,/* W,H, W, H (virtual) load xres,xres_virtual*/
  131. 0,0, /* virtual -> visible no offset */
  132. 8, /* depth -> load bits_per_pixel */
  133. 0, /* greyscale ? */
  134. {0,0,0}, /* R */
  135. {0,0,0}, /* G */
  136. {0,0,0}, /* B */
  137. {0,0,0}, /* transparency */
  138. 0, /* standard pixel format */
  139. FB_ACTIVATE_NOW,
  140. -1,-1,
  141. FB_ACCELF_TEXT, /* accel flags */
  142. 39721L,48L,16L,33L,10L,
  143. 96L,2L,~0, /* No sync info */
  144. FB_VMODE_NONINTERLACED,
  145. };
  146. /* --------------------------------------------------------------------- */
  147. static void update_crtc2(struct matrox_fb_info *minfo, unsigned int pos)
  148. {
  149. struct matroxfb_dh_fb_info *info = minfo->crtc2.info;
  150. /* Make sure that displays are compatible */
  151. if (info && (info->fbcon.var.bits_per_pixel == minfo->fbcon.var.bits_per_pixel)
  152. && (info->fbcon.var.xres_virtual == minfo->fbcon.var.xres_virtual)
  153. && (info->fbcon.var.green.length == minfo->fbcon.var.green.length)
  154. ) {
  155. switch (minfo->fbcon.var.bits_per_pixel) {
  156. case 16:
  157. case 32:
  158. pos = pos * 8;
  159. if (info->interlaced) {
  160. mga_outl(0x3C2C, pos);
  161. mga_outl(0x3C28, pos + minfo->fbcon.var.xres_virtual * minfo->fbcon.var.bits_per_pixel / 8);
  162. } else {
  163. mga_outl(0x3C28, pos);
  164. }
  165. break;
  166. }
  167. }
  168. }
  169. static void matroxfb_crtc1_panpos(struct matrox_fb_info *minfo)
  170. {
  171. if (minfo->crtc1.panpos >= 0) {
  172. unsigned long flags;
  173. int panpos;
  174. matroxfb_DAC_lock_irqsave(flags);
  175. panpos = minfo->crtc1.panpos;
  176. if (panpos >= 0) {
  177. unsigned int extvga_reg;
  178. minfo->crtc1.panpos = -1; /* No update pending anymore */
  179. extvga_reg = mga_inb(M_EXTVGA_INDEX);
  180. mga_setr(M_EXTVGA_INDEX, 0x00, panpos);
  181. if (extvga_reg != 0x00) {
  182. mga_outb(M_EXTVGA_INDEX, extvga_reg);
  183. }
  184. }
  185. matroxfb_DAC_unlock_irqrestore(flags);
  186. }
  187. }
  188. static irqreturn_t matrox_irq(int irq, void *dev_id)
  189. {
  190. u_int32_t status;
  191. int handled = 0;
  192. struct matrox_fb_info *minfo = dev_id;
  193. status = mga_inl(M_STATUS);
  194. if (status & 0x20) {
  195. mga_outl(M_ICLEAR, 0x20);
  196. minfo->crtc1.vsync.cnt++;
  197. matroxfb_crtc1_panpos(minfo);
  198. wake_up_interruptible(&minfo->crtc1.vsync.wait);
  199. handled = 1;
  200. }
  201. if (status & 0x200) {
  202. mga_outl(M_ICLEAR, 0x200);
  203. minfo->crtc2.vsync.cnt++;
  204. wake_up_interruptible(&minfo->crtc2.vsync.wait);
  205. handled = 1;
  206. }
  207. return IRQ_RETVAL(handled);
  208. }
  209. int matroxfb_enable_irq(struct matrox_fb_info *minfo, int reenable)
  210. {
  211. u_int32_t bm;
  212. if (minfo->devflags.accelerator == FB_ACCEL_MATROX_MGAG400)
  213. bm = 0x220;
  214. else
  215. bm = 0x020;
  216. if (!test_and_set_bit(0, &minfo->irq_flags)) {
  217. if (request_irq(minfo->pcidev->irq, matrox_irq,
  218. IRQF_SHARED, "matroxfb", minfo)) {
  219. clear_bit(0, &minfo->irq_flags);
  220. return -EINVAL;
  221. }
  222. /* Clear any pending field interrupts */
  223. mga_outl(M_ICLEAR, bm);
  224. mga_outl(M_IEN, mga_inl(M_IEN) | bm);
  225. } else if (reenable) {
  226. u_int32_t ien;
  227. ien = mga_inl(M_IEN);
  228. if ((ien & bm) != bm) {
  229. printk(KERN_DEBUG "matroxfb: someone disabled IRQ [%08X]\n", ien);
  230. mga_outl(M_IEN, ien | bm);
  231. }
  232. }
  233. return 0;
  234. }
  235. static void matroxfb_disable_irq(struct matrox_fb_info *minfo)
  236. {
  237. if (test_and_clear_bit(0, &minfo->irq_flags)) {
  238. /* Flush pending pan-at-vbl request... */
  239. matroxfb_crtc1_panpos(minfo);
  240. if (minfo->devflags.accelerator == FB_ACCEL_MATROX_MGAG400)
  241. mga_outl(M_IEN, mga_inl(M_IEN) & ~0x220);
  242. else
  243. mga_outl(M_IEN, mga_inl(M_IEN) & ~0x20);
  244. free_irq(minfo->pcidev->irq, minfo);
  245. }
  246. }
  247. int matroxfb_wait_for_sync(struct matrox_fb_info *minfo, u_int32_t crtc)
  248. {
  249. struct matrox_vsync *vs;
  250. unsigned int cnt;
  251. int ret;
  252. switch (crtc) {
  253. case 0:
  254. vs = &minfo->crtc1.vsync;
  255. break;
  256. case 1:
  257. if (minfo->devflags.accelerator != FB_ACCEL_MATROX_MGAG400) {
  258. return -ENODEV;
  259. }
  260. vs = &minfo->crtc2.vsync;
  261. break;
  262. default:
  263. return -ENODEV;
  264. }
  265. ret = matroxfb_enable_irq(minfo, 0);
  266. if (ret) {
  267. return ret;
  268. }
  269. cnt = vs->cnt;
  270. ret = wait_event_interruptible_timeout(vs->wait, cnt != vs->cnt, HZ/10);
  271. if (ret < 0) {
  272. return ret;
  273. }
  274. if (ret == 0) {
  275. matroxfb_enable_irq(minfo, 1);
  276. return -ETIMEDOUT;
  277. }
  278. return 0;
  279. }
  280. /* --------------------------------------------------------------------- */
  281. static void matrox_pan_var(struct matrox_fb_info *minfo,
  282. struct fb_var_screeninfo *var)
  283. {
  284. unsigned int pos;
  285. unsigned short p0, p1, p2;
  286. unsigned int p3;
  287. int vbl;
  288. unsigned long flags;
  289. CRITFLAGS
  290. DBG(__func__)
  291. if (minfo->dead)
  292. return;
  293. minfo->fbcon.var.xoffset = var->xoffset;
  294. minfo->fbcon.var.yoffset = var->yoffset;
  295. pos = (minfo->fbcon.var.yoffset * minfo->fbcon.var.xres_virtual + minfo->fbcon.var.xoffset) * minfo->curr.final_bppShift / 32;
  296. pos += minfo->curr.ydstorg.chunks;
  297. p0 = minfo->hw.CRTC[0x0D] = pos & 0xFF;
  298. p1 = minfo->hw.CRTC[0x0C] = (pos & 0xFF00) >> 8;
  299. p2 = minfo->hw.CRTCEXT[0] = (minfo->hw.CRTCEXT[0] & 0xB0) | ((pos >> 16) & 0x0F) | ((pos >> 14) & 0x40);
  300. p3 = minfo->hw.CRTCEXT[8] = pos >> 21;
  301. /* FB_ACTIVATE_VBL and we can acquire interrupts? Honor FB_ACTIVATE_VBL then... */
  302. vbl = (var->activate & FB_ACTIVATE_VBL) && (matroxfb_enable_irq(minfo, 0) == 0);
  303. CRITBEGIN
  304. matroxfb_DAC_lock_irqsave(flags);
  305. mga_setr(M_CRTC_INDEX, 0x0D, p0);
  306. mga_setr(M_CRTC_INDEX, 0x0C, p1);
  307. if (minfo->devflags.support32MB)
  308. mga_setr(M_EXTVGA_INDEX, 0x08, p3);
  309. if (vbl) {
  310. minfo->crtc1.panpos = p2;
  311. } else {
  312. /* Abort any pending change */
  313. minfo->crtc1.panpos = -1;
  314. mga_setr(M_EXTVGA_INDEX, 0x00, p2);
  315. }
  316. matroxfb_DAC_unlock_irqrestore(flags);
  317. update_crtc2(minfo, pos);
  318. CRITEND
  319. }
  320. static void matroxfb_remove(struct matrox_fb_info *minfo, int dummy)
  321. {
  322. /* Currently we are holding big kernel lock on all dead & usecount updates.
  323. * Destroy everything after all users release it. Especially do not unregister
  324. * framebuffer and iounmap memory, neither fbmem nor fbcon-cfb* does not check
  325. * for device unplugged when in use.
  326. * In future we should point mmio.vbase & video.vbase somewhere where we can
  327. * write data without causing too much damage...
  328. */
  329. minfo->dead = 1;
  330. if (minfo->usecount) {
  331. /* destroy it later */
  332. return;
  333. }
  334. matroxfb_unregister_device(minfo);
  335. unregister_framebuffer(&minfo->fbcon);
  336. matroxfb_g450_shutdown(minfo);
  337. arch_phys_wc_del(minfo->wc_cookie);
  338. iounmap(minfo->mmio.vbase.vaddr);
  339. iounmap(minfo->video.vbase.vaddr);
  340. release_mem_region(minfo->video.base, minfo->video.len_maximum);
  341. release_mem_region(minfo->mmio.base, 16384);
  342. kfree(minfo);
  343. }
  344. /*
  345. * Open/Release the frame buffer device
  346. */
  347. static int matroxfb_open(struct fb_info *info, int user)
  348. {
  349. struct matrox_fb_info *minfo = info2minfo(info);
  350. DBG_LOOP(__func__)
  351. if (minfo->dead) {
  352. return -ENXIO;
  353. }
  354. minfo->usecount++;
  355. if (user) {
  356. minfo->userusecount++;
  357. }
  358. return(0);
  359. }
  360. static int matroxfb_release(struct fb_info *info, int user)
  361. {
  362. struct matrox_fb_info *minfo = info2minfo(info);
  363. DBG_LOOP(__func__)
  364. if (user) {
  365. if (0 == --minfo->userusecount) {
  366. matroxfb_disable_irq(minfo);
  367. }
  368. }
  369. if (!(--minfo->usecount) && minfo->dead) {
  370. matroxfb_remove(minfo, 0);
  371. }
  372. return(0);
  373. }
  374. static int matroxfb_pan_display(struct fb_var_screeninfo *var,
  375. struct fb_info* info) {
  376. struct matrox_fb_info *minfo = info2minfo(info);
  377. DBG(__func__)
  378. matrox_pan_var(minfo, var);
  379. return 0;
  380. }
  381. static int matroxfb_get_final_bppShift(const struct matrox_fb_info *minfo,
  382. int bpp)
  383. {
  384. int bppshft2;
  385. DBG(__func__)
  386. bppshft2 = bpp;
  387. if (!bppshft2) {
  388. return 8;
  389. }
  390. if (isInterleave(minfo))
  391. bppshft2 >>= 1;
  392. if (minfo->devflags.video64bits)
  393. bppshft2 >>= 1;
  394. return bppshft2;
  395. }
  396. static int matroxfb_test_and_set_rounding(const struct matrox_fb_info *minfo,
  397. int xres, int bpp)
  398. {
  399. int over;
  400. int rounding;
  401. DBG(__func__)
  402. switch (bpp) {
  403. case 0: return xres;
  404. case 4: rounding = 128;
  405. break;
  406. case 8: rounding = 64; /* doc says 64; 32 is OK for G400 */
  407. break;
  408. case 16: rounding = 32;
  409. break;
  410. case 24: rounding = 64; /* doc says 64; 32 is OK for G400 */
  411. break;
  412. default: rounding = 16;
  413. /* on G400, 16 really does not work */
  414. if (minfo->devflags.accelerator == FB_ACCEL_MATROX_MGAG400)
  415. rounding = 32;
  416. break;
  417. }
  418. if (isInterleave(minfo)) {
  419. rounding *= 2;
  420. }
  421. over = xres % rounding;
  422. if (over)
  423. xres += rounding-over;
  424. return xres;
  425. }
  426. static int matroxfb_pitch_adjust(const struct matrox_fb_info *minfo, int xres,
  427. int bpp)
  428. {
  429. const int* width;
  430. int xres_new;
  431. DBG(__func__)
  432. if (!bpp) return xres;
  433. width = minfo->capable.vxres;
  434. if (minfo->devflags.precise_width) {
  435. while (*width) {
  436. if ((*width >= xres) && (matroxfb_test_and_set_rounding(minfo, *width, bpp) == *width)) {
  437. break;
  438. }
  439. width++;
  440. }
  441. xres_new = *width;
  442. } else {
  443. xres_new = matroxfb_test_and_set_rounding(minfo, xres, bpp);
  444. }
  445. return xres_new;
  446. }
  447. static int matroxfb_get_cmap_len(struct fb_var_screeninfo *var) {
  448. DBG(__func__)
  449. switch (var->bits_per_pixel) {
  450. case 4:
  451. return 16; /* pseudocolor... 16 entries HW palette */
  452. case 8:
  453. return 256; /* pseudocolor... 256 entries HW palette */
  454. case 16:
  455. return 16; /* directcolor... 16 entries SW palette */
  456. /* Mystique: truecolor, 16 entries SW palette, HW palette hardwired into 1:1 mapping */
  457. case 24:
  458. return 16; /* directcolor... 16 entries SW palette */
  459. /* Mystique: truecolor, 16 entries SW palette, HW palette hardwired into 1:1 mapping */
  460. case 32:
  461. return 16; /* directcolor... 16 entries SW palette */
  462. /* Mystique: truecolor, 16 entries SW palette, HW palette hardwired into 1:1 mapping */
  463. }
  464. return 16; /* return something reasonable... or panic()? */
  465. }
  466. static int matroxfb_decode_var(const struct matrox_fb_info *minfo,
  467. struct fb_var_screeninfo *var, int *visual,
  468. int *video_cmap_len, unsigned int* ydstorg)
  469. {
  470. struct RGBT {
  471. unsigned char bpp;
  472. struct {
  473. unsigned char offset,
  474. length;
  475. } red,
  476. green,
  477. blue,
  478. transp;
  479. signed char visual;
  480. };
  481. static const struct RGBT table[]= {
  482. { 8,{ 0,8},{0,8},{0,8},{ 0,0},MX_VISUAL_PSEUDOCOLOR},
  483. {15,{10,5},{5,5},{0,5},{15,1},MX_VISUAL_DIRECTCOLOR},
  484. {16,{11,5},{5,6},{0,5},{ 0,0},MX_VISUAL_DIRECTCOLOR},
  485. {24,{16,8},{8,8},{0,8},{ 0,0},MX_VISUAL_DIRECTCOLOR},
  486. {32,{16,8},{8,8},{0,8},{24,8},MX_VISUAL_DIRECTCOLOR}
  487. };
  488. struct RGBT const *rgbt;
  489. unsigned int bpp = var->bits_per_pixel;
  490. unsigned int vramlen;
  491. unsigned int memlen;
  492. DBG(__func__)
  493. switch (bpp) {
  494. case 4: if (!minfo->capable.cfb4) return -EINVAL;
  495. break;
  496. case 8: break;
  497. case 16: break;
  498. case 24: break;
  499. case 32: break;
  500. default: return -EINVAL;
  501. }
  502. *ydstorg = 0;
  503. vramlen = minfo->video.len_usable;
  504. if (var->yres_virtual < var->yres)
  505. var->yres_virtual = var->yres;
  506. if (var->xres_virtual < var->xres)
  507. var->xres_virtual = var->xres;
  508. var->xres_virtual = matroxfb_pitch_adjust(minfo, var->xres_virtual, bpp);
  509. memlen = var->xres_virtual * bpp * var->yres_virtual / 8;
  510. if (memlen > vramlen) {
  511. var->yres_virtual = vramlen * 8 / (var->xres_virtual * bpp);
  512. memlen = var->xres_virtual * bpp * var->yres_virtual / 8;
  513. }
  514. /* There is hardware bug that no line can cross 4MB boundary */
  515. /* give up for CFB24, it is impossible to easy workaround it */
  516. /* for other try to do something */
  517. if (!minfo->capable.cross4MB && (memlen > 0x400000)) {
  518. if (bpp == 24) {
  519. /* sorry */
  520. } else {
  521. unsigned int linelen;
  522. unsigned int m1 = linelen = var->xres_virtual * bpp / 8;
  523. unsigned int m2 = PAGE_SIZE; /* or 128 if you do not need PAGE ALIGNED address */
  524. unsigned int max_yres;
  525. while (m1) {
  526. while (m2 >= m1) m2 -= m1;
  527. swap(m1, m2);
  528. }
  529. m2 = linelen * PAGE_SIZE / m2;
  530. *ydstorg = m2 = 0x400000 % m2;
  531. max_yres = (vramlen - m2) / linelen;
  532. if (var->yres_virtual > max_yres)
  533. var->yres_virtual = max_yres;
  534. }
  535. }
  536. /* YDSTLEN contains only signed 16bit value */
  537. if (var->yres_virtual > 32767)
  538. var->yres_virtual = 32767;
  539. /* we must round yres/xres down, we already rounded y/xres_virtual up
  540. if it was possible. We should return -EINVAL, but I disagree */
  541. if (var->yres_virtual < var->yres)
  542. var->yres = var->yres_virtual;
  543. if (var->xres_virtual < var->xres)
  544. var->xres = var->xres_virtual;
  545. if (var->xoffset + var->xres > var->xres_virtual)
  546. var->xoffset = var->xres_virtual - var->xres;
  547. if (var->yoffset + var->yres > var->yres_virtual)
  548. var->yoffset = var->yres_virtual - var->yres;
  549. if (bpp == 16 && var->green.length == 5) {
  550. bpp--; /* an artificial value - 15 */
  551. }
  552. for (rgbt = table; rgbt->bpp < bpp; rgbt++);
  553. #define SETCLR(clr)\
  554. var->clr.offset = rgbt->clr.offset;\
  555. var->clr.length = rgbt->clr.length
  556. SETCLR(red);
  557. SETCLR(green);
  558. SETCLR(blue);
  559. SETCLR(transp);
  560. #undef SETCLR
  561. *visual = rgbt->visual;
  562. if (bpp > 8)
  563. dprintk("matroxfb: truecolor: "
  564. "size=%d:%d:%d:%d, shift=%d:%d:%d:%d\n",
  565. var->transp.length, var->red.length, var->green.length, var->blue.length,
  566. var->transp.offset, var->red.offset, var->green.offset, var->blue.offset);
  567. *video_cmap_len = matroxfb_get_cmap_len(var);
  568. dprintk(KERN_INFO "requested %d*%d/%dbpp (%d*%d)\n", var->xres, var->yres, var->bits_per_pixel,
  569. var->xres_virtual, var->yres_virtual);
  570. return 0;
  571. }
  572. static int matroxfb_setcolreg(unsigned regno, unsigned red, unsigned green,
  573. unsigned blue, unsigned transp,
  574. struct fb_info *fb_info)
  575. {
  576. struct matrox_fb_info* minfo = container_of(fb_info, struct matrox_fb_info, fbcon);
  577. DBG(__func__)
  578. /*
  579. * Set a single color register. The values supplied are
  580. * already rounded down to the hardware's capabilities
  581. * (according to the entries in the `var' structure). Return
  582. * != 0 for invalid regno.
  583. */
  584. if (regno >= minfo->curr.cmap_len)
  585. return 1;
  586. if (minfo->fbcon.var.grayscale) {
  587. /* gray = 0.30*R + 0.59*G + 0.11*B */
  588. red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
  589. }
  590. red = CNVT_TOHW(red, minfo->fbcon.var.red.length);
  591. green = CNVT_TOHW(green, minfo->fbcon.var.green.length);
  592. blue = CNVT_TOHW(blue, minfo->fbcon.var.blue.length);
  593. transp = CNVT_TOHW(transp, minfo->fbcon.var.transp.length);
  594. switch (minfo->fbcon.var.bits_per_pixel) {
  595. case 4:
  596. case 8:
  597. mga_outb(M_DAC_REG, regno);
  598. mga_outb(M_DAC_VAL, red);
  599. mga_outb(M_DAC_VAL, green);
  600. mga_outb(M_DAC_VAL, blue);
  601. break;
  602. case 16:
  603. if (regno >= 16)
  604. break;
  605. {
  606. u_int16_t col =
  607. (red << minfo->fbcon.var.red.offset) |
  608. (green << minfo->fbcon.var.green.offset) |
  609. (blue << minfo->fbcon.var.blue.offset) |
  610. (transp << minfo->fbcon.var.transp.offset); /* for 1:5:5:5 */
  611. minfo->cmap[regno] = col | (col << 16);
  612. }
  613. break;
  614. case 24:
  615. case 32:
  616. if (regno >= 16)
  617. break;
  618. minfo->cmap[regno] =
  619. (red << minfo->fbcon.var.red.offset) |
  620. (green << minfo->fbcon.var.green.offset) |
  621. (blue << minfo->fbcon.var.blue.offset) |
  622. (transp << minfo->fbcon.var.transp.offset); /* 8:8:8:8 */
  623. break;
  624. }
  625. return 0;
  626. }
  627. static void matroxfb_init_fix(struct matrox_fb_info *minfo)
  628. {
  629. struct fb_fix_screeninfo *fix = &minfo->fbcon.fix;
  630. DBG(__func__)
  631. strcpy(fix->id,"MATROX");
  632. fix->xpanstep = 8; /* 8 for 8bpp, 4 for 16bpp, 2 for 32bpp */
  633. fix->ypanstep = 1;
  634. fix->ywrapstep = 0;
  635. fix->mmio_start = minfo->mmio.base;
  636. fix->mmio_len = minfo->mmio.len;
  637. fix->accel = minfo->devflags.accelerator;
  638. }
  639. static void matroxfb_update_fix(struct matrox_fb_info *minfo)
  640. {
  641. struct fb_fix_screeninfo *fix = &minfo->fbcon.fix;
  642. DBG(__func__)
  643. mutex_lock(&minfo->fbcon.mm_lock);
  644. fix->smem_start = minfo->video.base + minfo->curr.ydstorg.bytes;
  645. fix->smem_len = minfo->video.len_usable - minfo->curr.ydstorg.bytes;
  646. mutex_unlock(&minfo->fbcon.mm_lock);
  647. }
  648. static int matroxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  649. {
  650. int err;
  651. int visual;
  652. int cmap_len;
  653. unsigned int ydstorg;
  654. struct matrox_fb_info *minfo = info2minfo(info);
  655. if (minfo->dead) {
  656. return -ENXIO;
  657. }
  658. if ((err = matroxfb_decode_var(minfo, var, &visual, &cmap_len, &ydstorg)) != 0)
  659. return err;
  660. return 0;
  661. }
  662. static int matroxfb_set_par(struct fb_info *info)
  663. {
  664. int err;
  665. int visual;
  666. int cmap_len;
  667. unsigned int ydstorg;
  668. struct fb_var_screeninfo *var;
  669. struct matrox_fb_info *minfo = info2minfo(info);
  670. DBG(__func__)
  671. if (minfo->dead) {
  672. return -ENXIO;
  673. }
  674. var = &info->var;
  675. if ((err = matroxfb_decode_var(minfo, var, &visual, &cmap_len, &ydstorg)) != 0)
  676. return err;
  677. minfo->fbcon.screen_base = vaddr_va(minfo->video.vbase) + ydstorg;
  678. matroxfb_update_fix(minfo);
  679. minfo->fbcon.fix.visual = visual;
  680. minfo->fbcon.fix.type = FB_TYPE_PACKED_PIXELS;
  681. minfo->fbcon.fix.type_aux = 0;
  682. minfo->fbcon.fix.line_length = (var->xres_virtual * var->bits_per_pixel) >> 3;
  683. {
  684. unsigned int pos;
  685. minfo->curr.cmap_len = cmap_len;
  686. ydstorg += minfo->devflags.ydstorg;
  687. minfo->curr.ydstorg.bytes = ydstorg;
  688. minfo->curr.ydstorg.chunks = ydstorg >> (isInterleave(minfo) ? 3 : 2);
  689. if (var->bits_per_pixel == 4)
  690. minfo->curr.ydstorg.pixels = ydstorg;
  691. else
  692. minfo->curr.ydstorg.pixels = (ydstorg * 8) / var->bits_per_pixel;
  693. minfo->curr.final_bppShift = matroxfb_get_final_bppShift(minfo, var->bits_per_pixel);
  694. { struct my_timming mt;
  695. struct matrox_hw_state* hw;
  696. int out;
  697. matroxfb_var2my(var, &mt);
  698. mt.crtc = MATROXFB_SRC_CRTC1;
  699. /* CRTC1 delays */
  700. switch (var->bits_per_pixel) {
  701. case 0: mt.delay = 31 + 0; break;
  702. case 16: mt.delay = 21 + 8; break;
  703. case 24: mt.delay = 17 + 8; break;
  704. case 32: mt.delay = 16 + 8; break;
  705. default: mt.delay = 31 + 8; break;
  706. }
  707. hw = &minfo->hw;
  708. down_read(&minfo->altout.lock);
  709. for (out = 0; out < MATROXFB_MAX_OUTPUTS; out++) {
  710. if (minfo->outputs[out].src == MATROXFB_SRC_CRTC1 &&
  711. minfo->outputs[out].output->compute) {
  712. minfo->outputs[out].output->compute(minfo->outputs[out].data, &mt);
  713. }
  714. }
  715. up_read(&minfo->altout.lock);
  716. minfo->crtc1.pixclock = mt.pixclock;
  717. minfo->crtc1.mnp = mt.mnp;
  718. minfo->hw_switch->init(minfo, &mt);
  719. pos = (var->yoffset * var->xres_virtual + var->xoffset) * minfo->curr.final_bppShift / 32;
  720. pos += minfo->curr.ydstorg.chunks;
  721. hw->CRTC[0x0D] = pos & 0xFF;
  722. hw->CRTC[0x0C] = (pos & 0xFF00) >> 8;
  723. hw->CRTCEXT[0] = (hw->CRTCEXT[0] & 0xF0) | ((pos >> 16) & 0x0F) | ((pos >> 14) & 0x40);
  724. hw->CRTCEXT[8] = pos >> 21;
  725. minfo->hw_switch->restore(minfo);
  726. update_crtc2(minfo, pos);
  727. down_read(&minfo->altout.lock);
  728. for (out = 0; out < MATROXFB_MAX_OUTPUTS; out++) {
  729. if (minfo->outputs[out].src == MATROXFB_SRC_CRTC1 &&
  730. minfo->outputs[out].output->program) {
  731. minfo->outputs[out].output->program(minfo->outputs[out].data);
  732. }
  733. }
  734. for (out = 0; out < MATROXFB_MAX_OUTPUTS; out++) {
  735. if (minfo->outputs[out].src == MATROXFB_SRC_CRTC1 &&
  736. minfo->outputs[out].output->start) {
  737. minfo->outputs[out].output->start(minfo->outputs[out].data);
  738. }
  739. }
  740. up_read(&minfo->altout.lock);
  741. matrox_cfbX_init(minfo);
  742. }
  743. }
  744. minfo->initialized = 1;
  745. return 0;
  746. }
  747. static int matroxfb_get_vblank(struct matrox_fb_info *minfo,
  748. struct fb_vblank *vblank)
  749. {
  750. unsigned int sts1;
  751. matroxfb_enable_irq(minfo, 0);
  752. memset(vblank, 0, sizeof(*vblank));
  753. vblank->flags = FB_VBLANK_HAVE_VCOUNT | FB_VBLANK_HAVE_VSYNC |
  754. FB_VBLANK_HAVE_VBLANK | FB_VBLANK_HAVE_HBLANK;
  755. sts1 = mga_inb(M_INSTS1);
  756. vblank->vcount = mga_inl(M_VCOUNT);
  757. /* BTW, on my PIII/450 with G400, reading M_INSTS1
  758. byte makes this call about 12% slower (1.70 vs. 2.05 us
  759. per ioctl()) */
  760. if (sts1 & 1)
  761. vblank->flags |= FB_VBLANK_HBLANKING;
  762. if (sts1 & 8)
  763. vblank->flags |= FB_VBLANK_VSYNCING;
  764. if (vblank->vcount >= minfo->fbcon.var.yres)
  765. vblank->flags |= FB_VBLANK_VBLANKING;
  766. if (test_bit(0, &minfo->irq_flags)) {
  767. vblank->flags |= FB_VBLANK_HAVE_COUNT;
  768. /* Only one writer, aligned int value...
  769. it should work without lock and without atomic_t */
  770. vblank->count = minfo->crtc1.vsync.cnt;
  771. }
  772. return 0;
  773. }
  774. static struct matrox_altout panellink_output = {
  775. .name = "Panellink output",
  776. };
  777. static int matroxfb_ioctl(struct fb_info *info,
  778. unsigned int cmd, unsigned long arg)
  779. {
  780. void __user *argp = (void __user *)arg;
  781. struct matrox_fb_info *minfo = info2minfo(info);
  782. DBG(__func__)
  783. if (minfo->dead) {
  784. return -ENXIO;
  785. }
  786. switch (cmd) {
  787. case FBIOGET_VBLANK:
  788. {
  789. struct fb_vblank vblank;
  790. int err;
  791. err = matroxfb_get_vblank(minfo, &vblank);
  792. if (err)
  793. return err;
  794. if (copy_to_user(argp, &vblank, sizeof(vblank)))
  795. return -EFAULT;
  796. return 0;
  797. }
  798. case FBIO_WAITFORVSYNC:
  799. {
  800. u_int32_t crt;
  801. if (get_user(crt, (u_int32_t __user *)arg))
  802. return -EFAULT;
  803. return matroxfb_wait_for_sync(minfo, crt);
  804. }
  805. case MATROXFB_SET_OUTPUT_MODE:
  806. {
  807. struct matroxioc_output_mode mom;
  808. struct matrox_altout *oproc;
  809. int val;
  810. if (copy_from_user(&mom, argp, sizeof(mom)))
  811. return -EFAULT;
  812. if (mom.output >= MATROXFB_MAX_OUTPUTS)
  813. return -ENXIO;
  814. down_read(&minfo->altout.lock);
  815. oproc = minfo->outputs[mom.output].output;
  816. if (!oproc) {
  817. val = -ENXIO;
  818. } else if (!oproc->verifymode) {
  819. if (mom.mode == MATROXFB_OUTPUT_MODE_MONITOR) {
  820. val = 0;
  821. } else {
  822. val = -EINVAL;
  823. }
  824. } else {
  825. val = oproc->verifymode(minfo->outputs[mom.output].data, mom.mode);
  826. }
  827. if (!val) {
  828. if (minfo->outputs[mom.output].mode != mom.mode) {
  829. minfo->outputs[mom.output].mode = mom.mode;
  830. val = 1;
  831. }
  832. }
  833. up_read(&minfo->altout.lock);
  834. if (val != 1)
  835. return val;
  836. switch (minfo->outputs[mom.output].src) {
  837. case MATROXFB_SRC_CRTC1:
  838. matroxfb_set_par(info);
  839. break;
  840. case MATROXFB_SRC_CRTC2:
  841. {
  842. struct matroxfb_dh_fb_info* crtc2;
  843. down_read(&minfo->crtc2.lock);
  844. crtc2 = minfo->crtc2.info;
  845. if (crtc2)
  846. crtc2->fbcon.fbops->fb_set_par(&crtc2->fbcon);
  847. up_read(&minfo->crtc2.lock);
  848. }
  849. break;
  850. }
  851. return 0;
  852. }
  853. case MATROXFB_GET_OUTPUT_MODE:
  854. {
  855. struct matroxioc_output_mode mom;
  856. struct matrox_altout *oproc;
  857. int val;
  858. if (copy_from_user(&mom, argp, sizeof(mom)))
  859. return -EFAULT;
  860. if (mom.output >= MATROXFB_MAX_OUTPUTS)
  861. return -ENXIO;
  862. down_read(&minfo->altout.lock);
  863. oproc = minfo->outputs[mom.output].output;
  864. if (!oproc) {
  865. val = -ENXIO;
  866. } else {
  867. mom.mode = minfo->outputs[mom.output].mode;
  868. val = 0;
  869. }
  870. up_read(&minfo->altout.lock);
  871. if (val)
  872. return val;
  873. if (copy_to_user(argp, &mom, sizeof(mom)))
  874. return -EFAULT;
  875. return 0;
  876. }
  877. case MATROXFB_SET_OUTPUT_CONNECTION:
  878. {
  879. u_int32_t tmp;
  880. int i;
  881. int changes;
  882. if (copy_from_user(&tmp, argp, sizeof(tmp)))
  883. return -EFAULT;
  884. for (i = 0; i < 32; i++) {
  885. if (tmp & (1 << i)) {
  886. if (i >= MATROXFB_MAX_OUTPUTS)
  887. return -ENXIO;
  888. if (!minfo->outputs[i].output)
  889. return -ENXIO;
  890. switch (minfo->outputs[i].src) {
  891. case MATROXFB_SRC_NONE:
  892. case MATROXFB_SRC_CRTC1:
  893. break;
  894. default:
  895. return -EBUSY;
  896. }
  897. }
  898. }
  899. if (minfo->devflags.panellink) {
  900. if (tmp & MATROXFB_OUTPUT_CONN_DFP) {
  901. if (tmp & MATROXFB_OUTPUT_CONN_SECONDARY)
  902. return -EINVAL;
  903. for (i = 0; i < MATROXFB_MAX_OUTPUTS; i++) {
  904. if (minfo->outputs[i].src == MATROXFB_SRC_CRTC2) {
  905. return -EBUSY;
  906. }
  907. }
  908. }
  909. }
  910. changes = 0;
  911. for (i = 0; i < MATROXFB_MAX_OUTPUTS; i++) {
  912. if (tmp & (1 << i)) {
  913. if (minfo->outputs[i].src != MATROXFB_SRC_CRTC1) {
  914. changes = 1;
  915. minfo->outputs[i].src = MATROXFB_SRC_CRTC1;
  916. }
  917. } else if (minfo->outputs[i].src == MATROXFB_SRC_CRTC1) {
  918. changes = 1;
  919. minfo->outputs[i].src = MATROXFB_SRC_NONE;
  920. }
  921. }
  922. if (!changes)
  923. return 0;
  924. matroxfb_set_par(info);
  925. return 0;
  926. }
  927. case MATROXFB_GET_OUTPUT_CONNECTION:
  928. {
  929. u_int32_t conn = 0;
  930. int i;
  931. for (i = 0; i < MATROXFB_MAX_OUTPUTS; i++) {
  932. if (minfo->outputs[i].src == MATROXFB_SRC_CRTC1) {
  933. conn |= 1 << i;
  934. }
  935. }
  936. if (put_user(conn, (u_int32_t __user *)arg))
  937. return -EFAULT;
  938. return 0;
  939. }
  940. case MATROXFB_GET_AVAILABLE_OUTPUTS:
  941. {
  942. u_int32_t conn = 0;
  943. int i;
  944. for (i = 0; i < MATROXFB_MAX_OUTPUTS; i++) {
  945. if (minfo->outputs[i].output) {
  946. switch (minfo->outputs[i].src) {
  947. case MATROXFB_SRC_NONE:
  948. case MATROXFB_SRC_CRTC1:
  949. conn |= 1 << i;
  950. break;
  951. }
  952. }
  953. }
  954. if (minfo->devflags.panellink) {
  955. if (conn & MATROXFB_OUTPUT_CONN_DFP)
  956. conn &= ~MATROXFB_OUTPUT_CONN_SECONDARY;
  957. if (conn & MATROXFB_OUTPUT_CONN_SECONDARY)
  958. conn &= ~MATROXFB_OUTPUT_CONN_DFP;
  959. }
  960. if (put_user(conn, (u_int32_t __user *)arg))
  961. return -EFAULT;
  962. return 0;
  963. }
  964. case MATROXFB_GET_ALL_OUTPUTS:
  965. {
  966. u_int32_t conn = 0;
  967. int i;
  968. for (i = 0; i < MATROXFB_MAX_OUTPUTS; i++) {
  969. if (minfo->outputs[i].output) {
  970. conn |= 1 << i;
  971. }
  972. }
  973. if (put_user(conn, (u_int32_t __user *)arg))
  974. return -EFAULT;
  975. return 0;
  976. }
  977. case VIDIOC_QUERYCAP:
  978. {
  979. struct v4l2_capability r;
  980. memset(&r, 0, sizeof(r));
  981. strcpy(r.driver, "matroxfb");
  982. strcpy(r.card, "Matrox");
  983. sprintf(r.bus_info, "PCI:%s", pci_name(minfo->pcidev));
  984. r.version = KERNEL_VERSION(1,0,0);
  985. r.capabilities = V4L2_CAP_VIDEO_OUTPUT;
  986. if (copy_to_user(argp, &r, sizeof(r)))
  987. return -EFAULT;
  988. return 0;
  989. }
  990. case VIDIOC_QUERYCTRL:
  991. {
  992. struct v4l2_queryctrl qctrl;
  993. int err;
  994. if (copy_from_user(&qctrl, argp, sizeof(qctrl)))
  995. return -EFAULT;
  996. down_read(&minfo->altout.lock);
  997. if (!minfo->outputs[1].output) {
  998. err = -ENXIO;
  999. } else if (minfo->outputs[1].output->getqueryctrl) {
  1000. err = minfo->outputs[1].output->getqueryctrl(minfo->outputs[1].data, &qctrl);
  1001. } else {
  1002. err = -EINVAL;
  1003. }
  1004. up_read(&minfo->altout.lock);
  1005. if (err >= 0 &&
  1006. copy_to_user(argp, &qctrl, sizeof(qctrl)))
  1007. return -EFAULT;
  1008. return err;
  1009. }
  1010. case VIDIOC_G_CTRL:
  1011. {
  1012. struct v4l2_control ctrl;
  1013. int err;
  1014. if (copy_from_user(&ctrl, argp, sizeof(ctrl)))
  1015. return -EFAULT;
  1016. down_read(&minfo->altout.lock);
  1017. if (!minfo->outputs[1].output) {
  1018. err = -ENXIO;
  1019. } else if (minfo->outputs[1].output->getctrl) {
  1020. err = minfo->outputs[1].output->getctrl(minfo->outputs[1].data, &ctrl);
  1021. } else {
  1022. err = -EINVAL;
  1023. }
  1024. up_read(&minfo->altout.lock);
  1025. if (err >= 0 &&
  1026. copy_to_user(argp, &ctrl, sizeof(ctrl)))
  1027. return -EFAULT;
  1028. return err;
  1029. }
  1030. case VIDIOC_S_CTRL:
  1031. {
  1032. struct v4l2_control ctrl;
  1033. int err;
  1034. if (copy_from_user(&ctrl, argp, sizeof(ctrl)))
  1035. return -EFAULT;
  1036. down_read(&minfo->altout.lock);
  1037. if (!minfo->outputs[1].output) {
  1038. err = -ENXIO;
  1039. } else if (minfo->outputs[1].output->setctrl) {
  1040. err = minfo->outputs[1].output->setctrl(minfo->outputs[1].data, &ctrl);
  1041. } else {
  1042. err = -EINVAL;
  1043. }
  1044. up_read(&minfo->altout.lock);
  1045. return err;
  1046. }
  1047. }
  1048. return -ENOTTY;
  1049. }
  1050. /* 0 unblank, 1 blank, 2 no vsync, 3 no hsync, 4 off */
  1051. static int matroxfb_blank(int blank, struct fb_info *info)
  1052. {
  1053. int seq;
  1054. int crtc;
  1055. CRITFLAGS
  1056. struct matrox_fb_info *minfo = info2minfo(info);
  1057. DBG(__func__)
  1058. if (minfo->dead)
  1059. return 1;
  1060. switch (blank) {
  1061. case FB_BLANK_NORMAL: seq = 0x20; crtc = 0x00; break; /* works ??? */
  1062. case FB_BLANK_VSYNC_SUSPEND: seq = 0x20; crtc = 0x10; break;
  1063. case FB_BLANK_HSYNC_SUSPEND: seq = 0x20; crtc = 0x20; break;
  1064. case FB_BLANK_POWERDOWN: seq = 0x20; crtc = 0x30; break;
  1065. default: seq = 0x00; crtc = 0x00; break;
  1066. }
  1067. CRITBEGIN
  1068. mga_outb(M_SEQ_INDEX, 1);
  1069. mga_outb(M_SEQ_DATA, (mga_inb(M_SEQ_DATA) & ~0x20) | seq);
  1070. mga_outb(M_EXTVGA_INDEX, 1);
  1071. mga_outb(M_EXTVGA_DATA, (mga_inb(M_EXTVGA_DATA) & ~0x30) | crtc);
  1072. CRITEND
  1073. return 0;
  1074. }
  1075. static const struct fb_ops matroxfb_ops = {
  1076. .owner = THIS_MODULE,
  1077. .fb_open = matroxfb_open,
  1078. .fb_release = matroxfb_release,
  1079. __FB_DEFAULT_IOMEM_OPS_RDWR,
  1080. .fb_check_var = matroxfb_check_var,
  1081. .fb_set_par = matroxfb_set_par,
  1082. .fb_setcolreg = matroxfb_setcolreg,
  1083. .fb_pan_display =matroxfb_pan_display,
  1084. .fb_blank = matroxfb_blank,
  1085. .fb_ioctl = matroxfb_ioctl,
  1086. /* .fb_fillrect = <set by matrox_cfbX_init>, */
  1087. /* .fb_copyarea = <set by matrox_cfbX_init>, */
  1088. /* .fb_imageblit = <set by matrox_cfbX_init>, */
  1089. /* .fb_cursor = <set by matrox_cfbX_init>, */
  1090. __FB_DEFAULT_IOMEM_OPS_MMAP,
  1091. };
  1092. #define RSDepth(X) (((X) >> 8) & 0x0F)
  1093. #define RS8bpp 0x1
  1094. #define RS15bpp 0x2
  1095. #define RS16bpp 0x3
  1096. #define RS32bpp 0x4
  1097. #define RS4bpp 0x5
  1098. #define RS24bpp 0x6
  1099. #define RSText 0x7
  1100. #define RSText8 0x8
  1101. /* 9-F */
  1102. static struct { struct fb_bitfield red, green, blue, transp; int bits_per_pixel; } colors[] = {
  1103. { { 0, 8, 0}, { 0, 8, 0}, { 0, 8, 0}, { 0, 0, 0}, 8 },
  1104. { { 10, 5, 0}, { 5, 5, 0}, { 0, 5, 0}, { 15, 1, 0}, 16 },
  1105. { { 11, 5, 0}, { 5, 6, 0}, { 0, 5, 0}, { 0, 0, 0}, 16 },
  1106. { { 16, 8, 0}, { 8, 8, 0}, { 0, 8, 0}, { 24, 8, 0}, 32 },
  1107. { { 0, 8, 0}, { 0, 8, 0}, { 0, 8, 0}, { 0, 0, 0}, 4 },
  1108. { { 16, 8, 0}, { 8, 8, 0}, { 0, 8, 0}, { 0, 0, 0}, 24 },
  1109. { { 0, 6, 0}, { 0, 6, 0}, { 0, 6, 0}, { 0, 0, 0}, 0 }, /* textmode with (default) VGA8x16 */
  1110. { { 0, 6, 0}, { 0, 6, 0}, { 0, 6, 0}, { 0, 0, 0}, 0 }, /* textmode hardwired to VGA8x8 */
  1111. };
  1112. /* initialized by setup, see explanation at end of file (search for MODULE_PARM_DESC) */
  1113. static unsigned int mem; /* "matroxfb:mem:xxxxxM" */
  1114. static int option_precise_width = 1; /* cannot be changed, option_precise_width==0 must imply noaccel */
  1115. static int inv24; /* "matroxfb:inv24" */
  1116. static int cross4MB = -1; /* "matroxfb:cross4MB" */
  1117. static int disabled; /* "matroxfb:disabled" */
  1118. static int noaccel; /* "matroxfb:noaccel" */
  1119. static int nopan; /* "matroxfb:nopan" */
  1120. static int no_pci_retry; /* "matroxfb:nopciretry" */
  1121. static int novga; /* "matroxfb:novga" */
  1122. static int nobios; /* "matroxfb:nobios" */
  1123. static int noinit = 1; /* "matroxfb:init" */
  1124. static int inverse; /* "matroxfb:inverse" */
  1125. static int sgram; /* "matroxfb:sgram" */
  1126. static int mtrr = 1; /* "matroxfb:nomtrr" */
  1127. static int grayscale; /* "matroxfb:grayscale" */
  1128. static int dev = -1; /* "matroxfb:dev:xxxxx" */
  1129. static unsigned int vesa = ~0; /* "matroxfb:vesa:xxxxx" */
  1130. static int depth = -1; /* "matroxfb:depth:xxxxx" */
  1131. static unsigned int xres; /* "matroxfb:xres:xxxxx" */
  1132. static unsigned int yres; /* "matroxfb:yres:xxxxx" */
  1133. static unsigned int upper = ~0; /* "matroxfb:upper:xxxxx" */
  1134. static unsigned int lower = ~0; /* "matroxfb:lower:xxxxx" */
  1135. static unsigned int vslen; /* "matroxfb:vslen:xxxxx" */
  1136. static unsigned int left = ~0; /* "matroxfb:left:xxxxx" */
  1137. static unsigned int right = ~0; /* "matroxfb:right:xxxxx" */
  1138. static unsigned int hslen; /* "matroxfb:hslen:xxxxx" */
  1139. static unsigned int pixclock; /* "matroxfb:pixclock:xxxxx" */
  1140. static int sync = -1; /* "matroxfb:sync:xxxxx" */
  1141. static unsigned int fv; /* "matroxfb:fv:xxxxx" */
  1142. static unsigned int fh; /* "matroxfb:fh:xxxxxk" */
  1143. static unsigned int maxclk; /* "matroxfb:maxclk:xxxxM" */
  1144. static int dfp; /* "matroxfb:dfp */
  1145. static int dfp_type = -1; /* "matroxfb:dfp:xxx */
  1146. static int memtype = -1; /* "matroxfb:memtype:xxx" */
  1147. static char outputs[8]; /* "matroxfb:outputs:xxx" */
  1148. #ifndef MODULE
  1149. static char videomode[64]; /* "matroxfb:mode:xxxxx" or "matroxfb:xxxxx" */
  1150. #endif
  1151. static int matroxfb_getmemory(struct matrox_fb_info *minfo,
  1152. unsigned int maxSize, unsigned int *realSize)
  1153. {
  1154. vaddr_t vm;
  1155. unsigned int offs;
  1156. unsigned int offs2;
  1157. unsigned char orig;
  1158. unsigned char bytes[32];
  1159. unsigned char* tmp;
  1160. DBG(__func__)
  1161. vm = minfo->video.vbase;
  1162. maxSize &= ~0x1FFFFF; /* must be X*2MB (really it must be 2 or X*4MB) */
  1163. /* at least 2MB */
  1164. if (maxSize < 0x0200000) return 0;
  1165. if (maxSize > 0x2000000) maxSize = 0x2000000;
  1166. mga_outb(M_EXTVGA_INDEX, 0x03);
  1167. orig = mga_inb(M_EXTVGA_DATA);
  1168. mga_outb(M_EXTVGA_DATA, orig | 0x80);
  1169. tmp = bytes;
  1170. for (offs = 0x100000; offs < maxSize; offs += 0x200000)
  1171. *tmp++ = mga_readb(vm, offs);
  1172. for (offs = 0x100000; offs < maxSize; offs += 0x200000)
  1173. mga_writeb(vm, offs, 0x02);
  1174. mga_outb(M_CACHEFLUSH, 0x00);
  1175. for (offs = 0x100000; offs < maxSize; offs += 0x200000) {
  1176. if (mga_readb(vm, offs) != 0x02)
  1177. break;
  1178. mga_writeb(vm, offs, mga_readb(vm, offs) - 0x02);
  1179. if (mga_readb(vm, offs))
  1180. break;
  1181. }
  1182. tmp = bytes;
  1183. for (offs2 = 0x100000; offs2 < maxSize; offs2 += 0x200000)
  1184. mga_writeb(vm, offs2, *tmp++);
  1185. mga_outb(M_EXTVGA_INDEX, 0x03);
  1186. mga_outb(M_EXTVGA_DATA, orig);
  1187. *realSize = offs - 0x100000;
  1188. #ifdef CONFIG_FB_MATROX_MILLENIUM
  1189. minfo->interleave = !(!isMillenium(minfo) || ((offs - 0x100000) & 0x3FFFFF));
  1190. #endif
  1191. return 1;
  1192. }
  1193. struct video_board {
  1194. int maxvram;
  1195. int maxdisplayable;
  1196. int accelID;
  1197. struct matrox_switch* lowlevel;
  1198. };
  1199. #ifdef CONFIG_FB_MATROX_MILLENIUM
  1200. static struct video_board vbMillennium = {
  1201. .maxvram = 0x0800000,
  1202. .maxdisplayable = 0x0800000,
  1203. .accelID = FB_ACCEL_MATROX_MGA2064W,
  1204. .lowlevel = &matrox_millennium
  1205. };
  1206. static struct video_board vbMillennium2 = {
  1207. .maxvram = 0x1000000,
  1208. .maxdisplayable = 0x0800000,
  1209. .accelID = FB_ACCEL_MATROX_MGA2164W,
  1210. .lowlevel = &matrox_millennium
  1211. };
  1212. static struct video_board vbMillennium2A = {
  1213. .maxvram = 0x1000000,
  1214. .maxdisplayable = 0x0800000,
  1215. .accelID = FB_ACCEL_MATROX_MGA2164W_AGP,
  1216. .lowlevel = &matrox_millennium
  1217. };
  1218. #endif /* CONFIG_FB_MATROX_MILLENIUM */
  1219. #ifdef CONFIG_FB_MATROX_MYSTIQUE
  1220. static struct video_board vbMystique = {
  1221. .maxvram = 0x0800000,
  1222. .maxdisplayable = 0x0800000,
  1223. .accelID = FB_ACCEL_MATROX_MGA1064SG,
  1224. .lowlevel = &matrox_mystique
  1225. };
  1226. #endif /* CONFIG_FB_MATROX_MYSTIQUE */
  1227. #ifdef CONFIG_FB_MATROX_G
  1228. static struct video_board vbG100 = {
  1229. .maxvram = 0x0800000,
  1230. .maxdisplayable = 0x0800000,
  1231. .accelID = FB_ACCEL_MATROX_MGAG100,
  1232. .lowlevel = &matrox_G100
  1233. };
  1234. static struct video_board vbG200 = {
  1235. .maxvram = 0x1000000,
  1236. .maxdisplayable = 0x1000000,
  1237. .accelID = FB_ACCEL_MATROX_MGAG200,
  1238. .lowlevel = &matrox_G100
  1239. };
  1240. static struct video_board vbG200eW = {
  1241. .maxvram = 0x1000000,
  1242. .maxdisplayable = 0x0800000,
  1243. .accelID = FB_ACCEL_MATROX_MGAG200,
  1244. .lowlevel = &matrox_G100
  1245. };
  1246. /* from doc it looks like that accelerator can draw only to low 16MB :-( Direct accesses & displaying are OK for
  1247. whole 32MB */
  1248. static struct video_board vbG400 = {
  1249. .maxvram = 0x2000000,
  1250. .maxdisplayable = 0x1000000,
  1251. .accelID = FB_ACCEL_MATROX_MGAG400,
  1252. .lowlevel = &matrox_G100
  1253. };
  1254. #endif
  1255. #define DEVF_VIDEO64BIT 0x0001
  1256. #define DEVF_SWAPS 0x0002
  1257. #define DEVF_SRCORG 0x0004
  1258. #define DEVF_DUALHEAD 0x0008
  1259. #define DEVF_CROSS4MB 0x0010
  1260. #define DEVF_TEXT4B 0x0020
  1261. /* #define DEVF_recycled 0x0040 */
  1262. /* #define DEVF_recycled 0x0080 */
  1263. #define DEVF_SUPPORT32MB 0x0100
  1264. #define DEVF_ANY_VXRES 0x0200
  1265. #define DEVF_TEXT16B 0x0400
  1266. #define DEVF_CRTC2 0x0800
  1267. #define DEVF_MAVEN_CAPABLE 0x1000
  1268. #define DEVF_PANELLINK_CAPABLE 0x2000
  1269. #define DEVF_G450DAC 0x4000
  1270. #define DEVF_GCORE (DEVF_VIDEO64BIT | DEVF_SWAPS | DEVF_CROSS4MB)
  1271. #define DEVF_G2CORE (DEVF_GCORE | DEVF_ANY_VXRES | DEVF_MAVEN_CAPABLE | DEVF_PANELLINK_CAPABLE | DEVF_SRCORG | DEVF_DUALHEAD)
  1272. #define DEVF_G100 (DEVF_GCORE) /* no doc, no vxres... */
  1273. #define DEVF_G200 (DEVF_G2CORE)
  1274. #define DEVF_G400 (DEVF_G2CORE | DEVF_SUPPORT32MB | DEVF_TEXT16B | DEVF_CRTC2)
  1275. /* if you'll find how to drive DFP... */
  1276. #define DEVF_G450 (DEVF_GCORE | DEVF_ANY_VXRES | DEVF_SUPPORT32MB | DEVF_TEXT16B | DEVF_CRTC2 | DEVF_G450DAC | DEVF_SRCORG | DEVF_DUALHEAD)
  1277. #define DEVF_G550 (DEVF_G450)
  1278. static struct board {
  1279. unsigned short vendor, device, rev, svid, sid;
  1280. unsigned int flags;
  1281. unsigned int maxclk;
  1282. enum mga_chip chip;
  1283. struct video_board* base;
  1284. const char* name;
  1285. } dev_list[] = {
  1286. #ifdef CONFIG_FB_MATROX_MILLENIUM
  1287. {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_MIL, 0xFF,
  1288. 0, 0,
  1289. DEVF_TEXT4B,
  1290. 230000,
  1291. MGA_2064,
  1292. &vbMillennium,
  1293. "Millennium (PCI)"},
  1294. {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_MIL_2, 0xFF,
  1295. 0, 0,
  1296. DEVF_SWAPS,
  1297. 220000,
  1298. MGA_2164,
  1299. &vbMillennium2,
  1300. "Millennium II (PCI)"},
  1301. {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_MIL_2_AGP, 0xFF,
  1302. 0, 0,
  1303. DEVF_SWAPS,
  1304. 250000,
  1305. MGA_2164,
  1306. &vbMillennium2A,
  1307. "Millennium II (AGP)"},
  1308. #endif
  1309. #ifdef CONFIG_FB_MATROX_MYSTIQUE
  1310. {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_MYS, 0x02,
  1311. 0, 0,
  1312. DEVF_VIDEO64BIT | DEVF_CROSS4MB,
  1313. 180000,
  1314. MGA_1064,
  1315. &vbMystique,
  1316. "Mystique (PCI)"},
  1317. {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_MYS, 0xFF,
  1318. 0, 0,
  1319. DEVF_VIDEO64BIT | DEVF_SWAPS | DEVF_CROSS4MB,
  1320. 220000,
  1321. MGA_1164,
  1322. &vbMystique,
  1323. "Mystique 220 (PCI)"},
  1324. {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_MYS_AGP, 0x02,
  1325. 0, 0,
  1326. DEVF_VIDEO64BIT | DEVF_CROSS4MB,
  1327. 180000,
  1328. MGA_1064,
  1329. &vbMystique,
  1330. "Mystique (AGP)"},
  1331. {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_MYS_AGP, 0xFF,
  1332. 0, 0,
  1333. DEVF_VIDEO64BIT | DEVF_SWAPS | DEVF_CROSS4MB,
  1334. 220000,
  1335. MGA_1164,
  1336. &vbMystique,
  1337. "Mystique 220 (AGP)"},
  1338. #endif
  1339. #ifdef CONFIG_FB_MATROX_G
  1340. {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G100_MM, 0xFF,
  1341. 0, 0,
  1342. DEVF_G100,
  1343. 230000,
  1344. MGA_G100,
  1345. &vbG100,
  1346. "MGA-G100 (PCI)"},
  1347. {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G100_AGP, 0xFF,
  1348. 0, 0,
  1349. DEVF_G100,
  1350. 230000,
  1351. MGA_G100,
  1352. &vbG100,
  1353. "MGA-G100 (AGP)"},
  1354. {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_PCI, 0xFF,
  1355. 0, 0,
  1356. DEVF_G200,
  1357. 250000,
  1358. MGA_G200,
  1359. &vbG200,
  1360. "MGA-G200 (PCI)"},
  1361. {PCI_VENDOR_ID_MATROX, 0x0532, 0xFF,
  1362. 0, 0,
  1363. DEVF_G200,
  1364. 250000,
  1365. MGA_G200,
  1366. &vbG200eW,
  1367. "MGA-G200eW (PCI)"},
  1368. {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_AGP, 0xFF,
  1369. PCI_SS_VENDOR_ID_MATROX, PCI_SS_ID_MATROX_GENERIC,
  1370. DEVF_G200,
  1371. 220000,
  1372. MGA_G200,
  1373. &vbG200,
  1374. "MGA-G200 (AGP)"},
  1375. {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_AGP, 0xFF,
  1376. PCI_SS_VENDOR_ID_MATROX, PCI_SS_ID_MATROX_MYSTIQUE_G200_AGP,
  1377. DEVF_G200,
  1378. 230000,
  1379. MGA_G200,
  1380. &vbG200,
  1381. "Mystique G200 (AGP)"},
  1382. {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_AGP, 0xFF,
  1383. PCI_SS_VENDOR_ID_MATROX, PCI_SS_ID_MATROX_MILLENIUM_G200_AGP,
  1384. DEVF_G200,
  1385. 250000,
  1386. MGA_G200,
  1387. &vbG200,
  1388. "Millennium G200 (AGP)"},
  1389. {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_AGP, 0xFF,
  1390. PCI_SS_VENDOR_ID_MATROX, PCI_SS_ID_MATROX_MARVEL_G200_AGP,
  1391. DEVF_G200,
  1392. 230000,
  1393. MGA_G200,
  1394. &vbG200,
  1395. "Marvel G200 (AGP)"},
  1396. {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_AGP, 0xFF,
  1397. PCI_SS_VENDOR_ID_SIEMENS_NIXDORF, PCI_SS_ID_SIEMENS_MGA_G200_AGP,
  1398. DEVF_G200,
  1399. 230000,
  1400. MGA_G200,
  1401. &vbG200,
  1402. "MGA-G200 (AGP)"},
  1403. {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_AGP, 0xFF,
  1404. 0, 0,
  1405. DEVF_G200,
  1406. 230000,
  1407. MGA_G200,
  1408. &vbG200,
  1409. "G200 (AGP)"},
  1410. {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G400, 0x80,
  1411. PCI_SS_VENDOR_ID_MATROX, PCI_SS_ID_MATROX_MILLENNIUM_G400_MAX_AGP,
  1412. DEVF_G400,
  1413. 360000,
  1414. MGA_G400,
  1415. &vbG400,
  1416. "Millennium G400 MAX (AGP)"},
  1417. {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G400, 0x80,
  1418. 0, 0,
  1419. DEVF_G400,
  1420. 300000,
  1421. MGA_G400,
  1422. &vbG400,
  1423. "G400 (AGP)"},
  1424. {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G400, 0xFF,
  1425. 0, 0,
  1426. DEVF_G450,
  1427. 360000,
  1428. MGA_G450,
  1429. &vbG400,
  1430. "G450"},
  1431. {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G550, 0xFF,
  1432. 0, 0,
  1433. DEVF_G550,
  1434. 360000,
  1435. MGA_G550,
  1436. &vbG400,
  1437. "G550"},
  1438. #endif
  1439. {0, 0, 0xFF,
  1440. 0, 0,
  1441. 0,
  1442. 0,
  1443. 0,
  1444. NULL,
  1445. NULL}};
  1446. #ifndef MODULE
  1447. static const struct fb_videomode defaultmode = {
  1448. /* 640x480 @ 60Hz, 31.5 kHz */
  1449. NULL, 60, 640, 480, 39721, 40, 24, 32, 11, 96, 2,
  1450. 0, FB_VMODE_NONINTERLACED
  1451. };
  1452. static int hotplug = 0;
  1453. #endif /* !MODULE */
  1454. static void setDefaultOutputs(struct matrox_fb_info *minfo)
  1455. {
  1456. unsigned int i;
  1457. const char* ptr;
  1458. minfo->outputs[0].default_src = MATROXFB_SRC_CRTC1;
  1459. if (minfo->devflags.g450dac) {
  1460. minfo->outputs[1].default_src = MATROXFB_SRC_CRTC1;
  1461. minfo->outputs[2].default_src = MATROXFB_SRC_CRTC1;
  1462. } else if (dfp) {
  1463. minfo->outputs[2].default_src = MATROXFB_SRC_CRTC1;
  1464. }
  1465. ptr = outputs;
  1466. for (i = 0; i < MATROXFB_MAX_OUTPUTS; i++) {
  1467. char c = *ptr++;
  1468. if (c == 0) {
  1469. break;
  1470. }
  1471. if (c == '0') {
  1472. minfo->outputs[i].default_src = MATROXFB_SRC_NONE;
  1473. } else if (c == '1') {
  1474. minfo->outputs[i].default_src = MATROXFB_SRC_CRTC1;
  1475. } else if (c == '2' && minfo->devflags.crtc2) {
  1476. minfo->outputs[i].default_src = MATROXFB_SRC_CRTC2;
  1477. } else {
  1478. printk(KERN_ERR "matroxfb: Unknown outputs setting\n");
  1479. break;
  1480. }
  1481. }
  1482. /* Nullify this option for subsequent adapters */
  1483. outputs[0] = 0;
  1484. }
  1485. static int initMatrox2(struct matrox_fb_info *minfo, struct board *b)
  1486. {
  1487. unsigned long ctrlptr_phys = 0;
  1488. unsigned long video_base_phys = 0;
  1489. unsigned int memsize;
  1490. int err;
  1491. static const struct pci_device_id intel_82437[] = {
  1492. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82437) },
  1493. { },
  1494. };
  1495. DBG(__func__)
  1496. /* set default values... */
  1497. vesafb_defined.accel_flags = FB_ACCELF_TEXT;
  1498. minfo->hw_switch = b->base->lowlevel;
  1499. minfo->devflags.accelerator = b->base->accelID;
  1500. minfo->max_pixel_clock = b->maxclk;
  1501. printk(KERN_INFO "matroxfb: Matrox %s detected\n", b->name);
  1502. minfo->capable.plnwt = 1;
  1503. minfo->chip = b->chip;
  1504. minfo->capable.srcorg = b->flags & DEVF_SRCORG;
  1505. minfo->devflags.video64bits = b->flags & DEVF_VIDEO64BIT;
  1506. if (b->flags & DEVF_TEXT4B) {
  1507. minfo->devflags.vgastep = 4;
  1508. minfo->devflags.textmode = 4;
  1509. minfo->devflags.text_type_aux = FB_AUX_TEXT_MGA_STEP16;
  1510. } else if (b->flags & DEVF_TEXT16B) {
  1511. minfo->devflags.vgastep = 16;
  1512. minfo->devflags.textmode = 1;
  1513. minfo->devflags.text_type_aux = FB_AUX_TEXT_MGA_STEP16;
  1514. } else {
  1515. minfo->devflags.vgastep = 8;
  1516. minfo->devflags.textmode = 1;
  1517. minfo->devflags.text_type_aux = FB_AUX_TEXT_MGA_STEP8;
  1518. }
  1519. minfo->devflags.support32MB = (b->flags & DEVF_SUPPORT32MB) != 0;
  1520. minfo->devflags.precise_width = !(b->flags & DEVF_ANY_VXRES);
  1521. minfo->devflags.crtc2 = (b->flags & DEVF_CRTC2) != 0;
  1522. minfo->devflags.maven_capable = (b->flags & DEVF_MAVEN_CAPABLE) != 0;
  1523. minfo->devflags.dualhead = (b->flags & DEVF_DUALHEAD) != 0;
  1524. minfo->devflags.dfp_type = dfp_type;
  1525. minfo->devflags.g450dac = (b->flags & DEVF_G450DAC) != 0;
  1526. minfo->devflags.textstep = minfo->devflags.vgastep * minfo->devflags.textmode;
  1527. minfo->devflags.textvram = 65536 / minfo->devflags.textmode;
  1528. setDefaultOutputs(minfo);
  1529. if (b->flags & DEVF_PANELLINK_CAPABLE) {
  1530. minfo->outputs[2].data = minfo;
  1531. minfo->outputs[2].output = &panellink_output;
  1532. minfo->outputs[2].src = minfo->outputs[2].default_src;
  1533. minfo->outputs[2].mode = MATROXFB_OUTPUT_MODE_MONITOR;
  1534. minfo->devflags.panellink = 1;
  1535. }
  1536. if (minfo->capable.cross4MB < 0)
  1537. minfo->capable.cross4MB = b->flags & DEVF_CROSS4MB;
  1538. if (b->flags & DEVF_SWAPS) {
  1539. ctrlptr_phys = pci_resource_start(minfo->pcidev, 1);
  1540. video_base_phys = pci_resource_start(minfo->pcidev, 0);
  1541. minfo->devflags.fbResource = PCI_BASE_ADDRESS_0;
  1542. } else {
  1543. ctrlptr_phys = pci_resource_start(minfo->pcidev, 0);
  1544. video_base_phys = pci_resource_start(minfo->pcidev, 1);
  1545. minfo->devflags.fbResource = PCI_BASE_ADDRESS_1;
  1546. }
  1547. err = -EINVAL;
  1548. if (!ctrlptr_phys) {
  1549. printk(KERN_ERR "matroxfb: control registers are not available, matroxfb disabled\n");
  1550. goto fail;
  1551. }
  1552. if (!video_base_phys) {
  1553. printk(KERN_ERR "matroxfb: video RAM is not available in PCI address space, matroxfb disabled\n");
  1554. goto fail;
  1555. }
  1556. memsize = b->base->maxvram;
  1557. if (!request_mem_region(ctrlptr_phys, 16384, "matroxfb MMIO")) {
  1558. goto fail;
  1559. }
  1560. if (!request_mem_region(video_base_phys, memsize, "matroxfb FB")) {
  1561. goto failCtrlMR;
  1562. }
  1563. minfo->video.len_maximum = memsize;
  1564. /* convert mem (autodetect k, M) */
  1565. if (mem < 1024) mem *= 1024;
  1566. if (mem < 0x00100000) mem *= 1024;
  1567. if (mem && (mem < memsize))
  1568. memsize = mem;
  1569. err = -ENOMEM;
  1570. minfo->mmio.vbase.vaddr = ioremap(ctrlptr_phys, 16384);
  1571. if (!minfo->mmio.vbase.vaddr) {
  1572. printk(KERN_ERR "matroxfb: cannot ioremap(%lX, 16384), matroxfb disabled\n", ctrlptr_phys);
  1573. goto failVideoMR;
  1574. }
  1575. minfo->mmio.base = ctrlptr_phys;
  1576. minfo->mmio.len = 16384;
  1577. minfo->video.base = video_base_phys;
  1578. minfo->video.vbase.vaddr = ioremap_wc(video_base_phys, memsize);
  1579. if (!minfo->video.vbase.vaddr) {
  1580. printk(KERN_ERR "matroxfb: cannot ioremap(%lX, %d), matroxfb disabled\n",
  1581. video_base_phys, memsize);
  1582. goto failCtrlIO;
  1583. }
  1584. {
  1585. u_int32_t cmd;
  1586. u_int32_t mga_option;
  1587. pci_read_config_dword(minfo->pcidev, PCI_OPTION_REG, &mga_option);
  1588. pci_read_config_dword(minfo->pcidev, PCI_COMMAND, &cmd);
  1589. mga_option &= 0x7FFFFFFF; /* clear BIG_ENDIAN */
  1590. mga_option |= MX_OPTION_BSWAP;
  1591. /* disable palette snooping */
  1592. cmd &= ~PCI_COMMAND_VGA_PALETTE;
  1593. if (pci_dev_present(intel_82437)) {
  1594. if (!(mga_option & 0x20000000) && !minfo->devflags.nopciretry) {
  1595. printk(KERN_WARNING "matroxfb: Disabling PCI retries due to i82437 present\n");
  1596. }
  1597. mga_option |= 0x20000000;
  1598. minfo->devflags.nopciretry = 1;
  1599. }
  1600. pci_write_config_dword(minfo->pcidev, PCI_COMMAND, cmd);
  1601. pci_write_config_dword(minfo->pcidev, PCI_OPTION_REG, mga_option);
  1602. minfo->hw.MXoptionReg = mga_option;
  1603. /* select non-DMA memory for PCI_MGA_DATA, otherwise dump of PCI cfg space can lock PCI bus */
  1604. /* maybe preinit() candidate, but it is same... for all devices... at this time... */
  1605. pci_write_config_dword(minfo->pcidev, PCI_MGA_INDEX, 0x00003C00);
  1606. }
  1607. err = -ENXIO;
  1608. matroxfb_read_pins(minfo);
  1609. if (minfo->hw_switch->preinit(minfo)) {
  1610. goto failVideoIO;
  1611. }
  1612. err = -ENOMEM;
  1613. if (!matroxfb_getmemory(minfo, memsize, &minfo->video.len) || !minfo->video.len) {
  1614. printk(KERN_ERR "matroxfb: cannot determine memory size\n");
  1615. goto failVideoIO;
  1616. }
  1617. minfo->devflags.ydstorg = 0;
  1618. minfo->video.base = video_base_phys;
  1619. minfo->video.len_usable = minfo->video.len;
  1620. if (minfo->video.len_usable > b->base->maxdisplayable)
  1621. minfo->video.len_usable = b->base->maxdisplayable;
  1622. if (mtrr)
  1623. minfo->wc_cookie = arch_phys_wc_add(video_base_phys,
  1624. minfo->video.len);
  1625. if (!minfo->devflags.novga)
  1626. request_region(0x3C0, 32, "matrox");
  1627. matroxfb_g450_connect(minfo);
  1628. minfo->hw_switch->reset(minfo);
  1629. minfo->fbcon.monspecs.hfmin = 0;
  1630. minfo->fbcon.monspecs.hfmax = fh;
  1631. minfo->fbcon.monspecs.vfmin = 0;
  1632. minfo->fbcon.monspecs.vfmax = fv;
  1633. minfo->fbcon.monspecs.dpms = 0; /* TBD */
  1634. /* static settings */
  1635. vesafb_defined.red = colors[depth-1].red;
  1636. vesafb_defined.green = colors[depth-1].green;
  1637. vesafb_defined.blue = colors[depth-1].blue;
  1638. vesafb_defined.bits_per_pixel = colors[depth-1].bits_per_pixel;
  1639. vesafb_defined.grayscale = grayscale;
  1640. vesafb_defined.vmode = 0;
  1641. if (noaccel)
  1642. vesafb_defined.accel_flags &= ~FB_ACCELF_TEXT;
  1643. minfo->fbops = matroxfb_ops;
  1644. minfo->fbcon.fbops = &minfo->fbops;
  1645. minfo->fbcon.pseudo_palette = minfo->cmap;
  1646. minfo->fbcon.flags = FBINFO_PARTIAL_PAN_OK | /* Prefer panning for scroll under MC viewer/edit */
  1647. FBINFO_HWACCEL_COPYAREA | /* We have hw-assisted bmove */
  1648. FBINFO_HWACCEL_FILLRECT | /* And fillrect */
  1649. FBINFO_HWACCEL_IMAGEBLIT | /* And imageblit */
  1650. FBINFO_HWACCEL_XPAN | /* And we support both horizontal */
  1651. FBINFO_HWACCEL_YPAN | /* And vertical panning */
  1652. FBINFO_READS_FAST;
  1653. minfo->video.len_usable &= PAGE_MASK;
  1654. fb_alloc_cmap(&minfo->fbcon.cmap, 256, 1);
  1655. #ifndef MODULE
  1656. /* mode database is marked __init!!! */
  1657. if (!hotplug) {
  1658. fb_find_mode(&vesafb_defined, &minfo->fbcon, videomode[0] ? videomode : NULL,
  1659. NULL, 0, &defaultmode, vesafb_defined.bits_per_pixel);
  1660. }
  1661. #endif /* !MODULE */
  1662. /* mode modifiers */
  1663. if (hslen)
  1664. vesafb_defined.hsync_len = hslen;
  1665. if (vslen)
  1666. vesafb_defined.vsync_len = vslen;
  1667. if (left != ~0)
  1668. vesafb_defined.left_margin = left;
  1669. if (right != ~0)
  1670. vesafb_defined.right_margin = right;
  1671. if (upper != ~0)
  1672. vesafb_defined.upper_margin = upper;
  1673. if (lower != ~0)
  1674. vesafb_defined.lower_margin = lower;
  1675. if (xres)
  1676. vesafb_defined.xres = xres;
  1677. if (yres)
  1678. vesafb_defined.yres = yres;
  1679. if (sync != -1)
  1680. vesafb_defined.sync = sync;
  1681. else if (vesafb_defined.sync == ~0) {
  1682. vesafb_defined.sync = 0;
  1683. if (yres < 400)
  1684. vesafb_defined.sync |= FB_SYNC_HOR_HIGH_ACT;
  1685. else if (yres < 480)
  1686. vesafb_defined.sync |= FB_SYNC_VERT_HIGH_ACT;
  1687. }
  1688. /* fv, fh, maxclk limits was specified */
  1689. {
  1690. unsigned int tmp;
  1691. if (fv) {
  1692. tmp = fv * (vesafb_defined.upper_margin + vesafb_defined.yres
  1693. + vesafb_defined.lower_margin + vesafb_defined.vsync_len);
  1694. if ((tmp < fh) || (fh == 0)) fh = tmp;
  1695. }
  1696. if (fh) {
  1697. tmp = fh * (vesafb_defined.left_margin + vesafb_defined.xres
  1698. + vesafb_defined.right_margin + vesafb_defined.hsync_len);
  1699. if ((tmp < maxclk) || (maxclk == 0)) maxclk = tmp;
  1700. }
  1701. tmp = (maxclk + 499) / 500;
  1702. if (tmp) {
  1703. tmp = (2000000000 + tmp) / tmp;
  1704. if (tmp > pixclock) pixclock = tmp;
  1705. }
  1706. }
  1707. if (pixclock) {
  1708. if (pixclock < 2000) /* > 500MHz */
  1709. pixclock = 4000; /* 250MHz */
  1710. if (pixclock > 1000000)
  1711. pixclock = 1000000; /* 1MHz */
  1712. vesafb_defined.pixclock = pixclock;
  1713. }
  1714. /* FIXME: Where to move this?! */
  1715. #if defined(CONFIG_PPC_PMAC)
  1716. #ifndef MODULE
  1717. if (machine_is(powermac)) {
  1718. struct fb_var_screeninfo var;
  1719. if (default_vmode <= 0 || default_vmode > VMODE_MAX)
  1720. default_vmode = VMODE_640_480_60;
  1721. #if defined(CONFIG_PPC32)
  1722. if (IS_REACHABLE(CONFIG_NVRAM) && default_cmode == CMODE_NVRAM)
  1723. default_cmode = nvram_read_byte(NV_CMODE);
  1724. #endif
  1725. if (default_cmode < CMODE_8 || default_cmode > CMODE_32)
  1726. default_cmode = CMODE_8;
  1727. if (!mac_vmode_to_var(default_vmode, default_cmode, &var)) {
  1728. var.accel_flags = vesafb_defined.accel_flags;
  1729. var.xoffset = var.yoffset = 0;
  1730. /* Note: mac_vmode_to_var() does not set all parameters */
  1731. vesafb_defined = var;
  1732. }
  1733. }
  1734. #endif /* !MODULE */
  1735. #endif /* CONFIG_PPC_PMAC */
  1736. vesafb_defined.xres_virtual = vesafb_defined.xres;
  1737. if (nopan) {
  1738. vesafb_defined.yres_virtual = vesafb_defined.yres;
  1739. } else {
  1740. vesafb_defined.yres_virtual = 65536; /* large enough to be INF, but small enough
  1741. to yres_virtual * xres_virtual < 2^32 */
  1742. }
  1743. matroxfb_init_fix(minfo);
  1744. minfo->fbcon.screen_base = vaddr_va(minfo->video.vbase);
  1745. /* Normalize values (namely yres_virtual) */
  1746. matroxfb_check_var(&vesafb_defined, &minfo->fbcon);
  1747. /* And put it into "current" var. Do NOT program hardware yet, or we'll not take over
  1748. * vgacon correctly. fbcon_startup will call fb_set_par for us, WITHOUT check_var,
  1749. * and unfortunately it will do it BEFORE vgacon contents is saved, so it won't work
  1750. * anyway. But we at least tried... */
  1751. minfo->fbcon.var = vesafb_defined;
  1752. err = -EINVAL;
  1753. printk(KERN_INFO "matroxfb: %dx%dx%dbpp (virtual: %dx%d)\n",
  1754. vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel,
  1755. vesafb_defined.xres_virtual, vesafb_defined.yres_virtual);
  1756. printk(KERN_INFO "matroxfb: framebuffer at 0x%lX, mapped to 0x%p, size %d\n",
  1757. minfo->video.base, vaddr_va(minfo->video.vbase), minfo->video.len);
  1758. /* We do not have to set currcon to 0... register_framebuffer do it for us on first console
  1759. * and we do not want currcon == 0 for subsequent framebuffers */
  1760. minfo->fbcon.device = &minfo->pcidev->dev;
  1761. if (register_framebuffer(&minfo->fbcon) < 0) {
  1762. goto failVideoIO;
  1763. }
  1764. fb_info(&minfo->fbcon, "%s frame buffer device\n", minfo->fbcon.fix.id);
  1765. /* there is no console on this fb... but we have to initialize hardware
  1766. * until someone tells me what is proper thing to do */
  1767. if (!minfo->initialized) {
  1768. fb_info(&minfo->fbcon, "initializing hardware\n");
  1769. /* We have to use FB_ACTIVATE_FORCE, as we had to put vesafb_defined to the fbcon.var
  1770. * already before, so register_framebuffer works correctly. */
  1771. vesafb_defined.activate |= FB_ACTIVATE_FORCE;
  1772. fb_set_var(&minfo->fbcon, &vesafb_defined);
  1773. }
  1774. return 0;
  1775. failVideoIO:;
  1776. matroxfb_g450_shutdown(minfo);
  1777. iounmap(minfo->video.vbase.vaddr);
  1778. failCtrlIO:;
  1779. iounmap(minfo->mmio.vbase.vaddr);
  1780. failVideoMR:;
  1781. release_mem_region(video_base_phys, minfo->video.len_maximum);
  1782. failCtrlMR:;
  1783. release_mem_region(ctrlptr_phys, 16384);
  1784. fail:;
  1785. return err;
  1786. }
  1787. static LIST_HEAD(matroxfb_list);
  1788. static LIST_HEAD(matroxfb_driver_list);
  1789. #define matroxfb_l(x) list_entry(x, struct matrox_fb_info, next_fb)
  1790. #define matroxfb_driver_l(x) list_entry(x, struct matroxfb_driver, node)
  1791. int matroxfb_register_driver(struct matroxfb_driver* drv) {
  1792. struct matrox_fb_info* minfo;
  1793. list_add(&drv->node, &matroxfb_driver_list);
  1794. list_for_each_entry(minfo, &matroxfb_list, next_fb) {
  1795. void* p;
  1796. if (minfo->drivers_count == MATROXFB_MAX_FB_DRIVERS)
  1797. continue;
  1798. p = drv->probe(minfo);
  1799. if (p) {
  1800. minfo->drivers_data[minfo->drivers_count] = p;
  1801. minfo->drivers[minfo->drivers_count++] = drv;
  1802. }
  1803. }
  1804. return 0;
  1805. }
  1806. void matroxfb_unregister_driver(struct matroxfb_driver* drv) {
  1807. struct matrox_fb_info* minfo;
  1808. list_del(&drv->node);
  1809. list_for_each_entry(minfo, &matroxfb_list, next_fb) {
  1810. int i;
  1811. for (i = 0; i < minfo->drivers_count; ) {
  1812. if (minfo->drivers[i] == drv) {
  1813. if (drv && drv->remove)
  1814. drv->remove(minfo, minfo->drivers_data[i]);
  1815. minfo->drivers[i] = minfo->drivers[--minfo->drivers_count];
  1816. minfo->drivers_data[i] = minfo->drivers_data[minfo->drivers_count];
  1817. } else
  1818. i++;
  1819. }
  1820. }
  1821. }
  1822. static void matroxfb_register_device(struct matrox_fb_info* minfo) {
  1823. struct matroxfb_driver* drv;
  1824. int i = 0;
  1825. list_add(&minfo->next_fb, &matroxfb_list);
  1826. for (drv = matroxfb_driver_l(matroxfb_driver_list.next);
  1827. drv != matroxfb_driver_l(&matroxfb_driver_list);
  1828. drv = matroxfb_driver_l(drv->node.next)) {
  1829. if (drv->probe) {
  1830. void *p = drv->probe(minfo);
  1831. if (p) {
  1832. minfo->drivers_data[i] = p;
  1833. minfo->drivers[i++] = drv;
  1834. if (i == MATROXFB_MAX_FB_DRIVERS)
  1835. break;
  1836. }
  1837. }
  1838. }
  1839. minfo->drivers_count = i;
  1840. }
  1841. static void matroxfb_unregister_device(struct matrox_fb_info* minfo) {
  1842. int i;
  1843. list_del(&minfo->next_fb);
  1844. for (i = 0; i < minfo->drivers_count; i++) {
  1845. struct matroxfb_driver* drv = minfo->drivers[i];
  1846. if (drv && drv->remove)
  1847. drv->remove(minfo, minfo->drivers_data[i]);
  1848. }
  1849. }
  1850. static int matroxfb_probe(struct pci_dev* pdev, const struct pci_device_id* dummy) {
  1851. struct board* b;
  1852. u_int16_t svid;
  1853. u_int16_t sid;
  1854. struct matrox_fb_info* minfo;
  1855. int err;
  1856. u_int32_t cmd;
  1857. DBG(__func__)
  1858. err = aperture_remove_conflicting_pci_devices(pdev, "matroxfb");
  1859. if (err)
  1860. return err;
  1861. svid = pdev->subsystem_vendor;
  1862. sid = pdev->subsystem_device;
  1863. for (b = dev_list; b->vendor; b++) {
  1864. if ((b->vendor != pdev->vendor) || (b->device != pdev->device) || (b->rev < pdev->revision)) continue;
  1865. if (b->svid)
  1866. if ((b->svid != svid) || (b->sid != sid)) continue;
  1867. break;
  1868. }
  1869. /* not match... */
  1870. if (!b->vendor)
  1871. return -ENODEV;
  1872. if (dev > 0) {
  1873. /* not requested one... */
  1874. dev--;
  1875. return -ENODEV;
  1876. }
  1877. pci_read_config_dword(pdev, PCI_COMMAND, &cmd);
  1878. if (pci_enable_device(pdev)) {
  1879. return -1;
  1880. }
  1881. minfo = kzalloc_obj(*minfo);
  1882. if (!minfo)
  1883. return -ENOMEM;
  1884. minfo->pcidev = pdev;
  1885. minfo->dead = 0;
  1886. minfo->usecount = 0;
  1887. minfo->userusecount = 0;
  1888. pci_set_drvdata(pdev, minfo);
  1889. /* DEVFLAGS */
  1890. minfo->devflags.memtype = memtype;
  1891. if (memtype != -1)
  1892. noinit = 0;
  1893. if (cmd & PCI_COMMAND_MEMORY) {
  1894. minfo->devflags.novga = novga;
  1895. minfo->devflags.nobios = nobios;
  1896. minfo->devflags.noinit = noinit;
  1897. /* subsequent heads always needs initialization and must not enable BIOS */
  1898. novga = 1;
  1899. nobios = 1;
  1900. noinit = 0;
  1901. } else {
  1902. minfo->devflags.novga = 1;
  1903. minfo->devflags.nobios = 1;
  1904. minfo->devflags.noinit = 0;
  1905. }
  1906. minfo->devflags.nopciretry = no_pci_retry;
  1907. minfo->devflags.mga_24bpp_fix = inv24;
  1908. minfo->devflags.precise_width = option_precise_width;
  1909. minfo->devflags.sgram = sgram;
  1910. minfo->capable.cross4MB = cross4MB;
  1911. spin_lock_init(&minfo->lock.DAC);
  1912. spin_lock_init(&minfo->lock.accel);
  1913. init_rwsem(&minfo->crtc2.lock);
  1914. init_rwsem(&minfo->altout.lock);
  1915. mutex_init(&minfo->fbcon.mm_lock);
  1916. minfo->irq_flags = 0;
  1917. init_waitqueue_head(&minfo->crtc1.vsync.wait);
  1918. init_waitqueue_head(&minfo->crtc2.vsync.wait);
  1919. minfo->crtc1.panpos = -1;
  1920. err = initMatrox2(minfo, b);
  1921. if (!err) {
  1922. matroxfb_register_device(minfo);
  1923. return 0;
  1924. }
  1925. kfree(minfo);
  1926. return -1;
  1927. }
  1928. static void pci_remove_matrox(struct pci_dev* pdev) {
  1929. struct matrox_fb_info* minfo;
  1930. minfo = pci_get_drvdata(pdev);
  1931. matroxfb_remove(minfo, 1);
  1932. }
  1933. static const struct pci_device_id matroxfb_devices[] = {
  1934. #ifdef CONFIG_FB_MATROX_MILLENIUM
  1935. {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_MIL,
  1936. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  1937. {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_MIL_2,
  1938. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  1939. {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_MIL_2_AGP,
  1940. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  1941. #endif
  1942. #ifdef CONFIG_FB_MATROX_MYSTIQUE
  1943. {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_MYS,
  1944. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  1945. #endif
  1946. #ifdef CONFIG_FB_MATROX_G
  1947. {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G100_MM,
  1948. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  1949. {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G100_AGP,
  1950. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  1951. {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_PCI,
  1952. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  1953. {PCI_VENDOR_ID_MATROX, 0x0532,
  1954. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  1955. {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_AGP,
  1956. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  1957. {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G400,
  1958. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  1959. {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G550,
  1960. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  1961. #endif
  1962. {0, 0,
  1963. 0, 0, 0, 0, 0}
  1964. };
  1965. MODULE_DEVICE_TABLE(pci, matroxfb_devices);
  1966. static struct pci_driver matroxfb_driver = {
  1967. .name = "matroxfb",
  1968. .id_table = matroxfb_devices,
  1969. .probe = matroxfb_probe,
  1970. .remove = pci_remove_matrox,
  1971. };
  1972. /* **************************** init-time only **************************** */
  1973. #define RSResolution(X) ((X) & 0x0F)
  1974. #define RS640x400 1
  1975. #define RS640x480 2
  1976. #define RS800x600 3
  1977. #define RS1024x768 4
  1978. #define RS1280x1024 5
  1979. #define RS1600x1200 6
  1980. #define RS768x576 7
  1981. #define RS960x720 8
  1982. #define RS1152x864 9
  1983. #define RS1408x1056 10
  1984. #define RS640x350 11
  1985. #define RS1056x344 12 /* 132 x 43 text */
  1986. #define RS1056x400 13 /* 132 x 50 text */
  1987. #define RS1056x480 14 /* 132 x 60 text */
  1988. #define RSNoxNo 15
  1989. /* 10-FF */
  1990. static struct { int xres, yres, left, right, upper, lower, hslen, vslen, vfreq; } timmings[] __initdata = {
  1991. { 640, 400, 48, 16, 39, 8, 96, 2, 70 },
  1992. { 640, 480, 48, 16, 33, 10, 96, 2, 60 },
  1993. { 800, 600, 144, 24, 28, 8, 112, 6, 60 },
  1994. { 1024, 768, 160, 32, 30, 4, 128, 4, 60 },
  1995. { 1280, 1024, 224, 32, 32, 4, 136, 4, 60 },
  1996. { 1600, 1200, 272, 48, 32, 5, 152, 5, 60 },
  1997. { 768, 576, 144, 16, 28, 6, 112, 4, 60 },
  1998. { 960, 720, 144, 24, 28, 8, 112, 4, 60 },
  1999. { 1152, 864, 192, 32, 30, 4, 128, 4, 60 },
  2000. { 1408, 1056, 256, 40, 32, 5, 144, 5, 60 },
  2001. { 640, 350, 48, 16, 39, 8, 96, 2, 70 },
  2002. { 1056, 344, 96, 24, 59, 44, 160, 2, 70 },
  2003. { 1056, 400, 96, 24, 39, 8, 160, 2, 70 },
  2004. { 1056, 480, 96, 24, 36, 12, 160, 3, 60 },
  2005. { 0, 0, ~0, ~0, ~0, ~0, 0, 0, 0 }
  2006. };
  2007. #define RSCreate(X,Y) ((X) | ((Y) << 8))
  2008. static struct { unsigned int vesa; unsigned int info; } *RSptr, vesamap[] __initdata = {
  2009. /* default must be first */
  2010. { ~0, RSCreate(RSNoxNo, RS8bpp ) },
  2011. { 0x101, RSCreate(RS640x480, RS8bpp ) },
  2012. { 0x100, RSCreate(RS640x400, RS8bpp ) },
  2013. { 0x180, RSCreate(RS768x576, RS8bpp ) },
  2014. { 0x103, RSCreate(RS800x600, RS8bpp ) },
  2015. { 0x188, RSCreate(RS960x720, RS8bpp ) },
  2016. { 0x105, RSCreate(RS1024x768, RS8bpp ) },
  2017. { 0x190, RSCreate(RS1152x864, RS8bpp ) },
  2018. { 0x107, RSCreate(RS1280x1024, RS8bpp ) },
  2019. { 0x198, RSCreate(RS1408x1056, RS8bpp ) },
  2020. { 0x11C, RSCreate(RS1600x1200, RS8bpp ) },
  2021. { 0x110, RSCreate(RS640x480, RS15bpp) },
  2022. { 0x181, RSCreate(RS768x576, RS15bpp) },
  2023. { 0x113, RSCreate(RS800x600, RS15bpp) },
  2024. { 0x189, RSCreate(RS960x720, RS15bpp) },
  2025. { 0x116, RSCreate(RS1024x768, RS15bpp) },
  2026. { 0x191, RSCreate(RS1152x864, RS15bpp) },
  2027. { 0x119, RSCreate(RS1280x1024, RS15bpp) },
  2028. { 0x199, RSCreate(RS1408x1056, RS15bpp) },
  2029. { 0x11D, RSCreate(RS1600x1200, RS15bpp) },
  2030. { 0x111, RSCreate(RS640x480, RS16bpp) },
  2031. { 0x182, RSCreate(RS768x576, RS16bpp) },
  2032. { 0x114, RSCreate(RS800x600, RS16bpp) },
  2033. { 0x18A, RSCreate(RS960x720, RS16bpp) },
  2034. { 0x117, RSCreate(RS1024x768, RS16bpp) },
  2035. { 0x192, RSCreate(RS1152x864, RS16bpp) },
  2036. { 0x11A, RSCreate(RS1280x1024, RS16bpp) },
  2037. { 0x19A, RSCreate(RS1408x1056, RS16bpp) },
  2038. { 0x11E, RSCreate(RS1600x1200, RS16bpp) },
  2039. { 0x1B2, RSCreate(RS640x480, RS24bpp) },
  2040. { 0x184, RSCreate(RS768x576, RS24bpp) },
  2041. { 0x1B5, RSCreate(RS800x600, RS24bpp) },
  2042. { 0x18C, RSCreate(RS960x720, RS24bpp) },
  2043. { 0x1B8, RSCreate(RS1024x768, RS24bpp) },
  2044. { 0x194, RSCreate(RS1152x864, RS24bpp) },
  2045. { 0x1BB, RSCreate(RS1280x1024, RS24bpp) },
  2046. { 0x19C, RSCreate(RS1408x1056, RS24bpp) },
  2047. { 0x1BF, RSCreate(RS1600x1200, RS24bpp) },
  2048. { 0x112, RSCreate(RS640x480, RS32bpp) },
  2049. { 0x183, RSCreate(RS768x576, RS32bpp) },
  2050. { 0x115, RSCreate(RS800x600, RS32bpp) },
  2051. { 0x18B, RSCreate(RS960x720, RS32bpp) },
  2052. { 0x118, RSCreate(RS1024x768, RS32bpp) },
  2053. { 0x193, RSCreate(RS1152x864, RS32bpp) },
  2054. { 0x11B, RSCreate(RS1280x1024, RS32bpp) },
  2055. { 0x19B, RSCreate(RS1408x1056, RS32bpp) },
  2056. { 0x11F, RSCreate(RS1600x1200, RS32bpp) },
  2057. { 0x010, RSCreate(RS640x350, RS4bpp ) },
  2058. { 0x012, RSCreate(RS640x480, RS4bpp ) },
  2059. { 0x102, RSCreate(RS800x600, RS4bpp ) },
  2060. { 0x104, RSCreate(RS1024x768, RS4bpp ) },
  2061. { 0x106, RSCreate(RS1280x1024, RS4bpp ) },
  2062. { 0, 0 }};
  2063. static void __init matroxfb_init_params(void) {
  2064. /* fh from kHz to Hz */
  2065. if (fh < 1000)
  2066. fh *= 1000; /* 1kHz minimum */
  2067. /* maxclk */
  2068. if (maxclk < 1000) maxclk *= 1000; /* kHz -> Hz, MHz -> kHz */
  2069. if (maxclk < 1000000) maxclk *= 1000; /* kHz -> Hz, 1MHz minimum */
  2070. /* fix VESA number */
  2071. if (vesa != ~0)
  2072. vesa &= 0x1DFF; /* mask out clearscreen, acceleration and so on */
  2073. /* static settings */
  2074. for (RSptr = vesamap; RSptr->vesa; RSptr++) {
  2075. if (RSptr->vesa == vesa) break;
  2076. }
  2077. if (!RSptr->vesa) {
  2078. printk(KERN_ERR "Invalid vesa mode 0x%04X\n", vesa);
  2079. RSptr = vesamap;
  2080. }
  2081. {
  2082. int res = RSResolution(RSptr->info)-1;
  2083. if (left == ~0)
  2084. left = timmings[res].left;
  2085. if (!xres)
  2086. xres = timmings[res].xres;
  2087. if (right == ~0)
  2088. right = timmings[res].right;
  2089. if (!hslen)
  2090. hslen = timmings[res].hslen;
  2091. if (upper == ~0)
  2092. upper = timmings[res].upper;
  2093. if (!yres)
  2094. yres = timmings[res].yres;
  2095. if (lower == ~0)
  2096. lower = timmings[res].lower;
  2097. if (!vslen)
  2098. vslen = timmings[res].vslen;
  2099. if (!(fv||fh||maxclk||pixclock))
  2100. fv = timmings[res].vfreq;
  2101. if (depth == -1)
  2102. depth = RSDepth(RSptr->info);
  2103. }
  2104. }
  2105. static int __init matrox_init(void) {
  2106. int err;
  2107. if (fb_modesetting_disabled("matroxfb"))
  2108. return -ENODEV;
  2109. matroxfb_init_params();
  2110. err = pci_register_driver(&matroxfb_driver);
  2111. dev = -1; /* accept all new devices... */
  2112. return err;
  2113. }
  2114. /* **************************** exit-time only **************************** */
  2115. static void __exit matrox_done(void) {
  2116. pci_unregister_driver(&matroxfb_driver);
  2117. }
  2118. #ifndef MODULE
  2119. /* ************************* init in-kernel code ************************** */
  2120. static int __init matroxfb_setup(char *options) {
  2121. char *this_opt;
  2122. DBG(__func__)
  2123. if (!options || !*options)
  2124. return 0;
  2125. while ((this_opt = strsep(&options, ",")) != NULL) {
  2126. if (!*this_opt) continue;
  2127. dprintk("matroxfb_setup: option %s\n", this_opt);
  2128. if (!strncmp(this_opt, "dev:", 4))
  2129. dev = simple_strtoul(this_opt+4, NULL, 0);
  2130. else if (!strncmp(this_opt, "depth:", 6)) {
  2131. switch (simple_strtoul(this_opt+6, NULL, 0)) {
  2132. case 0: depth = RSText; break;
  2133. case 4: depth = RS4bpp; break;
  2134. case 8: depth = RS8bpp; break;
  2135. case 15:depth = RS15bpp; break;
  2136. case 16:depth = RS16bpp; break;
  2137. case 24:depth = RS24bpp; break;
  2138. case 32:depth = RS32bpp; break;
  2139. default:
  2140. printk(KERN_ERR "matroxfb: unsupported color depth\n");
  2141. }
  2142. } else if (!strncmp(this_opt, "xres:", 5))
  2143. xres = simple_strtoul(this_opt+5, NULL, 0);
  2144. else if (!strncmp(this_opt, "yres:", 5))
  2145. yres = simple_strtoul(this_opt+5, NULL, 0);
  2146. else if (!strncmp(this_opt, "vslen:", 6))
  2147. vslen = simple_strtoul(this_opt+6, NULL, 0);
  2148. else if (!strncmp(this_opt, "hslen:", 6))
  2149. hslen = simple_strtoul(this_opt+6, NULL, 0);
  2150. else if (!strncmp(this_opt, "left:", 5))
  2151. left = simple_strtoul(this_opt+5, NULL, 0);
  2152. else if (!strncmp(this_opt, "right:", 6))
  2153. right = simple_strtoul(this_opt+6, NULL, 0);
  2154. else if (!strncmp(this_opt, "upper:", 6))
  2155. upper = simple_strtoul(this_opt+6, NULL, 0);
  2156. else if (!strncmp(this_opt, "lower:", 6))
  2157. lower = simple_strtoul(this_opt+6, NULL, 0);
  2158. else if (!strncmp(this_opt, "pixclock:", 9))
  2159. pixclock = simple_strtoul(this_opt+9, NULL, 0);
  2160. else if (!strncmp(this_opt, "sync:", 5))
  2161. sync = simple_strtoul(this_opt+5, NULL, 0);
  2162. else if (!strncmp(this_opt, "vesa:", 5))
  2163. vesa = simple_strtoul(this_opt+5, NULL, 0);
  2164. else if (!strncmp(this_opt, "maxclk:", 7))
  2165. maxclk = simple_strtoul(this_opt+7, NULL, 0);
  2166. else if (!strncmp(this_opt, "fh:", 3))
  2167. fh = simple_strtoul(this_opt+3, NULL, 0);
  2168. else if (!strncmp(this_opt, "fv:", 3))
  2169. fv = simple_strtoul(this_opt+3, NULL, 0);
  2170. else if (!strncmp(this_opt, "mem:", 4))
  2171. mem = simple_strtoul(this_opt+4, NULL, 0);
  2172. else if (!strncmp(this_opt, "mode:", 5))
  2173. strscpy(videomode, this_opt + 5, sizeof(videomode));
  2174. else if (!strncmp(this_opt, "outputs:", 8))
  2175. strscpy(outputs, this_opt + 8, sizeof(outputs));
  2176. else if (!strncmp(this_opt, "dfp:", 4)) {
  2177. dfp_type = simple_strtoul(this_opt+4, NULL, 0);
  2178. dfp = 1;
  2179. }
  2180. #ifdef CONFIG_PPC_PMAC
  2181. else if (!strncmp(this_opt, "vmode:", 6)) {
  2182. unsigned int vmode = simple_strtoul(this_opt+6, NULL, 0);
  2183. if (vmode > 0 && vmode <= VMODE_MAX)
  2184. default_vmode = vmode;
  2185. } else if (!strncmp(this_opt, "cmode:", 6)) {
  2186. unsigned int cmode = simple_strtoul(this_opt+6, NULL, 0);
  2187. switch (cmode) {
  2188. case 0:
  2189. case 8:
  2190. default_cmode = CMODE_8;
  2191. break;
  2192. case 15:
  2193. case 16:
  2194. default_cmode = CMODE_16;
  2195. break;
  2196. case 24:
  2197. case 32:
  2198. default_cmode = CMODE_32;
  2199. break;
  2200. }
  2201. }
  2202. #endif
  2203. else if (!strcmp(this_opt, "disabled")) /* nodisabled does not exist */
  2204. disabled = 1;
  2205. else if (!strcmp(this_opt, "enabled")) /* noenabled does not exist */
  2206. disabled = 0;
  2207. else if (!strcmp(this_opt, "sgram")) /* nosgram == sdram */
  2208. sgram = 1;
  2209. else if (!strcmp(this_opt, "sdram"))
  2210. sgram = 0;
  2211. else if (!strncmp(this_opt, "memtype:", 8))
  2212. memtype = simple_strtoul(this_opt+8, NULL, 0);
  2213. else {
  2214. int value = 1;
  2215. if (!strncmp(this_opt, "no", 2)) {
  2216. value = 0;
  2217. this_opt += 2;
  2218. }
  2219. if (! strcmp(this_opt, "inverse"))
  2220. inverse = value;
  2221. else if (!strcmp(this_opt, "accel"))
  2222. noaccel = !value;
  2223. else if (!strcmp(this_opt, "pan"))
  2224. nopan = !value;
  2225. else if (!strcmp(this_opt, "pciretry"))
  2226. no_pci_retry = !value;
  2227. else if (!strcmp(this_opt, "vga"))
  2228. novga = !value;
  2229. else if (!strcmp(this_opt, "bios"))
  2230. nobios = !value;
  2231. else if (!strcmp(this_opt, "init"))
  2232. noinit = !value;
  2233. else if (!strcmp(this_opt, "mtrr"))
  2234. mtrr = value;
  2235. else if (!strcmp(this_opt, "inv24"))
  2236. inv24 = value;
  2237. else if (!strcmp(this_opt, "cross4MB"))
  2238. cross4MB = value;
  2239. else if (!strcmp(this_opt, "grayscale"))
  2240. grayscale = value;
  2241. else if (!strcmp(this_opt, "dfp"))
  2242. dfp = value;
  2243. else {
  2244. strscpy(videomode, this_opt, sizeof(videomode));
  2245. }
  2246. }
  2247. }
  2248. return 0;
  2249. }
  2250. static int __initdata initialized = 0;
  2251. static int __init matroxfb_init(void)
  2252. {
  2253. char *option = NULL;
  2254. int err = 0;
  2255. DBG(__func__)
  2256. if (fb_get_options("matroxfb", &option))
  2257. return -ENODEV;
  2258. matroxfb_setup(option);
  2259. if (disabled)
  2260. return -ENXIO;
  2261. if (!initialized) {
  2262. initialized = 1;
  2263. err = matrox_init();
  2264. }
  2265. hotplug = 1;
  2266. /* never return failure, user can hotplug matrox later... */
  2267. return err;
  2268. }
  2269. #else
  2270. /* *************************** init module code **************************** */
  2271. MODULE_AUTHOR("(c) 1998-2002 Petr Vandrovec <vandrove@vc.cvut.cz>");
  2272. MODULE_DESCRIPTION("Accelerated FBDev driver for Matrox Millennium/Mystique/G100/G200/G400/G450/G550");
  2273. MODULE_LICENSE("GPL");
  2274. module_param(mem, int, 0);
  2275. MODULE_PARM_DESC(mem, "Size of available memory in MB, KB or B (2,4,8,12,16MB, default=autodetect)");
  2276. module_param(disabled, int, 0);
  2277. MODULE_PARM_DESC(disabled, "Disabled (0 or 1=disabled) (default=0)");
  2278. module_param(noaccel, int, 0);
  2279. MODULE_PARM_DESC(noaccel, "Do not use accelerating engine (0 or 1=disabled) (default=0)");
  2280. module_param(nopan, int, 0);
  2281. MODULE_PARM_DESC(nopan, "Disable pan on startup (0 or 1=disabled) (default=0)");
  2282. module_param(no_pci_retry, int, 0);
  2283. MODULE_PARM_DESC(no_pci_retry, "PCI retries enabled (0 or 1=disabled) (default=0)");
  2284. module_param(novga, int, 0);
  2285. MODULE_PARM_DESC(novga, "VGA I/O (0x3C0-0x3DF) disabled (0 or 1=disabled) (default=0)");
  2286. module_param(nobios, int, 0);
  2287. MODULE_PARM_DESC(nobios, "Disables ROM BIOS (0 or 1=disabled) (default=do not change BIOS state)");
  2288. module_param(noinit, int, 0);
  2289. MODULE_PARM_DESC(noinit, "Disables W/SG/SD-RAM and bus interface initialization (0 or 1=do not initialize) (default=0)");
  2290. module_param(memtype, int, 0);
  2291. MODULE_PARM_DESC(memtype, "Memory type for G200/G400 (see Documentation/fb/matroxfb.rst for explanation) (default=3 for G200, 0 for G400)");
  2292. module_param(mtrr, int, 0);
  2293. MODULE_PARM_DESC(mtrr, "This speeds up video memory accesses (0=disabled or 1) (default=1)");
  2294. module_param(sgram, int, 0);
  2295. MODULE_PARM_DESC(sgram, "Indicates that G100/G200/G400 has SGRAM memory (0=SDRAM, 1=SGRAM) (default=0)");
  2296. module_param(inv24, int, 0);
  2297. MODULE_PARM_DESC(inv24, "Inverts clock polarity for 24bpp and loop frequency > 100MHz (default=do not invert polarity)");
  2298. module_param(inverse, int, 0);
  2299. MODULE_PARM_DESC(inverse, "Inverse (0 or 1) (default=0)");
  2300. module_param(dev, int, 0);
  2301. MODULE_PARM_DESC(dev, "Multihead support, attach to device ID (0..N) (default=all working)");
  2302. module_param(vesa, int, 0);
  2303. MODULE_PARM_DESC(vesa, "Startup videomode (0x000-0x1FF) (default=0x101)");
  2304. module_param(xres, int, 0);
  2305. MODULE_PARM_DESC(xres, "Horizontal resolution (px), overrides xres from vesa (default=vesa)");
  2306. module_param(yres, int, 0);
  2307. MODULE_PARM_DESC(yres, "Vertical resolution (scans), overrides yres from vesa (default=vesa)");
  2308. module_param(upper, int, 0);
  2309. MODULE_PARM_DESC(upper, "Upper blank space (scans), overrides upper from vesa (default=vesa)");
  2310. module_param(lower, int, 0);
  2311. MODULE_PARM_DESC(lower, "Lower blank space (scans), overrides lower from vesa (default=vesa)");
  2312. module_param(vslen, int, 0);
  2313. MODULE_PARM_DESC(vslen, "Vertical sync length (scans), overrides lower from vesa (default=vesa)");
  2314. module_param(left, int, 0);
  2315. MODULE_PARM_DESC(left, "Left blank space (px), overrides left from vesa (default=vesa)");
  2316. module_param(right, int, 0);
  2317. MODULE_PARM_DESC(right, "Right blank space (px), overrides right from vesa (default=vesa)");
  2318. module_param(hslen, int, 0);
  2319. MODULE_PARM_DESC(hslen, "Horizontal sync length (px), overrides hslen from vesa (default=vesa)");
  2320. module_param(pixclock, int, 0);
  2321. MODULE_PARM_DESC(pixclock, "Pixelclock (ns), overrides pixclock from vesa (default=vesa)");
  2322. module_param(sync, int, 0);
  2323. MODULE_PARM_DESC(sync, "Sync polarity, overrides sync from vesa (default=vesa)");
  2324. module_param(depth, int, 0);
  2325. MODULE_PARM_DESC(depth, "Color depth (0=text,8,15,16,24,32) (default=vesa)");
  2326. module_param(maxclk, int, 0);
  2327. MODULE_PARM_DESC(maxclk, "Startup maximal clock, 0-999MHz, 1000-999999kHz, 1000000-INF Hz");
  2328. module_param(fh, int, 0);
  2329. MODULE_PARM_DESC(fh, "Startup horizontal frequency, 0-999kHz, 1000-INF Hz");
  2330. module_param(fv, int, 0);
  2331. MODULE_PARM_DESC(fv, "Startup vertical frequency, 0-INF Hz\n"
  2332. "You should specify \"fv:max_monitor_vsync,fh:max_monitor_hsync,maxclk:max_monitor_dotclock\"");
  2333. module_param(grayscale, int, 0);
  2334. MODULE_PARM_DESC(grayscale, "Sets display into grayscale. Works perfectly with paletized videomode (4, 8bpp), some limitations apply to 16, 24 and 32bpp videomodes (default=nograyscale)");
  2335. module_param(cross4MB, int, 0);
  2336. MODULE_PARM_DESC(cross4MB, "Specifies that 4MB boundary can be in middle of line. (default=autodetected)");
  2337. module_param(dfp, int, 0);
  2338. MODULE_PARM_DESC(dfp, "Specifies whether to use digital flat panel interface of G200/G400 (0 or 1) (default=0)");
  2339. module_param(dfp_type, int, 0);
  2340. MODULE_PARM_DESC(dfp_type, "Specifies DFP interface type (0 to 255) (default=read from hardware)");
  2341. module_param_string(outputs, outputs, sizeof(outputs), 0);
  2342. MODULE_PARM_DESC(outputs, "Specifies which CRTC is mapped to which output (string of up to three letters, consisting of 0 (disabled), 1 (CRTC1), 2 (CRTC2)) (default=111 for Gx50, 101 for G200/G400 with DFP, and 100 for all other devices)");
  2343. #ifdef CONFIG_PPC_PMAC
  2344. module_param_named(vmode, default_vmode, int, 0);
  2345. MODULE_PARM_DESC(vmode, "Specify the vmode mode number that should be used (640x480 default)");
  2346. module_param_named(cmode, default_cmode, int, 0);
  2347. MODULE_PARM_DESC(cmode, "Specify the video depth that should be used (8bit default)");
  2348. #endif
  2349. static int __init matroxfb_init(void){
  2350. DBG(__func__)
  2351. if (disabled)
  2352. return -ENXIO;
  2353. if (depth == 0)
  2354. depth = RSText;
  2355. else if (depth == 4)
  2356. depth = RS4bpp;
  2357. else if (depth == 8)
  2358. depth = RS8bpp;
  2359. else if (depth == 15)
  2360. depth = RS15bpp;
  2361. else if (depth == 16)
  2362. depth = RS16bpp;
  2363. else if (depth == 24)
  2364. depth = RS24bpp;
  2365. else if (depth == 32)
  2366. depth = RS32bpp;
  2367. else if (depth != -1) {
  2368. printk(KERN_ERR "matroxfb: depth %d is not supported, using default\n", depth);
  2369. depth = -1;
  2370. }
  2371. matrox_init();
  2372. /* never return failure; user can hotplug matrox later... */
  2373. return 0;
  2374. }
  2375. #endif /* MODULE */
  2376. module_init(matroxfb_init);
  2377. module_exit(matrox_done);
  2378. EXPORT_SYMBOL(matroxfb_register_driver);
  2379. EXPORT_SYMBOL(matroxfb_unregister_driver);
  2380. EXPORT_SYMBOL(matroxfb_wait_for_sync);
  2381. EXPORT_SYMBOL(matroxfb_enable_irq);