matroxfb_DAC1064.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108
  1. /*
  2. *
  3. * Hardware accelerated Matrox Millennium I, II, Mystique, G100, G200, G400 and G450.
  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. * See matroxfb_base.c for contributors.
  12. *
  13. */
  14. #include "matroxfb_DAC1064.h"
  15. #include "matroxfb_misc.h"
  16. #include "matroxfb_accel.h"
  17. #include "g450_pll.h"
  18. #include <linux/matroxfb.h>
  19. #ifdef NEED_DAC1064
  20. #define outDAC1064 matroxfb_DAC_out
  21. #define inDAC1064 matroxfb_DAC_in
  22. #define DAC1064_OPT_SCLK_PCI 0x00
  23. #define DAC1064_OPT_SCLK_PLL 0x01
  24. #define DAC1064_OPT_SCLK_EXT 0x02
  25. #define DAC1064_OPT_SCLK_MASK 0x03
  26. #define DAC1064_OPT_GDIV1 0x04 /* maybe it is GDIV2 on G100 ?! */
  27. #define DAC1064_OPT_GDIV3 0x00
  28. #define DAC1064_OPT_MDIV1 0x08
  29. #define DAC1064_OPT_MDIV2 0x00
  30. #define DAC1064_OPT_RESERVED 0x10
  31. static void DAC1064_calcclock(const struct matrox_fb_info *minfo,
  32. unsigned int freq, unsigned int fmax,
  33. unsigned int *in, unsigned int *feed,
  34. unsigned int *post)
  35. {
  36. unsigned int fvco;
  37. unsigned int p;
  38. DBG(__func__)
  39. /* only for devices older than G450 */
  40. fvco = PLL_calcclock(minfo, freq, fmax, in, feed, &p);
  41. p = (1 << p) - 1;
  42. if (fvco <= 100000)
  43. ;
  44. else if (fvco <= 140000)
  45. p |= 0x08;
  46. else if (fvco <= 180000)
  47. p |= 0x10;
  48. else
  49. p |= 0x18;
  50. *post = p;
  51. }
  52. /* they must be in POS order */
  53. static const unsigned char MGA1064_DAC_regs[] = {
  54. M1064_XCURADDL, M1064_XCURADDH, M1064_XCURCTRL,
  55. M1064_XCURCOL0RED, M1064_XCURCOL0GREEN, M1064_XCURCOL0BLUE,
  56. M1064_XCURCOL1RED, M1064_XCURCOL1GREEN, M1064_XCURCOL1BLUE,
  57. M1064_XCURCOL2RED, M1064_XCURCOL2GREEN, M1064_XCURCOL2BLUE,
  58. DAC1064_XVREFCTRL, M1064_XMULCTRL, M1064_XPIXCLKCTRL, M1064_XGENCTRL,
  59. M1064_XMISCCTRL,
  60. M1064_XGENIOCTRL, M1064_XGENIODATA, M1064_XZOOMCTRL, M1064_XSENSETEST,
  61. M1064_XCRCBITSEL,
  62. M1064_XCOLKEYMASKL, M1064_XCOLKEYMASKH, M1064_XCOLKEYL, M1064_XCOLKEYH };
  63. static const unsigned char MGA1064_DAC[] = {
  64. 0x00, 0x00, M1064_XCURCTRL_DIS,
  65. 0x00, 0x00, 0x00, /* black */
  66. 0xFF, 0xFF, 0xFF, /* white */
  67. 0xFF, 0x00, 0x00, /* red */
  68. 0x00, 0,
  69. M1064_XPIXCLKCTRL_PLL_UP | M1064_XPIXCLKCTRL_EN | M1064_XPIXCLKCTRL_SRC_PLL,
  70. M1064_XGENCTRL_VS_0 | M1064_XGENCTRL_ALPHA_DIS | M1064_XGENCTRL_BLACK_0IRE | M1064_XGENCTRL_NO_SYNC_ON_GREEN,
  71. M1064_XMISCCTRL_DAC_8BIT,
  72. 0x00, 0x00, M1064_XZOOMCTRL_1, M1064_XSENSETEST_BCOMP | M1064_XSENSETEST_GCOMP | M1064_XSENSETEST_RCOMP | M1064_XSENSETEST_PDOWN,
  73. 0x00,
  74. 0x00, 0x00, 0xFF, 0xFF};
  75. static void DAC1064_setpclk(struct matrox_fb_info *minfo, unsigned long fout)
  76. {
  77. unsigned int m, n, p;
  78. DBG(__func__)
  79. DAC1064_calcclock(minfo, fout, minfo->max_pixel_clock, &m, &n, &p);
  80. minfo->hw.DACclk[0] = m;
  81. minfo->hw.DACclk[1] = n;
  82. minfo->hw.DACclk[2] = p;
  83. }
  84. static void DAC1064_setmclk(struct matrox_fb_info *minfo, int oscinfo,
  85. unsigned long fmem)
  86. {
  87. u_int32_t mx;
  88. struct matrox_hw_state *hw = &minfo->hw;
  89. DBG(__func__)
  90. if (minfo->devflags.noinit) {
  91. /* read MCLK and give up... */
  92. hw->DACclk[3] = inDAC1064(minfo, DAC1064_XSYSPLLM);
  93. hw->DACclk[4] = inDAC1064(minfo, DAC1064_XSYSPLLN);
  94. hw->DACclk[5] = inDAC1064(minfo, DAC1064_XSYSPLLP);
  95. return;
  96. }
  97. mx = hw->MXoptionReg | 0x00000004;
  98. pci_write_config_dword(minfo->pcidev, PCI_OPTION_REG, mx);
  99. mx &= ~0x000000BB;
  100. if (oscinfo & DAC1064_OPT_GDIV1)
  101. mx |= 0x00000008;
  102. if (oscinfo & DAC1064_OPT_MDIV1)
  103. mx |= 0x00000010;
  104. if (oscinfo & DAC1064_OPT_RESERVED)
  105. mx |= 0x00000080;
  106. if ((oscinfo & DAC1064_OPT_SCLK_MASK) == DAC1064_OPT_SCLK_PLL) {
  107. /* select PCI clock until we have setup oscilator... */
  108. int clk;
  109. unsigned int m, n, p;
  110. /* powerup system PLL, select PCI clock */
  111. mx |= 0x00000020;
  112. pci_write_config_dword(minfo->pcidev, PCI_OPTION_REG, mx);
  113. mx &= ~0x00000004;
  114. pci_write_config_dword(minfo->pcidev, PCI_OPTION_REG, mx);
  115. /* !!! you must not access device if MCLK is not running !!!
  116. Doing so cause immediate PCI lockup :-( Maybe they should
  117. generate ABORT or I/O (parity...) error and Linux should
  118. recover from this... (kill driver/process). But world is not
  119. perfect... */
  120. /* (bit 2 of PCI_OPTION_REG must be 0... and bits 0,1 must not
  121. select PLL... because of PLL can be stopped at this time) */
  122. DAC1064_calcclock(minfo, fmem, minfo->max_pixel_clock, &m, &n, &p);
  123. outDAC1064(minfo, DAC1064_XSYSPLLM, hw->DACclk[3] = m);
  124. outDAC1064(minfo, DAC1064_XSYSPLLN, hw->DACclk[4] = n);
  125. outDAC1064(minfo, DAC1064_XSYSPLLP, hw->DACclk[5] = p);
  126. for (clk = 65536; clk; --clk) {
  127. if (inDAC1064(minfo, DAC1064_XSYSPLLSTAT) & 0x40)
  128. break;
  129. }
  130. if (!clk)
  131. printk(KERN_ERR "matroxfb: aiee, SYSPLL not locked\n");
  132. /* select PLL */
  133. mx |= 0x00000005;
  134. } else {
  135. /* select specified system clock source */
  136. mx |= oscinfo & DAC1064_OPT_SCLK_MASK;
  137. }
  138. pci_write_config_dword(minfo->pcidev, PCI_OPTION_REG, mx);
  139. mx &= ~0x00000004;
  140. pci_write_config_dword(minfo->pcidev, PCI_OPTION_REG, mx);
  141. hw->MXoptionReg = mx;
  142. }
  143. #ifdef CONFIG_FB_MATROX_G
  144. static void g450_set_plls(struct matrox_fb_info *minfo)
  145. {
  146. u_int32_t c2_ctl;
  147. unsigned int pxc;
  148. struct matrox_hw_state *hw = &minfo->hw;
  149. int pixelmnp;
  150. int videomnp;
  151. c2_ctl = hw->crtc2.ctl & ~0x4007; /* Clear PLL + enable for CRTC2 */
  152. c2_ctl |= 0x0001; /* Enable CRTC2 */
  153. hw->DACreg[POS1064_XPWRCTRL] &= ~0x02; /* Stop VIDEO PLL */
  154. pixelmnp = minfo->crtc1.mnp;
  155. videomnp = minfo->crtc2.mnp;
  156. if (videomnp < 0) {
  157. c2_ctl &= ~0x0001; /* Disable CRTC2 */
  158. hw->DACreg[POS1064_XPWRCTRL] &= ~0x10; /* Powerdown CRTC2 */
  159. } else if (minfo->crtc2.pixclock == minfo->features.pll.ref_freq) {
  160. c2_ctl |= 0x4002; /* Use reference directly */
  161. } else if (videomnp == pixelmnp) {
  162. c2_ctl |= 0x0004; /* Use pixel PLL */
  163. } else {
  164. if (0 == ((videomnp ^ pixelmnp) & 0xFFFFFF00)) {
  165. /* PIXEL and VIDEO PLL must not use same frequency. We modify N
  166. of PIXEL PLL in such case because of VIDEO PLL may be source
  167. of TVO clocks, and chroma subcarrier is derived from its
  168. pixel clocks */
  169. pixelmnp += 0x000100;
  170. }
  171. c2_ctl |= 0x0006; /* Use video PLL */
  172. hw->DACreg[POS1064_XPWRCTRL] |= 0x02;
  173. outDAC1064(minfo, M1064_XPWRCTRL, hw->DACreg[POS1064_XPWRCTRL]);
  174. matroxfb_g450_setpll_cond(minfo, videomnp, M_VIDEO_PLL);
  175. }
  176. hw->DACreg[POS1064_XPIXCLKCTRL] &= ~M1064_XPIXCLKCTRL_PLL_UP;
  177. if (pixelmnp >= 0) {
  178. hw->DACreg[POS1064_XPIXCLKCTRL] |= M1064_XPIXCLKCTRL_PLL_UP;
  179. outDAC1064(minfo, M1064_XPIXCLKCTRL, hw->DACreg[POS1064_XPIXCLKCTRL]);
  180. matroxfb_g450_setpll_cond(minfo, pixelmnp, M_PIXEL_PLL_C);
  181. }
  182. if (c2_ctl != hw->crtc2.ctl) {
  183. hw->crtc2.ctl = c2_ctl;
  184. mga_outl(0x3C10, c2_ctl);
  185. }
  186. pxc = minfo->crtc1.pixclock;
  187. if (pxc == 0 || minfo->outputs[2].src == MATROXFB_SRC_CRTC2) {
  188. pxc = minfo->crtc2.pixclock;
  189. }
  190. if (minfo->chip == MGA_G550) {
  191. if (pxc < 45000) {
  192. hw->DACreg[POS1064_XPANMODE] = 0x00; /* 0-50 */
  193. } else if (pxc < 55000) {
  194. hw->DACreg[POS1064_XPANMODE] = 0x08; /* 34-62 */
  195. } else if (pxc < 70000) {
  196. hw->DACreg[POS1064_XPANMODE] = 0x10; /* 42-78 */
  197. } else if (pxc < 85000) {
  198. hw->DACreg[POS1064_XPANMODE] = 0x18; /* 62-92 */
  199. } else if (pxc < 100000) {
  200. hw->DACreg[POS1064_XPANMODE] = 0x20; /* 74-108 */
  201. } else if (pxc < 115000) {
  202. hw->DACreg[POS1064_XPANMODE] = 0x28; /* 94-122 */
  203. } else if (pxc < 125000) {
  204. hw->DACreg[POS1064_XPANMODE] = 0x30; /* 108-132 */
  205. } else {
  206. hw->DACreg[POS1064_XPANMODE] = 0x38; /* 120-168 */
  207. }
  208. } else {
  209. /* G450 */
  210. if (pxc < 45000) {
  211. hw->DACreg[POS1064_XPANMODE] = 0x00; /* 0-54 */
  212. } else if (pxc < 65000) {
  213. hw->DACreg[POS1064_XPANMODE] = 0x08; /* 38-70 */
  214. } else if (pxc < 85000) {
  215. hw->DACreg[POS1064_XPANMODE] = 0x10; /* 56-96 */
  216. } else if (pxc < 105000) {
  217. hw->DACreg[POS1064_XPANMODE] = 0x18; /* 80-114 */
  218. } else if (pxc < 135000) {
  219. hw->DACreg[POS1064_XPANMODE] = 0x20; /* 102-144 */
  220. } else if (pxc < 160000) {
  221. hw->DACreg[POS1064_XPANMODE] = 0x28; /* 132-166 */
  222. } else if (pxc < 175000) {
  223. hw->DACreg[POS1064_XPANMODE] = 0x30; /* 154-182 */
  224. } else {
  225. hw->DACreg[POS1064_XPANMODE] = 0x38; /* 170-204 */
  226. }
  227. }
  228. }
  229. #endif
  230. void DAC1064_global_init(struct matrox_fb_info *minfo)
  231. {
  232. struct matrox_hw_state *hw = &minfo->hw;
  233. hw->DACreg[POS1064_XMISCCTRL] &= M1064_XMISCCTRL_DAC_WIDTHMASK;
  234. hw->DACreg[POS1064_XMISCCTRL] |= M1064_XMISCCTRL_LUT_EN;
  235. hw->DACreg[POS1064_XPIXCLKCTRL] = M1064_XPIXCLKCTRL_PLL_UP | M1064_XPIXCLKCTRL_EN | M1064_XPIXCLKCTRL_SRC_PLL;
  236. #ifdef CONFIG_FB_MATROX_G
  237. if (minfo->devflags.g450dac) {
  238. hw->DACreg[POS1064_XPWRCTRL] = 0x1F; /* powerup everything */
  239. hw->DACreg[POS1064_XOUTPUTCONN] = 0x00; /* disable outputs */
  240. hw->DACreg[POS1064_XMISCCTRL] |= M1064_XMISCCTRL_DAC_EN;
  241. switch (minfo->outputs[0].src) {
  242. case MATROXFB_SRC_CRTC1:
  243. case MATROXFB_SRC_CRTC2:
  244. hw->DACreg[POS1064_XOUTPUTCONN] |= 0x01; /* enable output; CRTC1/2 selection is in CRTC2 ctl */
  245. break;
  246. case MATROXFB_SRC_NONE:
  247. hw->DACreg[POS1064_XMISCCTRL] &= ~M1064_XMISCCTRL_DAC_EN;
  248. break;
  249. }
  250. switch (minfo->outputs[1].src) {
  251. case MATROXFB_SRC_CRTC1:
  252. hw->DACreg[POS1064_XOUTPUTCONN] |= 0x04;
  253. break;
  254. case MATROXFB_SRC_CRTC2:
  255. if (minfo->outputs[1].mode == MATROXFB_OUTPUT_MODE_MONITOR) {
  256. hw->DACreg[POS1064_XOUTPUTCONN] |= 0x08;
  257. } else {
  258. hw->DACreg[POS1064_XOUTPUTCONN] |= 0x0C;
  259. }
  260. break;
  261. case MATROXFB_SRC_NONE:
  262. hw->DACreg[POS1064_XPWRCTRL] &= ~0x01; /* Poweroff DAC2 */
  263. break;
  264. }
  265. switch (minfo->outputs[2].src) {
  266. case MATROXFB_SRC_CRTC1:
  267. hw->DACreg[POS1064_XOUTPUTCONN] |= 0x20;
  268. break;
  269. case MATROXFB_SRC_CRTC2:
  270. hw->DACreg[POS1064_XOUTPUTCONN] |= 0x40;
  271. break;
  272. case MATROXFB_SRC_NONE:
  273. #if 0
  274. /* HELP! If we boot without DFP connected to DVI, we can
  275. poweroff TMDS. But if we boot with DFP connected,
  276. TMDS generated clocks are used instead of ALL pixclocks
  277. available... If someone knows which register
  278. handles it, please reveal this secret to me... */
  279. hw->DACreg[POS1064_XPWRCTRL] &= ~0x04; /* Poweroff TMDS */
  280. #endif
  281. break;
  282. }
  283. /* Now set timming related variables... */
  284. g450_set_plls(minfo);
  285. } else
  286. #endif
  287. {
  288. if (minfo->outputs[1].src == MATROXFB_SRC_CRTC1) {
  289. hw->DACreg[POS1064_XPIXCLKCTRL] = M1064_XPIXCLKCTRL_PLL_UP | M1064_XPIXCLKCTRL_EN | M1064_XPIXCLKCTRL_SRC_EXT;
  290. hw->DACreg[POS1064_XMISCCTRL] |= GX00_XMISCCTRL_MFC_MAFC | G400_XMISCCTRL_VDO_MAFC12;
  291. } else if (minfo->outputs[1].src == MATROXFB_SRC_CRTC2) {
  292. hw->DACreg[POS1064_XMISCCTRL] |= GX00_XMISCCTRL_MFC_MAFC | G400_XMISCCTRL_VDO_C2_MAFC12;
  293. } else if (minfo->outputs[2].src == MATROXFB_SRC_CRTC1)
  294. hw->DACreg[POS1064_XMISCCTRL] |= GX00_XMISCCTRL_MFC_PANELLINK | G400_XMISCCTRL_VDO_MAFC12;
  295. else
  296. hw->DACreg[POS1064_XMISCCTRL] |= GX00_XMISCCTRL_MFC_DIS;
  297. if (minfo->outputs[0].src != MATROXFB_SRC_NONE)
  298. hw->DACreg[POS1064_XMISCCTRL] |= M1064_XMISCCTRL_DAC_EN;
  299. }
  300. }
  301. void DAC1064_global_restore(struct matrox_fb_info *minfo)
  302. {
  303. struct matrox_hw_state *hw = &minfo->hw;
  304. outDAC1064(minfo, M1064_XPIXCLKCTRL, hw->DACreg[POS1064_XPIXCLKCTRL]);
  305. outDAC1064(minfo, M1064_XMISCCTRL, hw->DACreg[POS1064_XMISCCTRL]);
  306. if (minfo->devflags.accelerator == FB_ACCEL_MATROX_MGAG400) {
  307. outDAC1064(minfo, 0x20, 0x04);
  308. outDAC1064(minfo, 0x1F, minfo->devflags.dfp_type);
  309. if (minfo->devflags.g450dac) {
  310. outDAC1064(minfo, M1064_XSYNCCTRL, 0xCC);
  311. outDAC1064(minfo, M1064_XPWRCTRL, hw->DACreg[POS1064_XPWRCTRL]);
  312. outDAC1064(minfo, M1064_XPANMODE, hw->DACreg[POS1064_XPANMODE]);
  313. outDAC1064(minfo, M1064_XOUTPUTCONN, hw->DACreg[POS1064_XOUTPUTCONN]);
  314. }
  315. }
  316. }
  317. static int DAC1064_init_1(struct matrox_fb_info *minfo, struct my_timming *m)
  318. {
  319. struct matrox_hw_state *hw = &minfo->hw;
  320. DBG(__func__)
  321. memcpy(hw->DACreg, MGA1064_DAC, sizeof(MGA1064_DAC_regs));
  322. switch (minfo->fbcon.var.bits_per_pixel) {
  323. /* case 4: not supported by MGA1064 DAC */
  324. case 8:
  325. hw->DACreg[POS1064_XMULCTRL] = M1064_XMULCTRL_DEPTH_8BPP | M1064_XMULCTRL_GRAPHICS_PALETIZED;
  326. break;
  327. case 16:
  328. if (minfo->fbcon.var.green.length == 5)
  329. hw->DACreg[POS1064_XMULCTRL] = M1064_XMULCTRL_DEPTH_15BPP_1BPP | M1064_XMULCTRL_GRAPHICS_PALETIZED;
  330. else
  331. hw->DACreg[POS1064_XMULCTRL] = M1064_XMULCTRL_DEPTH_16BPP | M1064_XMULCTRL_GRAPHICS_PALETIZED;
  332. break;
  333. case 24:
  334. hw->DACreg[POS1064_XMULCTRL] = M1064_XMULCTRL_DEPTH_24BPP | M1064_XMULCTRL_GRAPHICS_PALETIZED;
  335. break;
  336. case 32:
  337. hw->DACreg[POS1064_XMULCTRL] = M1064_XMULCTRL_DEPTH_32BPP | M1064_XMULCTRL_GRAPHICS_PALETIZED;
  338. break;
  339. default:
  340. return 1; /* unsupported depth */
  341. }
  342. hw->DACreg[POS1064_XVREFCTRL] = minfo->features.DAC1064.xvrefctrl;
  343. hw->DACreg[POS1064_XGENCTRL] &= ~M1064_XGENCTRL_SYNC_ON_GREEN_MASK;
  344. hw->DACreg[POS1064_XGENCTRL] |= (m->sync & FB_SYNC_ON_GREEN)?M1064_XGENCTRL_SYNC_ON_GREEN:M1064_XGENCTRL_NO_SYNC_ON_GREEN;
  345. hw->DACreg[POS1064_XCURADDL] = 0;
  346. hw->DACreg[POS1064_XCURADDH] = 0;
  347. DAC1064_global_init(minfo);
  348. return 0;
  349. }
  350. static int DAC1064_init_2(struct matrox_fb_info *minfo, struct my_timming *m)
  351. {
  352. struct matrox_hw_state *hw = &minfo->hw;
  353. DBG(__func__)
  354. if (minfo->fbcon.var.bits_per_pixel > 16) { /* 256 entries */
  355. int i;
  356. for (i = 0; i < 256; i++) {
  357. hw->DACpal[i * 3 + 0] = i;
  358. hw->DACpal[i * 3 + 1] = i;
  359. hw->DACpal[i * 3 + 2] = i;
  360. }
  361. } else if (minfo->fbcon.var.bits_per_pixel > 8) {
  362. if (minfo->fbcon.var.green.length == 5) { /* 0..31, 128..159 */
  363. int i;
  364. for (i = 0; i < 32; i++) {
  365. /* with p15 == 0 */
  366. hw->DACpal[i * 3 + 0] = i << 3;
  367. hw->DACpal[i * 3 + 1] = i << 3;
  368. hw->DACpal[i * 3 + 2] = i << 3;
  369. /* with p15 == 1 */
  370. hw->DACpal[(i + 128) * 3 + 0] = i << 3;
  371. hw->DACpal[(i + 128) * 3 + 1] = i << 3;
  372. hw->DACpal[(i + 128) * 3 + 2] = i << 3;
  373. }
  374. } else {
  375. int i;
  376. for (i = 0; i < 64; i++) { /* 0..63 */
  377. hw->DACpal[i * 3 + 0] = i << 3;
  378. hw->DACpal[i * 3 + 1] = i << 2;
  379. hw->DACpal[i * 3 + 2] = i << 3;
  380. }
  381. }
  382. } else {
  383. memset(hw->DACpal, 0, 768);
  384. }
  385. return 0;
  386. }
  387. static void DAC1064_restore_1(struct matrox_fb_info *minfo)
  388. {
  389. struct matrox_hw_state *hw = &minfo->hw;
  390. CRITFLAGS
  391. DBG(__func__)
  392. CRITBEGIN
  393. if ((inDAC1064(minfo, DAC1064_XSYSPLLM) != hw->DACclk[3]) ||
  394. (inDAC1064(minfo, DAC1064_XSYSPLLN) != hw->DACclk[4]) ||
  395. (inDAC1064(minfo, DAC1064_XSYSPLLP) != hw->DACclk[5])) {
  396. outDAC1064(minfo, DAC1064_XSYSPLLM, hw->DACclk[3]);
  397. outDAC1064(minfo, DAC1064_XSYSPLLN, hw->DACclk[4]);
  398. outDAC1064(minfo, DAC1064_XSYSPLLP, hw->DACclk[5]);
  399. }
  400. {
  401. unsigned int i;
  402. for (i = 0; i < sizeof(MGA1064_DAC_regs); i++) {
  403. if ((i != POS1064_XPIXCLKCTRL) && (i != POS1064_XMISCCTRL))
  404. outDAC1064(minfo, MGA1064_DAC_regs[i], hw->DACreg[i]);
  405. }
  406. }
  407. DAC1064_global_restore(minfo);
  408. CRITEND
  409. };
  410. static void DAC1064_restore_2(struct matrox_fb_info *minfo)
  411. {
  412. #ifdef DEBUG
  413. unsigned int i;
  414. #endif
  415. DBG(__func__)
  416. #ifdef DEBUG
  417. dprintk(KERN_DEBUG "DAC1064regs ");
  418. for (i = 0; i < sizeof(MGA1064_DAC_regs); i++) {
  419. dprintk("R%02X=%02X ", MGA1064_DAC_regs[i], minfo->hw.DACreg[i]);
  420. if ((i & 0x7) == 0x7) dprintk(KERN_DEBUG "continuing... ");
  421. }
  422. dprintk(KERN_DEBUG "DAC1064clk ");
  423. for (i = 0; i < 6; i++)
  424. dprintk("C%02X=%02X ", i, minfo->hw.DACclk[i]);
  425. dprintk("\n");
  426. #endif
  427. }
  428. static int m1064_compute(void* out, struct my_timming* m) {
  429. #define minfo ((struct matrox_fb_info*)out)
  430. {
  431. int i;
  432. int tmout;
  433. CRITFLAGS
  434. DAC1064_setpclk(minfo, m->pixclock);
  435. CRITBEGIN
  436. for (i = 0; i < 3; i++)
  437. outDAC1064(minfo, M1064_XPIXPLLCM + i, minfo->hw.DACclk[i]);
  438. for (tmout = 500000; tmout; tmout--) {
  439. if (inDAC1064(minfo, M1064_XPIXPLLSTAT) & 0x40)
  440. break;
  441. udelay(10);
  442. }
  443. CRITEND
  444. if (!tmout)
  445. printk(KERN_ERR "matroxfb: Pixel PLL not locked after 5 secs\n");
  446. }
  447. #undef minfo
  448. return 0;
  449. }
  450. static struct matrox_altout m1064 = {
  451. .name = "Primary output",
  452. .compute = m1064_compute,
  453. };
  454. #ifdef CONFIG_FB_MATROX_G
  455. static int g450_compute(void* out, struct my_timming* m) {
  456. #define minfo ((struct matrox_fb_info*)out)
  457. if (m->mnp < 0) {
  458. m->mnp = matroxfb_g450_setclk(minfo, m->pixclock, (m->crtc == MATROXFB_SRC_CRTC1) ? M_PIXEL_PLL_C : M_VIDEO_PLL);
  459. if (m->mnp >= 0) {
  460. m->pixclock = g450_mnp2f(minfo, m->mnp);
  461. }
  462. }
  463. #undef minfo
  464. return 0;
  465. }
  466. static struct matrox_altout g450out = {
  467. .name = "Primary output",
  468. .compute = g450_compute,
  469. };
  470. #endif
  471. #endif /* NEED_DAC1064 */
  472. #ifdef CONFIG_FB_MATROX_MYSTIQUE
  473. static int MGA1064_init(struct matrox_fb_info *minfo, struct my_timming *m)
  474. {
  475. struct matrox_hw_state *hw = &minfo->hw;
  476. DBG(__func__)
  477. if (DAC1064_init_1(minfo, m)) return 1;
  478. if (matroxfb_vgaHWinit(minfo, m)) return 1;
  479. hw->MiscOutReg = 0xCB;
  480. if (m->sync & FB_SYNC_HOR_HIGH_ACT)
  481. hw->MiscOutReg &= ~0x40;
  482. if (m->sync & FB_SYNC_VERT_HIGH_ACT)
  483. hw->MiscOutReg &= ~0x80;
  484. if (m->sync & FB_SYNC_COMP_HIGH_ACT) /* should be only FB_SYNC_COMP */
  485. hw->CRTCEXT[3] |= 0x40;
  486. if (DAC1064_init_2(minfo, m)) return 1;
  487. return 0;
  488. }
  489. #endif
  490. #ifdef CONFIG_FB_MATROX_G
  491. static int MGAG100_init(struct matrox_fb_info *minfo, struct my_timming *m)
  492. {
  493. struct matrox_hw_state *hw = &minfo->hw;
  494. DBG(__func__)
  495. if (DAC1064_init_1(minfo, m)) return 1;
  496. hw->MXoptionReg &= ~0x2000;
  497. if (matroxfb_vgaHWinit(minfo, m)) return 1;
  498. hw->MiscOutReg = 0xEF;
  499. if (m->sync & FB_SYNC_HOR_HIGH_ACT)
  500. hw->MiscOutReg &= ~0x40;
  501. if (m->sync & FB_SYNC_VERT_HIGH_ACT)
  502. hw->MiscOutReg &= ~0x80;
  503. if (m->sync & FB_SYNC_COMP_HIGH_ACT) /* should be only FB_SYNC_COMP */
  504. hw->CRTCEXT[3] |= 0x40;
  505. if (DAC1064_init_2(minfo, m)) return 1;
  506. return 0;
  507. }
  508. #endif /* G */
  509. #ifdef CONFIG_FB_MATROX_MYSTIQUE
  510. static void MGA1064_ramdac_init(struct matrox_fb_info *minfo)
  511. {
  512. DBG(__func__)
  513. /* minfo->features.DAC1064.vco_freq_min = 120000; */
  514. minfo->features.pll.vco_freq_min = 62000;
  515. minfo->features.pll.ref_freq = 14318;
  516. minfo->features.pll.feed_div_min = 100;
  517. minfo->features.pll.feed_div_max = 127;
  518. minfo->features.pll.in_div_min = 1;
  519. minfo->features.pll.in_div_max = 31;
  520. minfo->features.pll.post_shift_max = 3;
  521. minfo->features.DAC1064.xvrefctrl = DAC1064_XVREFCTRL_EXTERNAL;
  522. /* maybe cmdline MCLK= ?, doc says gclk=44MHz, mclk=66MHz... it was 55/83 with old values */
  523. DAC1064_setmclk(minfo, DAC1064_OPT_MDIV2 | DAC1064_OPT_GDIV3 | DAC1064_OPT_SCLK_PLL, 133333);
  524. }
  525. #endif
  526. #ifdef CONFIG_FB_MATROX_G
  527. /* BIOS environ */
  528. static int x7AF4 = 0x10; /* flags, maybe 0x10 = SDRAM, 0x00 = SGRAM??? */
  529. /* G100 wants 0x10, G200 SGRAM does not care... */
  530. #if 0
  531. static int def50 = 0; /* reg50, & 0x0F, & 0x3000 (only 0x0000, 0x1000, 0x2000 (0x3000 disallowed and treated as 0) */
  532. #endif
  533. static void MGAG100_progPixClock(const struct matrox_fb_info *minfo, int flags,
  534. int m, int n, int p)
  535. {
  536. int reg;
  537. int selClk;
  538. int clk;
  539. DBG(__func__)
  540. outDAC1064(minfo, M1064_XPIXCLKCTRL, inDAC1064(minfo, M1064_XPIXCLKCTRL) | M1064_XPIXCLKCTRL_DIS |
  541. M1064_XPIXCLKCTRL_PLL_UP);
  542. switch (flags & 3) {
  543. case 0: reg = M1064_XPIXPLLAM; break;
  544. case 1: reg = M1064_XPIXPLLBM; break;
  545. default: reg = M1064_XPIXPLLCM; break;
  546. }
  547. outDAC1064(minfo, reg++, m);
  548. outDAC1064(minfo, reg++, n);
  549. outDAC1064(minfo, reg, p);
  550. selClk = mga_inb(M_MISC_REG_READ) & ~0xC;
  551. /* there should be flags & 0x03 & case 0/1/else */
  552. /* and we should first select source and after that we should wait for PLL */
  553. /* and we are waiting for PLL with oscilator disabled... Is it right? */
  554. switch (flags & 0x03) {
  555. case 0x00: break;
  556. case 0x01: selClk |= 4; break;
  557. default: selClk |= 0x0C; break;
  558. }
  559. mga_outb(M_MISC_REG, selClk);
  560. for (clk = 500000; clk; clk--) {
  561. if (inDAC1064(minfo, M1064_XPIXPLLSTAT) & 0x40)
  562. break;
  563. udelay(10);
  564. }
  565. if (!clk)
  566. printk(KERN_ERR "matroxfb: Pixel PLL%c not locked after usual time\n", (reg-M1064_XPIXPLLAM-2)/4 + 'A');
  567. selClk = inDAC1064(minfo, M1064_XPIXCLKCTRL) & ~M1064_XPIXCLKCTRL_SRC_MASK;
  568. switch (flags & 0x0C) {
  569. case 0x00: selClk |= M1064_XPIXCLKCTRL_SRC_PCI; break;
  570. case 0x04: selClk |= M1064_XPIXCLKCTRL_SRC_PLL; break;
  571. default: selClk |= M1064_XPIXCLKCTRL_SRC_EXT; break;
  572. }
  573. outDAC1064(minfo, M1064_XPIXCLKCTRL, selClk);
  574. outDAC1064(minfo, M1064_XPIXCLKCTRL, inDAC1064(minfo, M1064_XPIXCLKCTRL) & ~M1064_XPIXCLKCTRL_DIS);
  575. }
  576. static void MGAG100_setPixClock(const struct matrox_fb_info *minfo, int flags,
  577. int freq)
  578. {
  579. unsigned int m, n, p;
  580. DBG(__func__)
  581. DAC1064_calcclock(minfo, freq, minfo->max_pixel_clock, &m, &n, &p);
  582. MGAG100_progPixClock(minfo, flags, m, n, p);
  583. }
  584. #endif
  585. #ifdef CONFIG_FB_MATROX_MYSTIQUE
  586. static int MGA1064_preinit(struct matrox_fb_info *minfo)
  587. {
  588. static const int vxres_mystique[] = { 512, 640, 768, 800, 832, 960,
  589. 1024, 1152, 1280, 1600, 1664, 1920,
  590. 2048, 0};
  591. struct matrox_hw_state *hw = &minfo->hw;
  592. DBG(__func__)
  593. /* minfo->capable.cfb4 = 0; ... preinitialized by 0 */
  594. minfo->capable.text = 1;
  595. minfo->capable.vxres = vxres_mystique;
  596. minfo->outputs[0].output = &m1064;
  597. minfo->outputs[0].src = minfo->outputs[0].default_src;
  598. minfo->outputs[0].data = minfo;
  599. minfo->outputs[0].mode = MATROXFB_OUTPUT_MODE_MONITOR;
  600. if (minfo->devflags.noinit)
  601. return 0; /* do not modify settings */
  602. hw->MXoptionReg &= 0xC0000100;
  603. hw->MXoptionReg |= 0x00094E20;
  604. if (minfo->devflags.novga)
  605. hw->MXoptionReg &= ~0x00000100;
  606. if (minfo->devflags.nobios)
  607. hw->MXoptionReg &= ~0x40000000;
  608. if (minfo->devflags.nopciretry)
  609. hw->MXoptionReg |= 0x20000000;
  610. pci_write_config_dword(minfo->pcidev, PCI_OPTION_REG, hw->MXoptionReg);
  611. mga_setr(M_SEQ_INDEX, 0x01, 0x20);
  612. mga_outl(M_CTLWTST, 0x00000000);
  613. udelay(200);
  614. mga_outl(M_MACCESS, 0x00008000);
  615. udelay(100);
  616. mga_outl(M_MACCESS, 0x0000C000);
  617. return 0;
  618. }
  619. static void MGA1064_reset(struct matrox_fb_info *minfo)
  620. {
  621. DBG(__func__);
  622. MGA1064_ramdac_init(minfo);
  623. }
  624. #endif
  625. #ifdef CONFIG_FB_MATROX_G
  626. static void g450_mclk_init(struct matrox_fb_info *minfo)
  627. {
  628. /* switch all clocks to PCI source */
  629. pci_write_config_dword(minfo->pcidev, PCI_OPTION_REG, minfo->hw.MXoptionReg | 4);
  630. pci_write_config_dword(minfo->pcidev, PCI_OPTION3_REG, minfo->values.reg.opt3 & ~0x00300C03);
  631. pci_write_config_dword(minfo->pcidev, PCI_OPTION_REG, minfo->hw.MXoptionReg);
  632. if (((minfo->values.reg.opt3 & 0x000003) == 0x000003) ||
  633. ((minfo->values.reg.opt3 & 0x000C00) == 0x000C00) ||
  634. ((minfo->values.reg.opt3 & 0x300000) == 0x300000)) {
  635. matroxfb_g450_setclk(minfo, minfo->values.pll.video, M_VIDEO_PLL);
  636. } else {
  637. unsigned long flags;
  638. unsigned int pwr;
  639. matroxfb_DAC_lock_irqsave(flags);
  640. pwr = inDAC1064(minfo, M1064_XPWRCTRL) & ~0x02;
  641. outDAC1064(minfo, M1064_XPWRCTRL, pwr);
  642. matroxfb_DAC_unlock_irqrestore(flags);
  643. }
  644. matroxfb_g450_setclk(minfo, minfo->values.pll.system, M_SYSTEM_PLL);
  645. /* switch clocks to their real PLL source(s) */
  646. pci_write_config_dword(minfo->pcidev, PCI_OPTION_REG, minfo->hw.MXoptionReg | 4);
  647. pci_write_config_dword(minfo->pcidev, PCI_OPTION3_REG, minfo->values.reg.opt3);
  648. pci_write_config_dword(minfo->pcidev, PCI_OPTION_REG, minfo->hw.MXoptionReg);
  649. }
  650. static void g450_memory_init(struct matrox_fb_info *minfo)
  651. {
  652. /* disable memory refresh */
  653. minfo->hw.MXoptionReg &= ~0x001F8000;
  654. pci_write_config_dword(minfo->pcidev, PCI_OPTION_REG, minfo->hw.MXoptionReg);
  655. /* set memory interface parameters */
  656. minfo->hw.MXoptionReg &= ~0x00207E00;
  657. minfo->hw.MXoptionReg |= 0x00207E00 & minfo->values.reg.opt;
  658. pci_write_config_dword(minfo->pcidev, PCI_OPTION_REG, minfo->hw.MXoptionReg);
  659. pci_write_config_dword(minfo->pcidev, PCI_OPTION2_REG, minfo->values.reg.opt2);
  660. mga_outl(M_CTLWTST, minfo->values.reg.mctlwtst);
  661. /* first set up memory interface with disabled memory interface clocks */
  662. pci_write_config_dword(minfo->pcidev, PCI_MEMMISC_REG, minfo->values.reg.memmisc & ~0x80000000U);
  663. mga_outl(M_MEMRDBK, minfo->values.reg.memrdbk);
  664. mga_outl(M_MACCESS, minfo->values.reg.maccess);
  665. /* start memory clocks */
  666. pci_write_config_dword(minfo->pcidev, PCI_MEMMISC_REG, minfo->values.reg.memmisc | 0x80000000U);
  667. udelay(200);
  668. if (minfo->values.memory.ddr && (!minfo->values.memory.emrswen || !minfo->values.memory.dll)) {
  669. mga_outl(M_MEMRDBK, minfo->values.reg.memrdbk & ~0x1000);
  670. }
  671. mga_outl(M_MACCESS, minfo->values.reg.maccess | 0x8000);
  672. udelay(200);
  673. minfo->hw.MXoptionReg |= 0x001F8000 & minfo->values.reg.opt;
  674. pci_write_config_dword(minfo->pcidev, PCI_OPTION_REG, minfo->hw.MXoptionReg);
  675. /* value is written to memory chips only if old != new */
  676. mga_outl(M_PLNWT, 0);
  677. mga_outl(M_PLNWT, ~0);
  678. if (minfo->values.reg.mctlwtst != minfo->values.reg.mctlwtst_core) {
  679. mga_outl(M_CTLWTST, minfo->values.reg.mctlwtst_core);
  680. }
  681. }
  682. static void g450_preinit(struct matrox_fb_info *minfo)
  683. {
  684. u_int32_t c2ctl;
  685. u_int8_t curctl;
  686. u_int8_t c1ctl;
  687. /* minfo->hw.MXoptionReg = minfo->values.reg.opt; */
  688. minfo->hw.MXoptionReg &= 0xC0000100;
  689. minfo->hw.MXoptionReg |= 0x00000020;
  690. if (minfo->devflags.novga)
  691. minfo->hw.MXoptionReg &= ~0x00000100;
  692. if (minfo->devflags.nobios)
  693. minfo->hw.MXoptionReg &= ~0x40000000;
  694. if (minfo->devflags.nopciretry)
  695. minfo->hw.MXoptionReg |= 0x20000000;
  696. minfo->hw.MXoptionReg |= minfo->values.reg.opt & 0x03400040;
  697. pci_write_config_dword(minfo->pcidev, PCI_OPTION_REG, minfo->hw.MXoptionReg);
  698. /* Init system clocks */
  699. /* stop crtc2 */
  700. c2ctl = mga_inl(M_C2CTL);
  701. mga_outl(M_C2CTL, c2ctl & ~1);
  702. /* stop cursor */
  703. curctl = inDAC1064(minfo, M1064_XCURCTRL);
  704. outDAC1064(minfo, M1064_XCURCTRL, 0);
  705. /* stop crtc1 */
  706. c1ctl = mga_readr(M_SEQ_INDEX, 1);
  707. mga_setr(M_SEQ_INDEX, 1, c1ctl | 0x20);
  708. g450_mclk_init(minfo);
  709. g450_memory_init(minfo);
  710. /* set legacy VGA clock sources for DOSEmu or VMware... */
  711. matroxfb_g450_setclk(minfo, 25175, M_PIXEL_PLL_A);
  712. matroxfb_g450_setclk(minfo, 28322, M_PIXEL_PLL_B);
  713. /* restore crtc1 */
  714. mga_setr(M_SEQ_INDEX, 1, c1ctl);
  715. /* restore cursor */
  716. outDAC1064(minfo, M1064_XCURCTRL, curctl);
  717. /* restore crtc2 */
  718. mga_outl(M_C2CTL, c2ctl);
  719. return;
  720. }
  721. static int MGAG100_preinit(struct matrox_fb_info *minfo)
  722. {
  723. static const int vxres_g100[] = { 512, 640, 768, 800, 832, 960,
  724. 1024, 1152, 1280, 1600, 1664, 1920,
  725. 2048, 0};
  726. struct matrox_hw_state *hw = &minfo->hw;
  727. u_int32_t reg50;
  728. #if 0
  729. u_int32_t q;
  730. #endif
  731. DBG(__func__)
  732. /* there are some instabilities if in_div > 19 && vco < 61000 */
  733. if (minfo->devflags.g450dac) {
  734. minfo->features.pll.vco_freq_min = 130000; /* my sample: >118 */
  735. } else {
  736. minfo->features.pll.vco_freq_min = 62000;
  737. }
  738. if (!minfo->features.pll.ref_freq) {
  739. minfo->features.pll.ref_freq = 27000;
  740. }
  741. minfo->features.pll.feed_div_min = 7;
  742. minfo->features.pll.feed_div_max = 127;
  743. minfo->features.pll.in_div_min = 1;
  744. minfo->features.pll.in_div_max = 31;
  745. minfo->features.pll.post_shift_max = 3;
  746. minfo->features.DAC1064.xvrefctrl = DAC1064_XVREFCTRL_G100_DEFAULT;
  747. /* minfo->capable.cfb4 = 0; ... preinitialized by 0 */
  748. minfo->capable.text = 1;
  749. minfo->capable.vxres = vxres_g100;
  750. minfo->capable.plnwt = minfo->devflags.accelerator == FB_ACCEL_MATROX_MGAG100
  751. ? minfo->devflags.sgram : 1;
  752. if (minfo->devflags.g450dac) {
  753. minfo->outputs[0].output = &g450out;
  754. } else {
  755. minfo->outputs[0].output = &m1064;
  756. }
  757. minfo->outputs[0].src = minfo->outputs[0].default_src;
  758. minfo->outputs[0].data = minfo;
  759. minfo->outputs[0].mode = MATROXFB_OUTPUT_MODE_MONITOR;
  760. if (minfo->devflags.g450dac) {
  761. /* we must do this always, BIOS does not do it for us
  762. and accelerator dies without it */
  763. mga_outl(0x1C0C, 0);
  764. }
  765. if (minfo->devflags.noinit)
  766. return 0;
  767. if (minfo->devflags.g450dac) {
  768. g450_preinit(minfo);
  769. return 0;
  770. }
  771. hw->MXoptionReg &= 0xC0000100;
  772. hw->MXoptionReg |= 0x00000020;
  773. if (minfo->devflags.novga)
  774. hw->MXoptionReg &= ~0x00000100;
  775. if (minfo->devflags.nobios)
  776. hw->MXoptionReg &= ~0x40000000;
  777. if (minfo->devflags.nopciretry)
  778. hw->MXoptionReg |= 0x20000000;
  779. pci_write_config_dword(minfo->pcidev, PCI_OPTION_REG, hw->MXoptionReg);
  780. DAC1064_setmclk(minfo, DAC1064_OPT_MDIV2 | DAC1064_OPT_GDIV3 | DAC1064_OPT_SCLK_PCI, 133333);
  781. if (minfo->devflags.accelerator == FB_ACCEL_MATROX_MGAG100) {
  782. pci_read_config_dword(minfo->pcidev, PCI_OPTION2_REG, &reg50);
  783. reg50 &= ~0x3000;
  784. pci_write_config_dword(minfo->pcidev, PCI_OPTION2_REG, reg50);
  785. hw->MXoptionReg |= 0x1080;
  786. pci_write_config_dword(minfo->pcidev, PCI_OPTION_REG, hw->MXoptionReg);
  787. mga_outl(M_CTLWTST, minfo->values.reg.mctlwtst);
  788. udelay(100);
  789. mga_outb(0x1C05, 0x00);
  790. mga_outb(0x1C05, 0x80);
  791. udelay(100);
  792. mga_outb(0x1C05, 0x40);
  793. mga_outb(0x1C05, 0xC0);
  794. udelay(100);
  795. reg50 &= ~0xFF;
  796. reg50 |= 0x07;
  797. pci_write_config_dword(minfo->pcidev, PCI_OPTION2_REG, reg50);
  798. /* it should help with G100 */
  799. mga_outb(M_GRAPHICS_INDEX, 6);
  800. mga_outb(M_GRAPHICS_DATA, (mga_inb(M_GRAPHICS_DATA) & 3) | 4);
  801. mga_setr(M_EXTVGA_INDEX, 0x03, 0x81);
  802. mga_setr(M_EXTVGA_INDEX, 0x04, 0x00);
  803. mga_writeb(minfo->video.vbase, 0x0000, 0xAA);
  804. mga_writeb(minfo->video.vbase, 0x0800, 0x55);
  805. mga_writeb(minfo->video.vbase, 0x4000, 0x55);
  806. #if 0
  807. if (mga_readb(minfo->video.vbase, 0x0000) != 0xAA) {
  808. hw->MXoptionReg &= ~0x1000;
  809. }
  810. #endif
  811. hw->MXoptionReg |= 0x00078020;
  812. } else if (minfo->devflags.accelerator == FB_ACCEL_MATROX_MGAG200) {
  813. pci_read_config_dword(minfo->pcidev, PCI_OPTION2_REG, &reg50);
  814. reg50 &= ~0x3000;
  815. pci_write_config_dword(minfo->pcidev, PCI_OPTION2_REG, reg50);
  816. if (minfo->devflags.memtype == -1)
  817. hw->MXoptionReg |= minfo->values.reg.opt & 0x1C00;
  818. else
  819. hw->MXoptionReg |= (minfo->devflags.memtype & 7) << 10;
  820. if (minfo->devflags.sgram)
  821. hw->MXoptionReg |= 0x4000;
  822. mga_outl(M_CTLWTST, minfo->values.reg.mctlwtst);
  823. mga_outl(M_MEMRDBK, minfo->values.reg.memrdbk);
  824. udelay(200);
  825. mga_outl(M_MACCESS, 0x00000000);
  826. mga_outl(M_MACCESS, 0x00008000);
  827. udelay(100);
  828. mga_outw(M_MEMRDBK, minfo->values.reg.memrdbk);
  829. hw->MXoptionReg |= 0x00078020;
  830. } else {
  831. pci_read_config_dword(minfo->pcidev, PCI_OPTION2_REG, &reg50);
  832. reg50 &= ~0x00000100;
  833. reg50 |= 0x00000000;
  834. pci_write_config_dword(minfo->pcidev, PCI_OPTION2_REG, reg50);
  835. if (minfo->devflags.memtype == -1)
  836. hw->MXoptionReg |= minfo->values.reg.opt & 0x1C00;
  837. else
  838. hw->MXoptionReg |= (minfo->devflags.memtype & 7) << 10;
  839. if (minfo->devflags.sgram)
  840. hw->MXoptionReg |= 0x4000;
  841. mga_outl(M_CTLWTST, minfo->values.reg.mctlwtst);
  842. mga_outl(M_MEMRDBK, minfo->values.reg.memrdbk);
  843. udelay(200);
  844. mga_outl(M_MACCESS, 0x00000000);
  845. mga_outl(M_MACCESS, 0x00008000);
  846. udelay(100);
  847. mga_outl(M_MEMRDBK, minfo->values.reg.memrdbk);
  848. hw->MXoptionReg |= 0x00040020;
  849. }
  850. pci_write_config_dword(minfo->pcidev, PCI_OPTION_REG, hw->MXoptionReg);
  851. return 0;
  852. }
  853. static void MGAG100_reset(struct matrox_fb_info *minfo)
  854. {
  855. u_int8_t b;
  856. struct matrox_hw_state *hw = &minfo->hw;
  857. DBG(__func__)
  858. {
  859. #ifdef G100_BROKEN_IBM_82351
  860. u_int32_t d;
  861. find 1014/22 (IBM/82351); /* if found and bridging Matrox, do some strange stuff */
  862. pci_read_config_byte(ibm, PCI_SECONDARY_BUS, &b);
  863. if (b == minfo->pcidev->bus->number) {
  864. pci_write_config_byte(ibm, PCI_COMMAND+1, 0); /* disable back-to-back & SERR */
  865. pci_write_config_byte(ibm, 0x41, 0xF4); /* ??? */
  866. pci_write_config_byte(ibm, PCI_IO_BASE, 0xF0); /* ??? */
  867. pci_write_config_byte(ibm, PCI_IO_LIMIT, 0x00); /* ??? */
  868. }
  869. #endif
  870. if (!minfo->devflags.noinit) {
  871. if (x7AF4 & 8) {
  872. hw->MXoptionReg |= 0x40; /* FIXME... */
  873. pci_write_config_dword(minfo->pcidev, PCI_OPTION_REG, hw->MXoptionReg);
  874. }
  875. mga_setr(M_EXTVGA_INDEX, 0x06, 0x00);
  876. }
  877. }
  878. if (minfo->devflags.g450dac) {
  879. /* either leave MCLK as is... or they were set in preinit */
  880. hw->DACclk[3] = inDAC1064(minfo, DAC1064_XSYSPLLM);
  881. hw->DACclk[4] = inDAC1064(minfo, DAC1064_XSYSPLLN);
  882. hw->DACclk[5] = inDAC1064(minfo, DAC1064_XSYSPLLP);
  883. } else {
  884. DAC1064_setmclk(minfo, DAC1064_OPT_RESERVED | DAC1064_OPT_MDIV2 | DAC1064_OPT_GDIV1 | DAC1064_OPT_SCLK_PLL, 133333);
  885. }
  886. if (minfo->devflags.accelerator == FB_ACCEL_MATROX_MGAG400) {
  887. if (minfo->devflags.dfp_type == -1) {
  888. minfo->devflags.dfp_type = inDAC1064(minfo, 0x1F);
  889. }
  890. }
  891. if (minfo->devflags.noinit)
  892. return;
  893. if (minfo->devflags.g450dac) {
  894. } else {
  895. MGAG100_setPixClock(minfo, 4, 25175);
  896. MGAG100_setPixClock(minfo, 5, 28322);
  897. if (x7AF4 & 0x10) {
  898. b = inDAC1064(minfo, M1064_XGENIODATA) & ~1;
  899. outDAC1064(minfo, M1064_XGENIODATA, b);
  900. b = inDAC1064(minfo, M1064_XGENIOCTRL) | 1;
  901. outDAC1064(minfo, M1064_XGENIOCTRL, b);
  902. }
  903. }
  904. }
  905. #endif
  906. #ifdef CONFIG_FB_MATROX_MYSTIQUE
  907. static void MGA1064_restore(struct matrox_fb_info *minfo)
  908. {
  909. int i;
  910. struct matrox_hw_state *hw = &minfo->hw;
  911. CRITFLAGS
  912. DBG(__func__)
  913. CRITBEGIN
  914. pci_write_config_dword(minfo->pcidev, PCI_OPTION_REG, hw->MXoptionReg);
  915. mga_outb(M_IEN, 0x00);
  916. mga_outb(M_CACHEFLUSH, 0x00);
  917. CRITEND
  918. DAC1064_restore_1(minfo);
  919. matroxfb_vgaHWrestore(minfo);
  920. minfo->crtc1.panpos = -1;
  921. for (i = 0; i < 6; i++)
  922. mga_setr(M_EXTVGA_INDEX, i, hw->CRTCEXT[i]);
  923. DAC1064_restore_2(minfo);
  924. }
  925. #endif
  926. #ifdef CONFIG_FB_MATROX_G
  927. static void MGAG100_restore(struct matrox_fb_info *minfo)
  928. {
  929. int i;
  930. struct matrox_hw_state *hw = &minfo->hw;
  931. CRITFLAGS
  932. DBG(__func__)
  933. CRITBEGIN
  934. pci_write_config_dword(minfo->pcidev, PCI_OPTION_REG, hw->MXoptionReg);
  935. CRITEND
  936. DAC1064_restore_1(minfo);
  937. matroxfb_vgaHWrestore(minfo);
  938. if (minfo->devflags.support32MB)
  939. mga_setr(M_EXTVGA_INDEX, 8, hw->CRTCEXT[8]);
  940. minfo->crtc1.panpos = -1;
  941. for (i = 0; i < 6; i++)
  942. mga_setr(M_EXTVGA_INDEX, i, hw->CRTCEXT[i]);
  943. DAC1064_restore_2(minfo);
  944. }
  945. #endif
  946. #ifdef CONFIG_FB_MATROX_MYSTIQUE
  947. struct matrox_switch matrox_mystique = {
  948. MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
  949. };
  950. EXPORT_SYMBOL(matrox_mystique);
  951. #endif
  952. #ifdef CONFIG_FB_MATROX_G
  953. struct matrox_switch matrox_G100 = {
  954. MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
  955. };
  956. EXPORT_SYMBOL(matrox_G100);
  957. #endif
  958. #ifdef NEED_DAC1064
  959. EXPORT_SYMBOL(DAC1064_global_init);
  960. EXPORT_SYMBOL(DAC1064_global_restore);
  961. #endif
  962. MODULE_LICENSE("GPL");