matroxfb_base.c 75 KB

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