matroxfb_misc.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  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. * "David C. Hansen" <haveblue@us.ibm.com>
  69. * Fixes
  70. *
  71. * (following author is not in any relation with this code, but his code
  72. * is included in this driver)
  73. *
  74. * Based on framebuffer driver for VBE 2.0 compliant graphic boards
  75. * (c) 1998 Gerd Knorr <kraxel@cs.tu-berlin.de>
  76. *
  77. * (following author is not in any relation with this code, but his ideas
  78. * were used when writting this driver)
  79. *
  80. * FreeVBE/AF (Matrox), "Shawn Hargreaves" <shawn@talula.demon.co.uk>
  81. *
  82. */
  83. /* make checkconfig does not check includes for this... */
  84. #include <linux/config.h>
  85. #include "matroxfb_misc.h"
  86. #include <linux/interrupt.h>
  87. #include <linux/matroxfb.h>
  88. void matroxfb_DAC_out(CPMINFO int reg, int val) {
  89. DBG_REG(__FUNCTION__)
  90. mga_outb(M_RAMDAC_BASE+M_X_INDEX, reg);
  91. mga_outb(M_RAMDAC_BASE+M_X_DATAREG, val);
  92. }
  93. int matroxfb_DAC_in(CPMINFO int reg) {
  94. DBG_REG(__FUNCTION__)
  95. mga_outb(M_RAMDAC_BASE+M_X_INDEX, reg);
  96. return mga_inb(M_RAMDAC_BASE+M_X_DATAREG);
  97. }
  98. void matroxfb_var2my(struct fb_var_screeninfo* var, struct my_timming* mt) {
  99. unsigned int pixclock = var->pixclock;
  100. DBG(__FUNCTION__)
  101. if (!pixclock) pixclock = 10000; /* 10ns = 100MHz */
  102. mt->pixclock = 1000000000 / pixclock;
  103. if (mt->pixclock < 1) mt->pixclock = 1;
  104. mt->mnp = -1;
  105. mt->dblscan = var->vmode & FB_VMODE_DOUBLE;
  106. mt->interlaced = var->vmode & FB_VMODE_INTERLACED;
  107. mt->HDisplay = var->xres;
  108. mt->HSyncStart = mt->HDisplay + var->right_margin;
  109. mt->HSyncEnd = mt->HSyncStart + var->hsync_len;
  110. mt->HTotal = mt->HSyncEnd + var->left_margin;
  111. mt->VDisplay = var->yres;
  112. mt->VSyncStart = mt->VDisplay + var->lower_margin;
  113. mt->VSyncEnd = mt->VSyncStart + var->vsync_len;
  114. mt->VTotal = mt->VSyncEnd + var->upper_margin;
  115. mt->sync = var->sync;
  116. }
  117. int matroxfb_PLL_calcclock(const struct matrox_pll_features* pll, unsigned int freq, unsigned int fmax,
  118. unsigned int* in, unsigned int* feed, unsigned int* post) {
  119. unsigned int bestdiff = ~0;
  120. unsigned int bestvco = 0;
  121. unsigned int fxtal = pll->ref_freq;
  122. unsigned int fwant;
  123. unsigned int p;
  124. DBG(__FUNCTION__)
  125. fwant = freq;
  126. #ifdef DEBUG
  127. printk(KERN_ERR "post_shift_max: %d\n", pll->post_shift_max);
  128. printk(KERN_ERR "ref_freq: %d\n", pll->ref_freq);
  129. printk(KERN_ERR "freq: %d\n", freq);
  130. printk(KERN_ERR "vco_freq_min: %d\n", pll->vco_freq_min);
  131. printk(KERN_ERR "in_div_min: %d\n", pll->in_div_min);
  132. printk(KERN_ERR "in_div_max: %d\n", pll->in_div_max);
  133. printk(KERN_ERR "feed_div_min: %d\n", pll->feed_div_min);
  134. printk(KERN_ERR "feed_div_max: %d\n", pll->feed_div_max);
  135. printk(KERN_ERR "fmax: %d\n", fmax);
  136. #endif
  137. for (p = 1; p <= pll->post_shift_max; p++) {
  138. if (fwant * 2 > fmax)
  139. break;
  140. fwant *= 2;
  141. }
  142. if (fwant < pll->vco_freq_min) fwant = pll->vco_freq_min;
  143. if (fwant > fmax) fwant = fmax;
  144. for (; p-- > 0; fwant >>= 1, bestdiff >>= 1) {
  145. unsigned int m;
  146. if (fwant < pll->vco_freq_min) break;
  147. for (m = pll->in_div_min; m <= pll->in_div_max; m++) {
  148. unsigned int diff, fvco;
  149. unsigned int n;
  150. n = (fwant * (m + 1) + (fxtal >> 1)) / fxtal - 1;
  151. if (n > pll->feed_div_max)
  152. break;
  153. if (n < pll->feed_div_min)
  154. n = pll->feed_div_min;
  155. fvco = (fxtal * (n + 1)) / (m + 1);
  156. if (fvco < fwant)
  157. diff = fwant - fvco;
  158. else
  159. diff = fvco - fwant;
  160. if (diff < bestdiff) {
  161. bestdiff = diff;
  162. *post = p;
  163. *in = m;
  164. *feed = n;
  165. bestvco = fvco;
  166. }
  167. }
  168. }
  169. dprintk(KERN_ERR "clk: %02X %02X %02X %d %d %d\n", *in, *feed, *post, fxtal, bestvco, fwant);
  170. return bestvco;
  171. }
  172. int matroxfb_vgaHWinit(WPMINFO struct my_timming* m) {
  173. unsigned int hd, hs, he, hbe, ht;
  174. unsigned int vd, vs, ve, vt, lc;
  175. unsigned int wd;
  176. unsigned int divider;
  177. int i;
  178. int fwidth;
  179. struct matrox_hw_state * const hw = &ACCESS_FBINFO(hw);
  180. fwidth = 8;
  181. DBG(__FUNCTION__)
  182. hw->SEQ[0] = 0x00;
  183. hw->SEQ[1] = 0x01; /* or 0x09 */
  184. hw->SEQ[2] = 0x0F; /* bitplanes */
  185. hw->SEQ[3] = 0x00;
  186. hw->SEQ[4] = 0x0E;
  187. /* CRTC 0..7, 9, 16..19, 21, 22 are reprogrammed by Matrox Millennium code... Hope that by MGA1064 too */
  188. if (m->dblscan) {
  189. m->VTotal <<= 1;
  190. m->VDisplay <<= 1;
  191. m->VSyncStart <<= 1;
  192. m->VSyncEnd <<= 1;
  193. }
  194. if (m->interlaced) {
  195. m->VTotal >>= 1;
  196. m->VDisplay >>= 1;
  197. m->VSyncStart >>= 1;
  198. m->VSyncEnd >>= 1;
  199. }
  200. /* GCTL is ignored when not using 0xA0000 aperture */
  201. hw->GCTL[0] = 0x00;
  202. hw->GCTL[1] = 0x00;
  203. hw->GCTL[2] = 0x00;
  204. hw->GCTL[3] = 0x00;
  205. hw->GCTL[4] = 0x00;
  206. hw->GCTL[5] = 0x40;
  207. hw->GCTL[6] = 0x05;
  208. hw->GCTL[7] = 0x0F;
  209. hw->GCTL[8] = 0xFF;
  210. /* Whole ATTR is ignored in PowerGraphics mode */
  211. for (i = 0; i < 16; i++)
  212. hw->ATTR[i] = i;
  213. hw->ATTR[16] = 0x41;
  214. hw->ATTR[17] = 0xFF;
  215. hw->ATTR[18] = 0x0F;
  216. if (fwidth == 9)
  217. hw->ATTR[19] = 0x08;
  218. else
  219. hw->ATTR[19] = 0x00;
  220. hw->ATTR[20] = 0x00;
  221. hd = m->HDisplay >> 3;
  222. hs = m->HSyncStart >> 3;
  223. he = m->HSyncEnd >> 3;
  224. ht = m->HTotal >> 3;
  225. /* standard timmings are in 8pixels, but for interleaved we cannot */
  226. /* do it for 4bpp (because of (4bpp >> 1(interleaved))/4 == 0) */
  227. /* using 16 or more pixels per unit can save us */
  228. divider = ACCESS_FBINFO(curr.final_bppShift);
  229. while (divider & 3) {
  230. hd >>= 1;
  231. hs >>= 1;
  232. he >>= 1;
  233. ht >>= 1;
  234. divider <<= 1;
  235. }
  236. divider = divider / 4;
  237. /* divider can be from 1 to 8 */
  238. while (divider > 8) {
  239. hd <<= 1;
  240. hs <<= 1;
  241. he <<= 1;
  242. ht <<= 1;
  243. divider >>= 1;
  244. }
  245. hd = hd - 1;
  246. hs = hs - 1;
  247. he = he - 1;
  248. ht = ht - 1;
  249. vd = m->VDisplay - 1;
  250. vs = m->VSyncStart - 1;
  251. ve = m->VSyncEnd - 1;
  252. vt = m->VTotal - 2;
  253. lc = vd;
  254. /* G200 cannot work with (ht & 7) == 6 */
  255. if (((ht & 0x07) == 0x06) || ((ht & 0x0F) == 0x04))
  256. ht++;
  257. hbe = ht;
  258. wd = ACCESS_FBINFO(fbcon).var.xres_virtual * ACCESS_FBINFO(curr.final_bppShift) / 64;
  259. hw->CRTCEXT[0] = 0;
  260. hw->CRTCEXT[5] = 0;
  261. if (m->interlaced) {
  262. hw->CRTCEXT[0] = 0x80;
  263. hw->CRTCEXT[5] = (hs + he - ht) >> 1;
  264. if (!m->dblscan)
  265. wd <<= 1;
  266. vt &= ~1;
  267. }
  268. hw->CRTCEXT[0] |= (wd & 0x300) >> 4;
  269. hw->CRTCEXT[1] = (((ht - 4) & 0x100) >> 8) |
  270. ((hd & 0x100) >> 7) | /* blanking */
  271. ((hs & 0x100) >> 6) | /* sync start */
  272. (hbe & 0x040); /* end hor. blanking */
  273. /* FIXME: Enable vidrst only on G400, and only if TV-out is used */
  274. if (ACCESS_FBINFO(outputs[1]).src == MATROXFB_SRC_CRTC1)
  275. hw->CRTCEXT[1] |= 0x88; /* enable horizontal and vertical vidrst */
  276. hw->CRTCEXT[2] = ((vt & 0xC00) >> 10) |
  277. ((vd & 0x400) >> 8) | /* disp end */
  278. ((vd & 0xC00) >> 7) | /* vblanking start */
  279. ((vs & 0xC00) >> 5) |
  280. ((lc & 0x400) >> 3);
  281. hw->CRTCEXT[3] = (divider - 1) | 0x80;
  282. hw->CRTCEXT[4] = 0;
  283. hw->CRTC[0] = ht-4;
  284. hw->CRTC[1] = hd;
  285. hw->CRTC[2] = hd;
  286. hw->CRTC[3] = (hbe & 0x1F) | 0x80;
  287. hw->CRTC[4] = hs;
  288. hw->CRTC[5] = ((hbe & 0x20) << 2) | (he & 0x1F);
  289. hw->CRTC[6] = vt & 0xFF;
  290. hw->CRTC[7] = ((vt & 0x100) >> 8) |
  291. ((vd & 0x100) >> 7) |
  292. ((vs & 0x100) >> 6) |
  293. ((vd & 0x100) >> 5) |
  294. ((lc & 0x100) >> 4) |
  295. ((vt & 0x200) >> 4) |
  296. ((vd & 0x200) >> 3) |
  297. ((vs & 0x200) >> 2);
  298. hw->CRTC[8] = 0x00;
  299. hw->CRTC[9] = ((vd & 0x200) >> 4) |
  300. ((lc & 0x200) >> 3);
  301. if (m->dblscan && !m->interlaced)
  302. hw->CRTC[9] |= 0x80;
  303. for (i = 10; i < 16; i++)
  304. hw->CRTC[i] = 0x00;
  305. hw->CRTC[16] = vs /* & 0xFF */;
  306. hw->CRTC[17] = (ve & 0x0F) | 0x20;
  307. hw->CRTC[18] = vd /* & 0xFF */;
  308. hw->CRTC[19] = wd /* & 0xFF */;
  309. hw->CRTC[20] = 0x00;
  310. hw->CRTC[21] = vd /* & 0xFF */;
  311. hw->CRTC[22] = (vt + 1) /* & 0xFF */;
  312. hw->CRTC[23] = 0xC3;
  313. hw->CRTC[24] = lc;
  314. return 0;
  315. };
  316. void matroxfb_vgaHWrestore(WPMINFO2) {
  317. int i;
  318. struct matrox_hw_state * const hw = &ACCESS_FBINFO(hw);
  319. CRITFLAGS
  320. DBG(__FUNCTION__)
  321. dprintk(KERN_INFO "MiscOutReg: %02X\n", hw->MiscOutReg);
  322. dprintk(KERN_INFO "SEQ regs: ");
  323. for (i = 0; i < 5; i++)
  324. dprintk("%02X:", hw->SEQ[i]);
  325. dprintk("\n");
  326. dprintk(KERN_INFO "GDC regs: ");
  327. for (i = 0; i < 9; i++)
  328. dprintk("%02X:", hw->GCTL[i]);
  329. dprintk("\n");
  330. dprintk(KERN_INFO "CRTC regs: ");
  331. for (i = 0; i < 25; i++)
  332. dprintk("%02X:", hw->CRTC[i]);
  333. dprintk("\n");
  334. dprintk(KERN_INFO "ATTR regs: ");
  335. for (i = 0; i < 21; i++)
  336. dprintk("%02X:", hw->ATTR[i]);
  337. dprintk("\n");
  338. CRITBEGIN
  339. mga_inb(M_ATTR_RESET);
  340. mga_outb(M_ATTR_INDEX, 0);
  341. mga_outb(M_MISC_REG, hw->MiscOutReg);
  342. for (i = 1; i < 5; i++)
  343. mga_setr(M_SEQ_INDEX, i, hw->SEQ[i]);
  344. mga_setr(M_CRTC_INDEX, 17, hw->CRTC[17] & 0x7F);
  345. for (i = 0; i < 25; i++)
  346. mga_setr(M_CRTC_INDEX, i, hw->CRTC[i]);
  347. for (i = 0; i < 9; i++)
  348. mga_setr(M_GRAPHICS_INDEX, i, hw->GCTL[i]);
  349. for (i = 0; i < 21; i++) {
  350. mga_inb(M_ATTR_RESET);
  351. mga_outb(M_ATTR_INDEX, i);
  352. mga_outb(M_ATTR_INDEX, hw->ATTR[i]);
  353. }
  354. mga_outb(M_PALETTE_MASK, 0xFF);
  355. mga_outb(M_DAC_REG, 0x00);
  356. for (i = 0; i < 768; i++)
  357. mga_outb(M_DAC_VAL, hw->DACpal[i]);
  358. mga_inb(M_ATTR_RESET);
  359. mga_outb(M_ATTR_INDEX, 0x20);
  360. CRITEND
  361. }
  362. static void get_pins(unsigned char __iomem* pins, struct matrox_bios* bd) {
  363. unsigned int b0 = readb(pins);
  364. if (b0 == 0x2E && readb(pins+1) == 0x41) {
  365. unsigned int pins_len = readb(pins+2);
  366. unsigned int i;
  367. unsigned char cksum;
  368. unsigned char* dst = bd->pins;
  369. if (pins_len < 3 || pins_len > 128) {
  370. return;
  371. }
  372. *dst++ = 0x2E;
  373. *dst++ = 0x41;
  374. *dst++ = pins_len;
  375. cksum = 0x2E + 0x41 + pins_len;
  376. for (i = 3; i < pins_len; i++) {
  377. cksum += *dst++ = readb(pins+i);
  378. }
  379. if (cksum) {
  380. return;
  381. }
  382. bd->pins_len = pins_len;
  383. } else if (b0 == 0x40 && readb(pins+1) == 0x00) {
  384. unsigned int i;
  385. unsigned char* dst = bd->pins;
  386. *dst++ = 0x40;
  387. *dst++ = 0;
  388. for (i = 2; i < 0x40; i++) {
  389. *dst++ = readb(pins+i);
  390. }
  391. bd->pins_len = 0x40;
  392. }
  393. }
  394. static void get_bios_version(unsigned char __iomem * vbios, struct matrox_bios* bd) {
  395. unsigned int pcir_offset;
  396. pcir_offset = readb(vbios + 24) | (readb(vbios + 25) << 8);
  397. if (pcir_offset >= 26 && pcir_offset < 0xFFE0 &&
  398. readb(vbios + pcir_offset ) == 'P' &&
  399. readb(vbios + pcir_offset + 1) == 'C' &&
  400. readb(vbios + pcir_offset + 2) == 'I' &&
  401. readb(vbios + pcir_offset + 3) == 'R') {
  402. unsigned char h;
  403. h = readb(vbios + pcir_offset + 0x12);
  404. bd->version.vMaj = (h >> 4) & 0xF;
  405. bd->version.vMin = h & 0xF;
  406. bd->version.vRev = readb(vbios + pcir_offset + 0x13);
  407. } else {
  408. unsigned char h;
  409. h = readb(vbios + 5);
  410. bd->version.vMaj = (h >> 4) & 0xF;
  411. bd->version.vMin = h & 0xF;
  412. bd->version.vRev = 0;
  413. }
  414. }
  415. static void get_bios_output(unsigned char __iomem* vbios, struct matrox_bios* bd) {
  416. unsigned char b;
  417. b = readb(vbios + 0x7FF1);
  418. if (b == 0xFF) {
  419. b = 0;
  420. }
  421. bd->output.state = b;
  422. }
  423. static void get_bios_tvout(unsigned char __iomem* vbios, struct matrox_bios* bd) {
  424. unsigned int i;
  425. /* Check for 'IBM .*(V....TVO' string - it means TVO BIOS */
  426. bd->output.tvout = 0;
  427. if (readb(vbios + 0x1D) != 'I' ||
  428. readb(vbios + 0x1E) != 'B' ||
  429. readb(vbios + 0x1F) != 'M' ||
  430. readb(vbios + 0x20) != ' ') {
  431. return;
  432. }
  433. for (i = 0x2D; i < 0x2D + 128; i++) {
  434. unsigned char b = readb(vbios + i);
  435. if (b == '(' && readb(vbios + i + 1) == 'V') {
  436. if (readb(vbios + i + 6) == 'T' &&
  437. readb(vbios + i + 7) == 'V' &&
  438. readb(vbios + i + 8) == 'O') {
  439. bd->output.tvout = 1;
  440. }
  441. return;
  442. }
  443. if (b == 0)
  444. break;
  445. }
  446. }
  447. static void parse_bios(unsigned char __iomem* vbios, struct matrox_bios* bd) {
  448. unsigned int pins_offset;
  449. if (readb(vbios) != 0x55 || readb(vbios + 1) != 0xAA) {
  450. return;
  451. }
  452. bd->bios_valid = 1;
  453. get_bios_version(vbios, bd);
  454. get_bios_output(vbios, bd);
  455. get_bios_tvout(vbios, bd);
  456. pins_offset = readb(vbios + 0x7FFC) | (readb(vbios + 0x7FFD) << 8);
  457. if (pins_offset <= 0xFF80) {
  458. get_pins(vbios + pins_offset, bd);
  459. }
  460. }
  461. #define get_u16(x) (le16_to_cpu(get_unaligned((__u16*)(x))))
  462. #define get_u32(x) (le32_to_cpu(get_unaligned((__u32*)(x))))
  463. static int parse_pins1(WPMINFO const struct matrox_bios* bd) {
  464. unsigned int maxdac;
  465. switch (bd->pins[22]) {
  466. case 0: maxdac = 175000; break;
  467. case 1: maxdac = 220000; break;
  468. default: maxdac = 240000; break;
  469. }
  470. if (get_u16(bd->pins + 24)) {
  471. maxdac = get_u16(bd->pins + 24) * 10;
  472. }
  473. MINFO->limits.pixel.vcomax = maxdac;
  474. MINFO->values.pll.system = get_u16(bd->pins + 28) ? get_u16(bd->pins + 28) * 10 : 50000;
  475. /* ignore 4MB, 8MB, module clocks */
  476. MINFO->features.pll.ref_freq = 14318;
  477. MINFO->values.reg.mctlwtst = 0x00030101;
  478. return 0;
  479. }
  480. static void default_pins1(WPMINFO2) {
  481. /* Millennium */
  482. MINFO->limits.pixel.vcomax = 220000;
  483. MINFO->values.pll.system = 50000;
  484. MINFO->features.pll.ref_freq = 14318;
  485. MINFO->values.reg.mctlwtst = 0x00030101;
  486. }
  487. static int parse_pins2(WPMINFO const struct matrox_bios* bd) {
  488. MINFO->limits.pixel.vcomax =
  489. MINFO->limits.system.vcomax = (bd->pins[41] == 0xFF) ? 230000 : ((bd->pins[41] + 100) * 1000);
  490. MINFO->values.reg.mctlwtst = ((bd->pins[51] & 0x01) ? 0x00000001 : 0) |
  491. ((bd->pins[51] & 0x02) ? 0x00000100 : 0) |
  492. ((bd->pins[51] & 0x04) ? 0x00010000 : 0) |
  493. ((bd->pins[51] & 0x08) ? 0x00020000 : 0);
  494. MINFO->values.pll.system = (bd->pins[43] == 0xFF) ? 50000 : ((bd->pins[43] + 100) * 1000);
  495. MINFO->features.pll.ref_freq = 14318;
  496. return 0;
  497. }
  498. static void default_pins2(WPMINFO2) {
  499. /* Millennium II, Mystique */
  500. MINFO->limits.pixel.vcomax =
  501. MINFO->limits.system.vcomax = 230000;
  502. MINFO->values.reg.mctlwtst = 0x00030101;
  503. MINFO->values.pll.system = 50000;
  504. MINFO->features.pll.ref_freq = 14318;
  505. }
  506. static int parse_pins3(WPMINFO const struct matrox_bios* bd) {
  507. MINFO->limits.pixel.vcomax =
  508. MINFO->limits.system.vcomax = (bd->pins[36] == 0xFF) ? 230000 : ((bd->pins[36] + 100) * 1000);
  509. MINFO->values.reg.mctlwtst = get_u32(bd->pins + 48) == 0xFFFFFFFF ? 0x01250A21 : get_u32(bd->pins + 48);
  510. /* memory config */
  511. MINFO->values.reg.memrdbk = ((bd->pins[57] << 21) & 0x1E000000) |
  512. ((bd->pins[57] << 22) & 0x00C00000) |
  513. ((bd->pins[56] << 1) & 0x000001E0) |
  514. ( bd->pins[56] & 0x0000000F);
  515. MINFO->values.reg.opt = (bd->pins[54] & 7) << 10;
  516. MINFO->values.reg.opt2 = bd->pins[58] << 12;
  517. MINFO->features.pll.ref_freq = (bd->pins[52] & 0x20) ? 14318 : 27000;
  518. return 0;
  519. }
  520. static void default_pins3(WPMINFO2) {
  521. /* G100, G200 */
  522. MINFO->limits.pixel.vcomax =
  523. MINFO->limits.system.vcomax = 230000;
  524. MINFO->values.reg.mctlwtst = 0x01250A21;
  525. MINFO->values.reg.memrdbk = 0x00000000;
  526. MINFO->values.reg.opt = 0x00000C00;
  527. MINFO->values.reg.opt2 = 0x00000000;
  528. MINFO->features.pll.ref_freq = 27000;
  529. }
  530. static int parse_pins4(WPMINFO const struct matrox_bios* bd) {
  531. MINFO->limits.pixel.vcomax = (bd->pins[ 39] == 0xFF) ? 230000 : bd->pins[ 39] * 4000;
  532. MINFO->limits.system.vcomax = (bd->pins[ 38] == 0xFF) ? MINFO->limits.pixel.vcomax : bd->pins[ 38] * 4000;
  533. MINFO->values.reg.mctlwtst = get_u32(bd->pins + 71);
  534. MINFO->values.reg.memrdbk = ((bd->pins[87] << 21) & 0x1E000000) |
  535. ((bd->pins[87] << 22) & 0x00C00000) |
  536. ((bd->pins[86] << 1) & 0x000001E0) |
  537. ( bd->pins[86] & 0x0000000F);
  538. MINFO->values.reg.opt = ((bd->pins[53] << 15) & 0x00400000) |
  539. ((bd->pins[53] << 22) & 0x10000000) |
  540. ((bd->pins[53] << 7) & 0x00001C00);
  541. MINFO->values.reg.opt3 = get_u32(bd->pins + 67);
  542. MINFO->values.pll.system = (bd->pins[ 65] == 0xFF) ? 200000 : bd->pins[ 65] * 4000;
  543. MINFO->features.pll.ref_freq = (bd->pins[ 92] & 0x01) ? 14318 : 27000;
  544. return 0;
  545. }
  546. static void default_pins4(WPMINFO2) {
  547. /* G400 */
  548. MINFO->limits.pixel.vcomax =
  549. MINFO->limits.system.vcomax = 252000;
  550. MINFO->values.reg.mctlwtst = 0x04A450A1;
  551. MINFO->values.reg.memrdbk = 0x000000E7;
  552. MINFO->values.reg.opt = 0x10000400;
  553. MINFO->values.reg.opt3 = 0x0190A419;
  554. MINFO->values.pll.system = 200000;
  555. MINFO->features.pll.ref_freq = 27000;
  556. }
  557. static int parse_pins5(WPMINFO const struct matrox_bios* bd) {
  558. unsigned int mult;
  559. mult = bd->pins[4]?8000:6000;
  560. MINFO->limits.pixel.vcomax = (bd->pins[ 38] == 0xFF) ? 600000 : bd->pins[ 38] * mult;
  561. MINFO->limits.system.vcomax = (bd->pins[ 36] == 0xFF) ? MINFO->limits.pixel.vcomax : bd->pins[ 36] * mult;
  562. MINFO->limits.video.vcomax = (bd->pins[ 37] == 0xFF) ? MINFO->limits.system.vcomax : bd->pins[ 37] * mult;
  563. MINFO->limits.pixel.vcomin = (bd->pins[123] == 0xFF) ? 256000 : bd->pins[123] * mult;
  564. MINFO->limits.system.vcomin = (bd->pins[121] == 0xFF) ? MINFO->limits.pixel.vcomin : bd->pins[121] * mult;
  565. MINFO->limits.video.vcomin = (bd->pins[122] == 0xFF) ? MINFO->limits.system.vcomin : bd->pins[122] * mult;
  566. MINFO->values.pll.system =
  567. MINFO->values.pll.video = (bd->pins[ 92] == 0xFF) ? 284000 : bd->pins[ 92] * 4000;
  568. MINFO->values.reg.opt = get_u32(bd->pins+ 48);
  569. MINFO->values.reg.opt2 = get_u32(bd->pins+ 52);
  570. MINFO->values.reg.opt3 = get_u32(bd->pins+ 94);
  571. MINFO->values.reg.mctlwtst = get_u32(bd->pins+ 98);
  572. MINFO->values.reg.memmisc = get_u32(bd->pins+102);
  573. MINFO->values.reg.memrdbk = get_u32(bd->pins+106);
  574. MINFO->features.pll.ref_freq = (bd->pins[110] & 0x01) ? 14318 : 27000;
  575. MINFO->values.memory.ddr = (bd->pins[114] & 0x60) == 0x20;
  576. MINFO->values.memory.dll = (bd->pins[115] & 0x02) != 0;
  577. MINFO->values.memory.emrswen = (bd->pins[115] & 0x01) != 0;
  578. MINFO->values.reg.maccess = MINFO->values.memory.emrswen ? 0x00004000 : 0x00000000;
  579. if (bd->pins[115] & 4) {
  580. MINFO->values.reg.mctlwtst_core = MINFO->values.reg.mctlwtst;
  581. } else {
  582. u_int32_t wtst_xlat[] = { 0, 1, 5, 6, 7, 5, 2, 3 };
  583. MINFO->values.reg.mctlwtst_core = (MINFO->values.reg.mctlwtst & ~7) |
  584. wtst_xlat[MINFO->values.reg.mctlwtst & 7];
  585. }
  586. return 0;
  587. }
  588. static void default_pins5(WPMINFO2) {
  589. /* Mine 16MB G450 with SDRAM DDR */
  590. MINFO->limits.pixel.vcomax =
  591. MINFO->limits.system.vcomax =
  592. MINFO->limits.video.vcomax = 600000;
  593. MINFO->limits.pixel.vcomin =
  594. MINFO->limits.system.vcomin =
  595. MINFO->limits.video.vcomin = 256000;
  596. MINFO->values.pll.system =
  597. MINFO->values.pll.video = 284000;
  598. MINFO->values.reg.opt = 0x404A1160;
  599. MINFO->values.reg.opt2 = 0x0000AC00;
  600. MINFO->values.reg.opt3 = 0x0090A409;
  601. MINFO->values.reg.mctlwtst_core =
  602. MINFO->values.reg.mctlwtst = 0x0C81462B;
  603. MINFO->values.reg.memmisc = 0x80000004;
  604. MINFO->values.reg.memrdbk = 0x01001103;
  605. MINFO->features.pll.ref_freq = 27000;
  606. MINFO->values.memory.ddr = 1;
  607. MINFO->values.memory.dll = 1;
  608. MINFO->values.memory.emrswen = 1;
  609. MINFO->values.reg.maccess = 0x00004000;
  610. }
  611. static int matroxfb_set_limits(WPMINFO const struct matrox_bios* bd) {
  612. unsigned int pins_version;
  613. static const unsigned int pinslen[] = { 64, 64, 64, 128, 128 };
  614. switch (ACCESS_FBINFO(chip)) {
  615. case MGA_2064: default_pins1(PMINFO2); break;
  616. case MGA_2164:
  617. case MGA_1064:
  618. case MGA_1164: default_pins2(PMINFO2); break;
  619. case MGA_G100:
  620. case MGA_G200: default_pins3(PMINFO2); break;
  621. case MGA_G400: default_pins4(PMINFO2); break;
  622. case MGA_G450:
  623. case MGA_G550: default_pins5(PMINFO2); break;
  624. }
  625. if (!bd->bios_valid) {
  626. printk(KERN_INFO "matroxfb: Your Matrox device does not have BIOS\n");
  627. return -1;
  628. }
  629. if (bd->pins_len < 64) {
  630. printk(KERN_INFO "matroxfb: BIOS on your Matrox device does not contain powerup info\n");
  631. return -1;
  632. }
  633. if (bd->pins[0] == 0x2E && bd->pins[1] == 0x41) {
  634. pins_version = bd->pins[5];
  635. if (pins_version < 2 || pins_version > 5) {
  636. printk(KERN_INFO "matroxfb: Unknown version (%u) of powerup info\n", pins_version);
  637. return -1;
  638. }
  639. } else {
  640. pins_version = 1;
  641. }
  642. if (bd->pins_len != pinslen[pins_version - 1]) {
  643. printk(KERN_INFO "matroxfb: Invalid powerup info\n");
  644. return -1;
  645. }
  646. switch (pins_version) {
  647. case 1:
  648. return parse_pins1(PMINFO bd);
  649. case 2:
  650. return parse_pins2(PMINFO bd);
  651. case 3:
  652. return parse_pins3(PMINFO bd);
  653. case 4:
  654. return parse_pins4(PMINFO bd);
  655. case 5:
  656. return parse_pins5(PMINFO bd);
  657. default:
  658. printk(KERN_DEBUG "matroxfb: Powerup info version %u is not yet supported\n", pins_version);
  659. return -1;
  660. }
  661. }
  662. void matroxfb_read_pins(WPMINFO2) {
  663. u32 opt;
  664. u32 biosbase;
  665. u32 fbbase;
  666. struct pci_dev* pdev = ACCESS_FBINFO(pcidev);
  667. memset(&ACCESS_FBINFO(bios), 0, sizeof(ACCESS_FBINFO(bios)));
  668. pci_read_config_dword(pdev, PCI_OPTION_REG, &opt);
  669. pci_write_config_dword(pdev, PCI_OPTION_REG, opt | PCI_OPTION_ENABLE_ROM);
  670. pci_read_config_dword(pdev, PCI_ROM_ADDRESS, &biosbase);
  671. pci_read_config_dword(pdev, ACCESS_FBINFO(devflags.fbResource), &fbbase);
  672. pci_write_config_dword(pdev, PCI_ROM_ADDRESS, (fbbase & PCI_ROM_ADDRESS_MASK) | PCI_ROM_ADDRESS_ENABLE);
  673. parse_bios(vaddr_va(ACCESS_FBINFO(video).vbase), &ACCESS_FBINFO(bios));
  674. pci_write_config_dword(pdev, PCI_ROM_ADDRESS, biosbase);
  675. pci_write_config_dword(pdev, PCI_OPTION_REG, opt);
  676. #ifdef CONFIG_X86
  677. if (!ACCESS_FBINFO(bios).bios_valid) {
  678. unsigned char __iomem* b;
  679. b = ioremap(0x000C0000, 65536);
  680. if (!b) {
  681. printk(KERN_INFO "matroxfb: Unable to map legacy BIOS\n");
  682. } else {
  683. unsigned int ven = readb(b+0x64+0) | (readb(b+0x64+1) << 8);
  684. unsigned int dev = readb(b+0x64+2) | (readb(b+0x64+3) << 8);
  685. if (ven != pdev->vendor || dev != pdev->device) {
  686. printk(KERN_INFO "matroxfb: Legacy BIOS is for %04X:%04X, while this device is %04X:%04X\n",
  687. ven, dev, pdev->vendor, pdev->device);
  688. } else {
  689. parse_bios(b, &ACCESS_FBINFO(bios));
  690. }
  691. iounmap(b);
  692. }
  693. }
  694. #endif
  695. matroxfb_set_limits(PMINFO &ACCESS_FBINFO(bios));
  696. }
  697. EXPORT_SYMBOL(matroxfb_DAC_in);
  698. EXPORT_SYMBOL(matroxfb_DAC_out);
  699. EXPORT_SYMBOL(matroxfb_var2my);
  700. EXPORT_SYMBOL(matroxfb_PLL_calcclock);
  701. #ifndef CONFIG_FB_MATROX_MULTIHEAD
  702. struct matrox_fb_info matroxfb_global_mxinfo;
  703. EXPORT_SYMBOL(matroxfb_global_mxinfo);
  704. #endif
  705. EXPORT_SYMBOL(matroxfb_vgaHWinit); /* DAC1064, Ti3026 */
  706. EXPORT_SYMBOL(matroxfb_vgaHWrestore); /* DAC1064, Ti3026 */
  707. EXPORT_SYMBOL(matroxfb_read_pins);
  708. MODULE_AUTHOR("(c) 1999-2002 Petr Vandrovec <vandrove@vc.cvut.cz>");
  709. MODULE_DESCRIPTION("Miscellaneous support for Matrox video cards");
  710. MODULE_LICENSE("GPL");