matroxfb_base.c 76 KB

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