PageRenderTime 60ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/drivers/video/matrox/matroxfb_base.c

https://github.com/mstsirkin/linux
C | 1770 lines | 1435 code | 166 blank | 169 comment | 257 complexity | 6460579b07d248432be4563edb335744 MD5 | raw file
  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 mo