matroxfb_DAC1064.c 33 KB

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