matroxfb_base.c 75 KB

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