matroxfb_Ti3026.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  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. * (following author is not in any relation with this code, but his code
  69. * is included in this driver)
  70. *
  71. * Based on framebuffer driver for VBE 2.0 compliant graphic boards
  72. * (c) 1998 Gerd Knorr <kraxel@cs.tu-berlin.de>
  73. *
  74. * (following author is not in any relation with this code, but his ideas
  75. * were used when writing this driver)
  76. *
  77. * FreeVBE/AF (Matrox), "Shawn Hargreaves" <shawn@talula.demon.co.uk>
  78. *
  79. */
  80. #include "matroxfb_Ti3026.h"
  81. #include "matroxfb_misc.h"
  82. #include "matroxfb_accel.h"
  83. #include <linux/matroxfb.h>
  84. #ifdef CONFIG_FB_MATROX_MILLENIUM
  85. #define outTi3026 matroxfb_DAC_out
  86. #define inTi3026 matroxfb_DAC_in
  87. #define TVP3026_INDEX 0x00
  88. #define TVP3026_PALWRADD 0x00
  89. #define TVP3026_PALDATA 0x01
  90. #define TVP3026_PIXRDMSK 0x02
  91. #define TVP3026_PALRDADD 0x03
  92. #define TVP3026_CURCOLWRADD 0x04
  93. #define TVP3026_CLOVERSCAN 0x00
  94. #define TVP3026_CLCOLOR0 0x01
  95. #define TVP3026_CLCOLOR1 0x02
  96. #define TVP3026_CLCOLOR2 0x03
  97. #define TVP3026_CURCOLDATA 0x05
  98. #define TVP3026_CURCOLRDADD 0x07
  99. #define TVP3026_CURCTRL 0x09
  100. #define TVP3026_X_DATAREG 0x0A
  101. #define TVP3026_CURRAMDATA 0x0B
  102. #define TVP3026_CURPOSXL 0x0C
  103. #define TVP3026_CURPOSXH 0x0D
  104. #define TVP3026_CURPOSYL 0x0E
  105. #define TVP3026_CURPOSYH 0x0F
  106. #define TVP3026_XSILICONREV 0x01
  107. #define TVP3026_XCURCTRL 0x06
  108. #define TVP3026_XCURCTRL_DIS 0x00 /* transparent, transparent, transparent, transparent */
  109. #define TVP3026_XCURCTRL_3COLOR 0x01 /* transparent, 0, 1, 2 */
  110. #define TVP3026_XCURCTRL_XGA 0x02 /* 0, 1, transparent, complement */
  111. #define TVP3026_XCURCTRL_XWIN 0x03 /* transparent, transparent, 0, 1 */
  112. #define TVP3026_XCURCTRL_BLANK2048 0x00
  113. #define TVP3026_XCURCTRL_BLANK4096 0x10
  114. #define TVP3026_XCURCTRL_INTERLACED 0x20
  115. #define TVP3026_XCURCTRL_ODD 0x00 /* ext.signal ODD/\EVEN */
  116. #define TVP3026_XCURCTRL_EVEN 0x40 /* ext.signal EVEN/\ODD */
  117. #define TVP3026_XCURCTRL_INDIRECT 0x00
  118. #define TVP3026_XCURCTRL_DIRECT 0x80
  119. #define TVP3026_XLATCHCTRL 0x0F
  120. #define TVP3026_XLATCHCTRL_1_1 0x06
  121. #define TVP3026_XLATCHCTRL_2_1 0x07
  122. #define TVP3026_XLATCHCTRL_4_1 0x06
  123. #define TVP3026_XLATCHCTRL_8_1 0x06
  124. #define TVP3026_XLATCHCTRL_16_1 0x06
  125. #define TVP3026A_XLATCHCTRL_4_3 0x06 /* ??? do not understand... but it works... !!! */
  126. #define TVP3026A_XLATCHCTRL_8_3 0x07
  127. #define TVP3026B_XLATCHCTRL_4_3 0x08
  128. #define TVP3026B_XLATCHCTRL_8_3 0x06 /* ??? do not understand... but it works... !!! */
  129. #define TVP3026_XTRUECOLORCTRL 0x18
  130. #define TVP3026_XTRUECOLORCTRL_VRAM_SHIFT_ACCEL 0x00
  131. #define TVP3026_XTRUECOLORCTRL_VRAM_SHIFT_TVP 0x20
  132. #define TVP3026_XTRUECOLORCTRL_PSEUDOCOLOR 0x80
  133. #define TVP3026_XTRUECOLORCTRL_TRUECOLOR 0x40 /* paletized */
  134. #define TVP3026_XTRUECOLORCTRL_DIRECTCOLOR 0x00
  135. #define TVP3026_XTRUECOLORCTRL_24_ALTERNATE 0x08 /* 5:4/5:2 instead of 4:3/8:3 */
  136. #define TVP3026_XTRUECOLORCTRL_RGB_888 0x16 /* 4:3/8:3 (or 5:4/5:2) */
  137. #define TVP3026_XTRUECOLORCTRL_BGR_888 0x17
  138. #define TVP3026_XTRUECOLORCTRL_ORGB_8888 0x06
  139. #define TVP3026_XTRUECOLORCTRL_BGRO_8888 0x07
  140. #define TVP3026_XTRUECOLORCTRL_RGB_565 0x05
  141. #define TVP3026_XTRUECOLORCTRL_ORGB_1555 0x04
  142. #define TVP3026_XTRUECOLORCTRL_RGB_664 0x03
  143. #define TVP3026_XTRUECOLORCTRL_RGBO_4444 0x01
  144. #define TVP3026_XMUXCTRL 0x19
  145. #define TVP3026_XMUXCTRL_MEMORY_8BIT 0x01 /* - */
  146. #define TVP3026_XMUXCTRL_MEMORY_16BIT 0x02 /* - */
  147. #define TVP3026_XMUXCTRL_MEMORY_32BIT 0x03 /* 2MB RAM, 512K * 4 */
  148. #define TVP3026_XMUXCTRL_MEMORY_64BIT 0x04 /* >2MB RAM, 512K * 8 & more */
  149. #define TVP3026_XMUXCTRL_PIXEL_4BIT 0x40 /* L0,H0,L1,H1... */
  150. #define TVP3026_XMUXCTRL_PIXEL_4BIT_SWAPPED 0x60 /* H0,L0,H1,L1... */
  151. #define TVP3026_XMUXCTRL_PIXEL_8BIT 0x48
  152. #define TVP3026_XMUXCTRL_PIXEL_16BIT 0x50
  153. #define TVP3026_XMUXCTRL_PIXEL_32BIT 0x58
  154. #define TVP3026_XMUXCTRL_VGA 0x98 /* VGA MEMORY, 8BIT PIXEL */
  155. #define TVP3026_XCLKCTRL 0x1A
  156. #define TVP3026_XCLKCTRL_DIV1 0x00
  157. #define TVP3026_XCLKCTRL_DIV2 0x10
  158. #define TVP3026_XCLKCTRL_DIV4 0x20
  159. #define TVP3026_XCLKCTRL_DIV8 0x30
  160. #define TVP3026_XCLKCTRL_DIV16 0x40
  161. #define TVP3026_XCLKCTRL_DIV32 0x50
  162. #define TVP3026_XCLKCTRL_DIV64 0x60
  163. #define TVP3026_XCLKCTRL_CLKSTOPPED 0x70
  164. #define TVP3026_XCLKCTRL_SRC_CLK0 0x00
  165. #define TVP3026_XCLKCTRL_SRC_CLK1 0x01
  166. #define TVP3026_XCLKCTRL_SRC_CLK2 0x02 /* CLK2 is TTL source*/
  167. #define TVP3026_XCLKCTRL_SRC_NCLK2 0x03 /* not CLK2 is TTL source */
  168. #define TVP3026_XCLKCTRL_SRC_ECLK2 0x04 /* CLK2 and not CLK2 is ECL source */
  169. #define TVP3026_XCLKCTRL_SRC_PLL 0x05
  170. #define TVP3026_XCLKCTRL_SRC_DIS 0x06 /* disable & poweroff internal clock */
  171. #define TVP3026_XCLKCTRL_SRC_CLK0VGA 0x07
  172. #define TVP3026_XPALETTEPAGE 0x1C
  173. #define TVP3026_XGENCTRL 0x1D
  174. #define TVP3026_XGENCTRL_HSYNC_POS 0x00
  175. #define TVP3026_XGENCTRL_HSYNC_NEG 0x01
  176. #define TVP3026_XGENCTRL_VSYNC_POS 0x00
  177. #define TVP3026_XGENCTRL_VSYNC_NEG 0x02
  178. #define TVP3026_XGENCTRL_LITTLE_ENDIAN 0x00
  179. #define TVP3026_XGENCTRL_BIG_ENDIAN 0x08
  180. #define TVP3026_XGENCTRL_BLACK_0IRE 0x00
  181. #define TVP3026_XGENCTRL_BLACK_75IRE 0x10
  182. #define TVP3026_XGENCTRL_NO_SYNC_ON_GREEN 0x00
  183. #define TVP3026_XGENCTRL_SYNC_ON_GREEN 0x20
  184. #define TVP3026_XGENCTRL_OVERSCAN_DIS 0x00
  185. #define TVP3026_XGENCTRL_OVERSCAN_EN 0x40
  186. #define TVP3026_XMISCCTRL 0x1E
  187. #define TVP3026_XMISCCTRL_DAC_PUP 0x00
  188. #define TVP3026_XMISCCTRL_DAC_PDOWN 0x01
  189. #define TVP3026_XMISCCTRL_DAC_EXT 0x00 /* or 8, bit 3 is ignored */
  190. #define TVP3026_XMISCCTRL_DAC_6BIT 0x04
  191. #define TVP3026_XMISCCTRL_DAC_8BIT 0x0C
  192. #define TVP3026_XMISCCTRL_PSEL_DIS 0x00
  193. #define TVP3026_XMISCCTRL_PSEL_EN 0x10
  194. #define TVP3026_XMISCCTRL_PSEL_LOW 0x00 /* PSEL high selects directcolor */
  195. #define TVP3026_XMISCCTRL_PSEL_HIGH 0x20 /* PSEL high selects truecolor or pseudocolor */
  196. #define TVP3026_XGENIOCTRL 0x2A
  197. #define TVP3026_XGENIODATA 0x2B
  198. #define TVP3026_XPLLADDR 0x2C
  199. #define TVP3026_XPLLADDR_X(LOOP,MCLK,PIX) (((LOOP)<<4) | ((MCLK)<<2) | (PIX))
  200. #define TVP3026_XPLLDATA_N 0x00
  201. #define TVP3026_XPLLDATA_M 0x01
  202. #define TVP3026_XPLLDATA_P 0x02
  203. #define TVP3026_XPLLDATA_STAT 0x03
  204. #define TVP3026_XPIXPLLDATA 0x2D
  205. #define TVP3026_XMEMPLLDATA 0x2E
  206. #define TVP3026_XLOOPPLLDATA 0x2F
  207. #define TVP3026_XCOLKEYOVRMIN 0x30
  208. #define TVP3026_XCOLKEYOVRMAX 0x31
  209. #define TVP3026_XCOLKEYREDMIN 0x32
  210. #define TVP3026_XCOLKEYREDMAX 0x33
  211. #define TVP3026_XCOLKEYGREENMIN 0x34
  212. #define TVP3026_XCOLKEYGREENMAX 0x35
  213. #define TVP3026_XCOLKEYBLUEMIN 0x36
  214. #define TVP3026_XCOLKEYBLUEMAX 0x37
  215. #define TVP3026_XCOLKEYCTRL 0x38
  216. #define TVP3026_XCOLKEYCTRL_OVR_EN 0x01
  217. #define TVP3026_XCOLKEYCTRL_RED_EN 0x02
  218. #define TVP3026_XCOLKEYCTRL_GREEN_EN 0x04
  219. #define TVP3026_XCOLKEYCTRL_BLUE_EN 0x08
  220. #define TVP3026_XCOLKEYCTRL_NEGATE 0x10
  221. #define TVP3026_XCOLKEYCTRL_ZOOM1 0x00
  222. #define TVP3026_XCOLKEYCTRL_ZOOM2 0x20
  223. #define TVP3026_XCOLKEYCTRL_ZOOM4 0x40
  224. #define TVP3026_XCOLKEYCTRL_ZOOM8 0x60
  225. #define TVP3026_XCOLKEYCTRL_ZOOM16 0x80
  226. #define TVP3026_XCOLKEYCTRL_ZOOM32 0xA0
  227. #define TVP3026_XMEMPLLCTRL 0x39
  228. #define TVP3026_XMEMPLLCTRL_DIV(X) (((X)-1)>>1) /* 2,4,6,8,10,12,14,16, division applied to LOOP PLL after divide by 2^P */
  229. #define TVP3026_XMEMPLLCTRL_STROBEMKC4 0x08
  230. #define TVP3026_XMEMPLLCTRL_MCLK_DOTCLOCK 0x00 /* MKC4 */
  231. #define TVP3026_XMEMPLLCTRL_MCLK_MCLKPLL 0x10 /* MKC4 */
  232. #define TVP3026_XMEMPLLCTRL_RCLK_PIXPLL 0x00
  233. #define TVP3026_XMEMPLLCTRL_RCLK_LOOPPLL 0x20
  234. #define TVP3026_XMEMPLLCTRL_RCLK_DOTDIVN 0x40 /* dot clock divided by loop pclk N prescaler */
  235. #define TVP3026_XSENSETEST 0x3A
  236. #define TVP3026_XTESTMODEDATA 0x3B
  237. #define TVP3026_XCRCREML 0x3C
  238. #define TVP3026_XCRCREMH 0x3D
  239. #define TVP3026_XCRCBITSEL 0x3E
  240. #define TVP3026_XID 0x3F
  241. static const unsigned char DACseq[] =
  242. { TVP3026_XLATCHCTRL, TVP3026_XTRUECOLORCTRL,
  243. TVP3026_XMUXCTRL, TVP3026_XCLKCTRL,
  244. TVP3026_XPALETTEPAGE,
  245. TVP3026_XGENCTRL,
  246. TVP3026_XMISCCTRL,
  247. TVP3026_XGENIOCTRL,
  248. TVP3026_XGENIODATA,
  249. TVP3026_XCOLKEYOVRMIN, TVP3026_XCOLKEYOVRMAX, TVP3026_XCOLKEYREDMIN, TVP3026_XCOLKEYREDMAX,
  250. TVP3026_XCOLKEYGREENMIN, TVP3026_XCOLKEYGREENMAX, TVP3026_XCOLKEYBLUEMIN, TVP3026_XCOLKEYBLUEMAX,
  251. TVP3026_XCOLKEYCTRL,
  252. TVP3026_XMEMPLLCTRL, TVP3026_XSENSETEST, TVP3026_XCURCTRL };
  253. #define POS3026_XLATCHCTRL 0
  254. #define POS3026_XTRUECOLORCTRL 1
  255. #define POS3026_XMUXCTRL 2
  256. #define POS3026_XCLKCTRL 3
  257. #define POS3026_XGENCTRL 5
  258. #define POS3026_XMISCCTRL 6
  259. #define POS3026_XMEMPLLCTRL 18
  260. #define POS3026_XCURCTRL 20
  261. static const unsigned char MGADACbpp32[] =
  262. { TVP3026_XLATCHCTRL_2_1, TVP3026_XTRUECOLORCTRL_DIRECTCOLOR | TVP3026_XTRUECOLORCTRL_ORGB_8888,
  263. 0x00, TVP3026_XCLKCTRL_DIV1 | TVP3026_XCLKCTRL_SRC_PLL,
  264. 0x00,
  265. TVP3026_XGENCTRL_HSYNC_POS | TVP3026_XGENCTRL_VSYNC_POS | TVP3026_XGENCTRL_LITTLE_ENDIAN | TVP3026_XGENCTRL_BLACK_0IRE | TVP3026_XGENCTRL_NO_SYNC_ON_GREEN | TVP3026_XGENCTRL_OVERSCAN_DIS,
  266. TVP3026_XMISCCTRL_DAC_PUP | TVP3026_XMISCCTRL_DAC_8BIT | TVP3026_XMISCCTRL_PSEL_DIS | TVP3026_XMISCCTRL_PSEL_HIGH,
  267. 0x00,
  268. 0x1E,
  269. 0xFF, 0xFF, 0xFF, 0xFF,
  270. 0xFF, 0xFF, 0xFF, 0xFF,
  271. TVP3026_XCOLKEYCTRL_ZOOM1,
  272. 0x00, 0x00, TVP3026_XCURCTRL_DIS };
  273. static int Ti3026_calcclock(const struct matrox_fb_info *minfo,
  274. unsigned int freq, unsigned int fmax, int *in,
  275. int *feed, int *post)
  276. {
  277. unsigned int fvco;
  278. unsigned int lin, lfeed, lpost;
  279. DBG(__func__)
  280. fvco = PLL_calcclock(minfo, freq, fmax, &lin, &lfeed, &lpost);
  281. fvco >>= (*post = lpost);
  282. *in = 64 - lin;
  283. *feed = 64 - lfeed;
  284. return fvco;
  285. }
  286. static int Ti3026_setpclk(struct matrox_fb_info *minfo, int clk)
  287. {
  288. unsigned int f_pll;
  289. unsigned int pixfeed, pixin, pixpost;
  290. struct matrox_hw_state *hw = &minfo->hw;
  291. DBG(__func__)
  292. f_pll = Ti3026_calcclock(minfo, clk, minfo->max_pixel_clock, &pixin, &pixfeed, &pixpost);
  293. hw->DACclk[0] = pixin | 0xC0;
  294. hw->DACclk[1] = pixfeed;
  295. hw->DACclk[2] = pixpost | 0xB0;
  296. {
  297. unsigned int loopfeed, loopin, looppost, loopdiv, z;
  298. unsigned int Bpp;
  299. Bpp = minfo->curr.final_bppShift;
  300. if (minfo->fbcon.var.bits_per_pixel == 24) {
  301. loopfeed = 3; /* set lm to any possible value */
  302. loopin = 3 * 32 / Bpp;
  303. } else {
  304. loopfeed = 4;
  305. loopin = 4 * 32 / Bpp;
  306. }
  307. z = (110000 * loopin) / (f_pll * loopfeed);
  308. loopdiv = 0; /* div 2 */
  309. if (z < 2)
  310. looppost = 0;
  311. else if (z < 4)
  312. looppost = 1;
  313. else if (z < 8)
  314. looppost = 2;
  315. else {
  316. looppost = 3;
  317. loopdiv = z/16;
  318. }
  319. if (minfo->fbcon.var.bits_per_pixel == 24) {
  320. hw->DACclk[3] = ((65 - loopin) & 0x3F) | 0xC0;
  321. hw->DACclk[4] = (65 - loopfeed) | 0x80;
  322. if (minfo->accel.ramdac_rev > 0x20) {
  323. if (isInterleave(minfo))
  324. hw->DACreg[POS3026_XLATCHCTRL] = TVP3026B_XLATCHCTRL_8_3;
  325. else {
  326. hw->DACclk[4] &= ~0xC0;
  327. hw->DACreg[POS3026_XLATCHCTRL] = TVP3026B_XLATCHCTRL_4_3;
  328. }
  329. } else {
  330. if (isInterleave(minfo))
  331. ; /* default... */
  332. else {
  333. hw->DACclk[4] ^= 0xC0; /* change from 0x80 to 0x40 */
  334. hw->DACreg[POS3026_XLATCHCTRL] = TVP3026A_XLATCHCTRL_4_3;
  335. }
  336. }
  337. hw->DACclk[5] = looppost | 0xF8;
  338. if (minfo->devflags.mga_24bpp_fix)
  339. hw->DACclk[5] ^= 0x40;
  340. } else {
  341. hw->DACclk[3] = ((65 - loopin) & 0x3F) | 0xC0;
  342. hw->DACclk[4] = 65 - loopfeed;
  343. hw->DACclk[5] = looppost | 0xF0;
  344. }
  345. hw->DACreg[POS3026_XMEMPLLCTRL] = loopdiv | TVP3026_XMEMPLLCTRL_MCLK_MCLKPLL | TVP3026_XMEMPLLCTRL_RCLK_LOOPPLL;
  346. }
  347. return 0;
  348. }
  349. static int Ti3026_init(struct matrox_fb_info *minfo, struct my_timming *m)
  350. {
  351. u_int8_t muxctrl = isInterleave(minfo) ? TVP3026_XMUXCTRL_MEMORY_64BIT : TVP3026_XMUXCTRL_MEMORY_32BIT;
  352. struct matrox_hw_state *hw = &minfo->hw;
  353. DBG(__func__)
  354. memcpy(hw->DACreg, MGADACbpp32, sizeof(hw->DACreg));
  355. switch (minfo->fbcon.var.bits_per_pixel) {
  356. case 4: hw->DACreg[POS3026_XLATCHCTRL] = TVP3026_XLATCHCTRL_16_1; /* or _8_1, they are same */
  357. hw->DACreg[POS3026_XTRUECOLORCTRL] = TVP3026_XTRUECOLORCTRL_PSEUDOCOLOR;
  358. hw->DACreg[POS3026_XMUXCTRL] = muxctrl | TVP3026_XMUXCTRL_PIXEL_4BIT;
  359. hw->DACreg[POS3026_XCLKCTRL] = TVP3026_XCLKCTRL_SRC_PLL | TVP3026_XCLKCTRL_DIV8;
  360. hw->DACreg[POS3026_XMISCCTRL] = TVP3026_XMISCCTRL_DAC_PUP | TVP3026_XMISCCTRL_DAC_8BIT | TVP3026_XMISCCTRL_PSEL_DIS | TVP3026_XMISCCTRL_PSEL_LOW;
  361. break;
  362. case 8: hw->DACreg[POS3026_XLATCHCTRL] = TVP3026_XLATCHCTRL_8_1; /* or _4_1, they are same */
  363. hw->DACreg[POS3026_XTRUECOLORCTRL] = TVP3026_XTRUECOLORCTRL_PSEUDOCOLOR;
  364. hw->DACreg[POS3026_XMUXCTRL] = muxctrl | TVP3026_XMUXCTRL_PIXEL_8BIT;
  365. hw->DACreg[POS3026_XCLKCTRL] = TVP3026_XCLKCTRL_SRC_PLL | TVP3026_XCLKCTRL_DIV4;
  366. hw->DACreg[POS3026_XMISCCTRL] = TVP3026_XMISCCTRL_DAC_PUP | TVP3026_XMISCCTRL_DAC_8BIT | TVP3026_XMISCCTRL_PSEL_DIS | TVP3026_XMISCCTRL_PSEL_LOW;
  367. break;
  368. case 16:
  369. /* XLATCHCTRL should be _4_1 / _2_1... Why is not? (_2_1 is used every time) */
  370. hw->DACreg[POS3026_XTRUECOLORCTRL] = (minfo->fbcon.var.green.length == 5) ? (TVP3026_XTRUECOLORCTRL_DIRECTCOLOR | TVP3026_XTRUECOLORCTRL_ORGB_1555) : (TVP3026_XTRUECOLORCTRL_DIRECTCOLOR | TVP3026_XTRUECOLORCTRL_RGB_565);
  371. hw->DACreg[POS3026_XMUXCTRL] = muxctrl | TVP3026_XMUXCTRL_PIXEL_16BIT;
  372. hw->DACreg[POS3026_XCLKCTRL] = TVP3026_XCLKCTRL_SRC_PLL | TVP3026_XCLKCTRL_DIV2;
  373. break;
  374. case 24:
  375. /* XLATCHCTRL is: for (A) use _4_3 (?_8_3 is same? TBD), for (B) it is set in setpclk */
  376. hw->DACreg[POS3026_XTRUECOLORCTRL] = TVP3026_XTRUECOLORCTRL_DIRECTCOLOR | TVP3026_XTRUECOLORCTRL_RGB_888;
  377. hw->DACreg[POS3026_XMUXCTRL] = muxctrl | TVP3026_XMUXCTRL_PIXEL_32BIT;
  378. hw->DACreg[POS3026_XCLKCTRL] = TVP3026_XCLKCTRL_SRC_PLL | TVP3026_XCLKCTRL_DIV4;
  379. break;
  380. case 32:
  381. /* XLATCHCTRL should be _2_1 / _1_1... Why is not? (_2_1 is used every time) */
  382. hw->DACreg[POS3026_XMUXCTRL] = muxctrl | TVP3026_XMUXCTRL_PIXEL_32BIT;
  383. break;
  384. default:
  385. return 1; /* TODO: failed */
  386. }
  387. if (matroxfb_vgaHWinit(minfo, m)) return 1;
  388. /* set SYNC */
  389. hw->MiscOutReg = 0xCB;
  390. if (m->sync & FB_SYNC_HOR_HIGH_ACT)
  391. hw->DACreg[POS3026_XGENCTRL] |= TVP3026_XGENCTRL_HSYNC_NEG;
  392. if (m->sync & FB_SYNC_VERT_HIGH_ACT)
  393. hw->DACreg[POS3026_XGENCTRL] |= TVP3026_XGENCTRL_VSYNC_NEG;
  394. if (m->sync & FB_SYNC_ON_GREEN)
  395. hw->DACreg[POS3026_XGENCTRL] |= TVP3026_XGENCTRL_SYNC_ON_GREEN;
  396. /* set DELAY */
  397. if (minfo->video.len < 0x400000)
  398. hw->CRTCEXT[3] |= 0x08;
  399. else if (minfo->video.len > 0x400000)
  400. hw->CRTCEXT[3] |= 0x10;
  401. /* set HWCURSOR */
  402. if (m->interlaced) {
  403. hw->DACreg[POS3026_XCURCTRL] |= TVP3026_XCURCTRL_INTERLACED;
  404. }
  405. if (m->HTotal >= 1536)
  406. hw->DACreg[POS3026_XCURCTRL] |= TVP3026_XCURCTRL_BLANK4096;
  407. /* set interleaving */
  408. hw->MXoptionReg &= ~0x00001000;
  409. if (isInterleave(minfo)) hw->MXoptionReg |= 0x00001000;
  410. /* set DAC */
  411. Ti3026_setpclk(minfo, m->pixclock);
  412. return 0;
  413. }
  414. static void ti3026_setMCLK(struct matrox_fb_info *minfo, int fout)
  415. {
  416. unsigned int f_pll;
  417. unsigned int pclk_m, pclk_n, pclk_p;
  418. unsigned int mclk_m, mclk_n, mclk_p;
  419. unsigned int rfhcnt, mclk_ctl;
  420. int tmout;
  421. DBG(__func__)
  422. f_pll = Ti3026_calcclock(minfo, fout, minfo->max_pixel_clock, &mclk_n, &mclk_m, &mclk_p);
  423. /* save pclk */
  424. outTi3026(minfo, TVP3026_XPLLADDR, 0xFC);
  425. pclk_n = inTi3026(minfo, TVP3026_XPIXPLLDATA);
  426. outTi3026(minfo, TVP3026_XPLLADDR, 0xFD);
  427. pclk_m = inTi3026(minfo, TVP3026_XPIXPLLDATA);
  428. outTi3026(minfo, TVP3026_XPLLADDR, 0xFE);
  429. pclk_p = inTi3026(minfo, TVP3026_XPIXPLLDATA);
  430. /* stop pclk */
  431. outTi3026(minfo, TVP3026_XPLLADDR, 0xFE);
  432. outTi3026(minfo, TVP3026_XPIXPLLDATA, 0x00);
  433. /* set pclk to new mclk */
  434. outTi3026(minfo, TVP3026_XPLLADDR, 0xFC);
  435. outTi3026(minfo, TVP3026_XPIXPLLDATA, mclk_n | 0xC0);
  436. outTi3026(minfo, TVP3026_XPIXPLLDATA, mclk_m);
  437. outTi3026(minfo, TVP3026_XPIXPLLDATA, mclk_p | 0xB0);
  438. /* wait for PLL to lock */
  439. for (tmout = 500000; tmout; tmout--) {
  440. if (inTi3026(minfo, TVP3026_XPIXPLLDATA) & 0x40)
  441. break;
  442. udelay(10);
  443. }
  444. if (!tmout)
  445. printk(KERN_ERR "matroxfb: Temporary pixel PLL not locked after 5 secs\n");
  446. /* output pclk on mclk pin */
  447. mclk_ctl = inTi3026(minfo, TVP3026_XMEMPLLCTRL);
  448. outTi3026(minfo, TVP3026_XMEMPLLCTRL, mclk_ctl & 0xE7);
  449. outTi3026(minfo, TVP3026_XMEMPLLCTRL, (mclk_ctl & 0xE7) | TVP3026_XMEMPLLCTRL_STROBEMKC4);
  450. /* stop MCLK */
  451. outTi3026(minfo, TVP3026_XPLLADDR, 0xFB);
  452. outTi3026(minfo, TVP3026_XMEMPLLDATA, 0x00);
  453. /* set mclk to new freq */
  454. outTi3026(minfo, TVP3026_XPLLADDR, 0xF3);
  455. outTi3026(minfo, TVP3026_XMEMPLLDATA, mclk_n | 0xC0);
  456. outTi3026(minfo, TVP3026_XMEMPLLDATA, mclk_m);
  457. outTi3026(minfo, TVP3026_XMEMPLLDATA, mclk_p | 0xB0);
  458. /* wait for PLL to lock */
  459. for (tmout = 500000; tmout; tmout--) {
  460. if (inTi3026(minfo, TVP3026_XMEMPLLDATA) & 0x40)
  461. break;
  462. udelay(10);
  463. }
  464. if (!tmout)
  465. printk(KERN_ERR "matroxfb: Memory PLL not locked after 5 secs\n");
  466. f_pll = f_pll * 333 / (10000 << mclk_p);
  467. if (isMilleniumII(minfo)) {
  468. rfhcnt = (f_pll - 128) / 256;
  469. if (rfhcnt > 15)
  470. rfhcnt = 15;
  471. } else {
  472. rfhcnt = (f_pll - 64) / 128;
  473. if (rfhcnt > 15)
  474. rfhcnt = 0;
  475. }
  476. minfo->hw.MXoptionReg = (minfo->hw.MXoptionReg & ~0x000F0000) | (rfhcnt << 16);
  477. pci_write_config_dword(minfo->pcidev, PCI_OPTION_REG, minfo->hw.MXoptionReg);
  478. /* output MCLK to MCLK pin */
  479. outTi3026(minfo, TVP3026_XMEMPLLCTRL, (mclk_ctl & 0xE7) | TVP3026_XMEMPLLCTRL_MCLK_MCLKPLL);
  480. outTi3026(minfo, TVP3026_XMEMPLLCTRL, (mclk_ctl ) | TVP3026_XMEMPLLCTRL_MCLK_MCLKPLL | TVP3026_XMEMPLLCTRL_STROBEMKC4);
  481. /* stop PCLK */
  482. outTi3026(minfo, TVP3026_XPLLADDR, 0xFE);
  483. outTi3026(minfo, TVP3026_XPIXPLLDATA, 0x00);
  484. /* restore pclk */
  485. outTi3026(minfo, TVP3026_XPLLADDR, 0xFC);
  486. outTi3026(minfo, TVP3026_XPIXPLLDATA, pclk_n);
  487. outTi3026(minfo, TVP3026_XPIXPLLDATA, pclk_m);
  488. outTi3026(minfo, TVP3026_XPIXPLLDATA, pclk_p);
  489. /* wait for PLL to lock */
  490. for (tmout = 500000; tmout; tmout--) {
  491. if (inTi3026(minfo, TVP3026_XPIXPLLDATA) & 0x40)
  492. break;
  493. udelay(10);
  494. }
  495. if (!tmout)
  496. printk(KERN_ERR "matroxfb: Pixel PLL not locked after 5 secs\n");
  497. }
  498. static void ti3026_ramdac_init(struct matrox_fb_info *minfo)
  499. {
  500. DBG(__func__)
  501. minfo->features.pll.vco_freq_min = 110000;
  502. minfo->features.pll.ref_freq = 114545;
  503. minfo->features.pll.feed_div_min = 2;
  504. minfo->features.pll.feed_div_max = 24;
  505. minfo->features.pll.in_div_min = 2;
  506. minfo->features.pll.in_div_max = 63;
  507. minfo->features.pll.post_shift_max = 3;
  508. if (minfo->devflags.noinit)
  509. return;
  510. ti3026_setMCLK(minfo, 60000);
  511. }
  512. static void Ti3026_restore(struct matrox_fb_info *minfo)
  513. {
  514. int i;
  515. unsigned char progdac[6];
  516. struct matrox_hw_state *hw = &minfo->hw;
  517. CRITFLAGS
  518. DBG(__func__)
  519. #ifdef DEBUG
  520. dprintk(KERN_INFO "EXTVGA regs: ");
  521. for (i = 0; i < 6; i++)
  522. dprintk("%02X:", hw->CRTCEXT[i]);
  523. dprintk("\n");
  524. #endif
  525. CRITBEGIN
  526. pci_write_config_dword(minfo->pcidev, PCI_OPTION_REG, hw->MXoptionReg);
  527. CRITEND
  528. matroxfb_vgaHWrestore(minfo);
  529. CRITBEGIN
  530. minfo->crtc1.panpos = -1;
  531. for (i = 0; i < 6; i++)
  532. mga_setr(M_EXTVGA_INDEX, i, hw->CRTCEXT[i]);
  533. for (i = 0; i < 21; i++) {
  534. outTi3026(minfo, DACseq[i], hw->DACreg[i]);
  535. }
  536. outTi3026(minfo, TVP3026_XPLLADDR, 0x00);
  537. progdac[0] = inTi3026(minfo, TVP3026_XPIXPLLDATA);
  538. progdac[3] = inTi3026(minfo, TVP3026_XLOOPPLLDATA);
  539. outTi3026(minfo, TVP3026_XPLLADDR, 0x15);
  540. progdac[1] = inTi3026(minfo, TVP3026_XPIXPLLDATA);
  541. progdac[4] = inTi3026(minfo, TVP3026_XLOOPPLLDATA);
  542. outTi3026(minfo, TVP3026_XPLLADDR, 0x2A);
  543. progdac[2] = inTi3026(minfo, TVP3026_XPIXPLLDATA);
  544. progdac[5] = inTi3026(minfo, TVP3026_XLOOPPLLDATA);
  545. CRITEND
  546. if (memcmp(hw->DACclk, progdac, 6)) {
  547. /* agrhh... setting up PLL is very slow on Millennium... */
  548. /* Mystique PLL is locked in few ms, but Millennium PLL lock takes about 0.15 s... */
  549. /* Maybe even we should call schedule() ? */
  550. CRITBEGIN
  551. outTi3026(minfo, TVP3026_XCLKCTRL, hw->DACreg[POS3026_XCLKCTRL]);
  552. outTi3026(minfo, TVP3026_XPLLADDR, 0x2A);
  553. outTi3026(minfo, TVP3026_XLOOPPLLDATA, 0);
  554. outTi3026(minfo, TVP3026_XPIXPLLDATA, 0);
  555. outTi3026(minfo, TVP3026_XPLLADDR, 0x00);
  556. for (i = 0; i < 3; i++)
  557. outTi3026(minfo, TVP3026_XPIXPLLDATA, hw->DACclk[i]);
  558. /* wait for PLL only if PLL clock requested (always for PowerMode, never for VGA) */
  559. if (hw->MiscOutReg & 0x08) {
  560. int tmout;
  561. outTi3026(minfo, TVP3026_XPLLADDR, 0x3F);
  562. for (tmout = 500000; tmout; --tmout) {
  563. if (inTi3026(minfo, TVP3026_XPIXPLLDATA) & 0x40)
  564. break;
  565. udelay(10);
  566. }
  567. CRITEND
  568. if (!tmout)
  569. printk(KERN_ERR "matroxfb: Pixel PLL not locked after 5 secs\n");
  570. else
  571. dprintk(KERN_INFO "PixelPLL: %d\n", 500000-tmout);
  572. CRITBEGIN
  573. }
  574. outTi3026(minfo, TVP3026_XMEMPLLCTRL, hw->DACreg[POS3026_XMEMPLLCTRL]);
  575. outTi3026(minfo, TVP3026_XPLLADDR, 0x00);
  576. for (i = 3; i < 6; i++)
  577. outTi3026(minfo, TVP3026_XLOOPPLLDATA, hw->DACclk[i]);
  578. CRITEND
  579. if ((hw->MiscOutReg & 0x08) && ((hw->DACclk[5] & 0x80) == 0x80)) {
  580. int tmout;
  581. CRITBEGIN
  582. outTi3026(minfo, TVP3026_XPLLADDR, 0x3F);
  583. for (tmout = 500000; tmout; --tmout) {
  584. if (inTi3026(minfo, TVP3026_XLOOPPLLDATA) & 0x40)
  585. break;
  586. udelay(10);
  587. }
  588. CRITEND
  589. if (!tmout)
  590. printk(KERN_ERR "matroxfb: Loop PLL not locked after 5 secs\n");
  591. else
  592. dprintk(KERN_INFO "LoopPLL: %d\n", 500000-tmout);
  593. }
  594. }
  595. #ifdef DEBUG
  596. dprintk(KERN_DEBUG "3026DACregs ");
  597. for (i = 0; i < 21; i++) {
  598. dprintk("R%02X=%02X ", DACseq[i], hw->DACreg[i]);
  599. if ((i & 0x7) == 0x7) dprintk(KERN_DEBUG "continuing... ");
  600. }
  601. dprintk(KERN_DEBUG "DACclk ");
  602. for (i = 0; i < 6; i++)
  603. dprintk("C%02X=%02X ", i, hw->DACclk[i]);
  604. dprintk("\n");
  605. #endif
  606. }
  607. static void Ti3026_reset(struct matrox_fb_info *minfo)
  608. {
  609. DBG(__func__)
  610. ti3026_ramdac_init(minfo);
  611. }
  612. static struct matrox_altout ti3026_output = {
  613. .name = "Primary output",
  614. };
  615. static int Ti3026_preinit(struct matrox_fb_info *minfo)
  616. {
  617. static const int vxres_mill2[] = { 512, 640, 768, 800, 832, 960,
  618. 1024, 1152, 1280, 1600, 1664, 1920,
  619. 2048, 0};
  620. static const int vxres_mill1[] = { 640, 768, 800, 960,
  621. 1024, 1152, 1280, 1600, 1920,
  622. 2048, 0};
  623. struct matrox_hw_state *hw = &minfo->hw;
  624. DBG(__func__)
  625. minfo->millenium = 1;
  626. minfo->milleniumII = (minfo->pcidev->device != PCI_DEVICE_ID_MATROX_MIL);
  627. minfo->capable.cfb4 = 1;
  628. minfo->capable.text = 1; /* isMilleniumII(minfo); */
  629. minfo->capable.vxres = isMilleniumII(minfo) ? vxres_mill2 : vxres_mill1;
  630. minfo->outputs[0].data = minfo;
  631. minfo->outputs[0].output = &ti3026_output;
  632. minfo->outputs[0].src = minfo->outputs[0].default_src;
  633. minfo->outputs[0].mode = MATROXFB_OUTPUT_MODE_MONITOR;
  634. if (minfo->devflags.noinit)
  635. return 0;
  636. /* preserve VGA I/O, BIOS and PPC */
  637. hw->MXoptionReg &= 0xC0000100;
  638. hw->MXoptionReg |= 0x002C0000;
  639. if (minfo->devflags.novga)
  640. hw->MXoptionReg &= ~0x00000100;
  641. if (minfo->devflags.nobios)
  642. hw->MXoptionReg &= ~0x40000000;
  643. if (minfo->devflags.nopciretry)
  644. hw->MXoptionReg |= 0x20000000;
  645. pci_write_config_dword(minfo->pcidev, PCI_OPTION_REG, hw->MXoptionReg);
  646. minfo->accel.ramdac_rev = inTi3026(minfo, TVP3026_XSILICONREV);
  647. outTi3026(minfo, TVP3026_XCLKCTRL, TVP3026_XCLKCTRL_SRC_CLK0VGA | TVP3026_XCLKCTRL_CLKSTOPPED);
  648. outTi3026(minfo, TVP3026_XTRUECOLORCTRL, TVP3026_XTRUECOLORCTRL_PSEUDOCOLOR);
  649. outTi3026(minfo, TVP3026_XMUXCTRL, TVP3026_XMUXCTRL_VGA);
  650. outTi3026(minfo, TVP3026_XPLLADDR, 0x2A);
  651. outTi3026(minfo, TVP3026_XLOOPPLLDATA, 0x00);
  652. outTi3026(minfo, TVP3026_XPIXPLLDATA, 0x00);
  653. mga_outb(M_MISC_REG, 0x67);
  654. outTi3026(minfo, TVP3026_XMEMPLLCTRL, TVP3026_XMEMPLLCTRL_STROBEMKC4 | TVP3026_XMEMPLLCTRL_MCLK_MCLKPLL);
  655. mga_outl(M_RESET, 1);
  656. udelay(250);
  657. mga_outl(M_RESET, 0);
  658. udelay(250);
  659. mga_outl(M_MACCESS, 0x00008000);
  660. udelay(10);
  661. return 0;
  662. }
  663. struct matrox_switch matrox_millennium = {
  664. Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
  665. };
  666. EXPORT_SYMBOL(matrox_millennium);
  667. #endif
  668. MODULE_LICENSE("GPL");