mach64_ct.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. /*
  2. * ATI Mach64 CT/VT/GT/LT Support
  3. */
  4. #include <linux/fb.h>
  5. #include <linux/delay.h>
  6. #include <asm/io.h>
  7. #include <video/mach64.h>
  8. #include "atyfb.h"
  9. #undef DEBUG
  10. static int aty_valid_pll_ct (const struct fb_info *info, u32 vclk_per, struct pll_ct *pll);
  11. static int aty_dsp_gt (const struct fb_info *info, u32 bpp, struct pll_ct *pll);
  12. static int aty_var_to_pll_ct(const struct fb_info *info, u32 vclk_per, u32 bpp, union aty_pll *pll);
  13. static u32 aty_pll_to_var_ct(const struct fb_info *info, const union aty_pll *pll);
  14. u8 aty_ld_pll_ct(int offset, const struct atyfb_par *par)
  15. {
  16. u8 res;
  17. /* write addr byte */
  18. aty_st_8(CLOCK_CNTL_ADDR, (offset << 2) & PLL_ADDR, par);
  19. /* read the register value */
  20. res = aty_ld_8(CLOCK_CNTL_DATA, par);
  21. return res;
  22. }
  23. void aty_st_pll_ct(int offset, u8 val, const struct atyfb_par *par)
  24. {
  25. /* write addr byte */
  26. aty_st_8(CLOCK_CNTL_ADDR, ((offset << 2) & PLL_ADDR) | PLL_WR_EN, par);
  27. /* write the register value */
  28. aty_st_8(CLOCK_CNTL_DATA, val & PLL_DATA, par);
  29. aty_st_8(CLOCK_CNTL_ADDR, ((offset << 2) & PLL_ADDR) & ~PLL_WR_EN, par);
  30. }
  31. /*
  32. * by Daniel Mantione
  33. * <daniel.mantione@freepascal.org>
  34. *
  35. *
  36. * ATI Mach64 CT clock synthesis description.
  37. *
  38. * All clocks on the Mach64 can be calculated using the same principle:
  39. *
  40. * XTALIN * x * FB_DIV
  41. * CLK = ----------------------
  42. * PLL_REF_DIV * POST_DIV
  43. *
  44. * XTALIN is a fixed speed clock. Common speeds are 14.31 MHz and 29.50 MHz.
  45. * PLL_REF_DIV can be set by the user, but is the same for all clocks.
  46. * FB_DIV can be set by the user for each clock individually, it should be set
  47. * between 128 and 255, the chip will generate a bad clock signal for too low
  48. * values.
  49. * x depends on the type of clock; usually it is 2, but for the MCLK it can also
  50. * be set to 4.
  51. * POST_DIV can be set by the user for each clock individually, Possible values
  52. * are 1,2,4,8 and for some clocks other values are available too.
  53. * CLK is of course the clock speed that is generated.
  54. *
  55. * The Mach64 has these clocks:
  56. *
  57. * MCLK The clock rate of the chip
  58. * XCLK The clock rate of the on-chip memory
  59. * VCLK0 First pixel clock of first CRT controller
  60. * VCLK1 Second pixel clock of first CRT controller
  61. * VCLK2 Third pixel clock of first CRT controller
  62. * VCLK3 Fourth pixel clock of first CRT controller
  63. * VCLK Selected pixel clock, one of VCLK0, VCLK1, VCLK2, VCLK3
  64. * V2CLK Pixel clock of the second CRT controller.
  65. * SCLK Multi-purpose clock
  66. *
  67. * - MCLK and XCLK use the same FB_DIV
  68. * - VCLK0 .. VCLK3 use the same FB_DIV
  69. * - V2CLK is needed when the second CRTC is used (can be used for dualhead);
  70. * i.e. CRT monitor connected to laptop has different resolution than built
  71. * in LCD monitor.
  72. * - SCLK is not available on all cards; it is know to exist on the Rage LT-PRO,
  73. * Rage XL and Rage Mobility. It is know not to exist on the Mach64 VT.
  74. * - V2CLK is not available on all cards, most likely only the Rage LT-PRO,
  75. * the Rage XL and the Rage Mobility
  76. *
  77. * SCLK can be used to:
  78. * - Clock the chip instead of MCLK
  79. * - Replace XTALIN with a user defined frequency
  80. * - Generate the pixel clock for the LCD monitor (instead of VCLK)
  81. */
  82. /*
  83. * It can be quite hard to calculate XCLK and MCLK if they don't run at the
  84. * same frequency. Luckily, until now all cards that need asynchrone clock
  85. * speeds seem to have SCLK.
  86. * So this driver uses SCLK to clock the chip and XCLK to clock the memory.
  87. */
  88. /* ------------------------------------------------------------------------- */
  89. /*
  90. * PLL programming (Mach64 CT family)
  91. *
  92. *
  93. * This procedure sets the display fifo. The display fifo is a buffer that
  94. * contains data read from the video memory that waits to be processed by
  95. * the CRT controller.
  96. *
  97. * On the more modern Mach64 variants, the chip doesn't calculate the
  98. * interval after which the display fifo has to be reloaded from memory
  99. * automatically, the driver has to do it instead.
  100. */
  101. #define Maximum_DSP_PRECISION 7
  102. static u8 postdividers[] = {1,2,4,8,3};
  103. static int aty_dsp_gt(const struct fb_info *info, u32 bpp, struct pll_ct *pll)
  104. {
  105. u32 dsp_off, dsp_on, dsp_xclks;
  106. u32 multiplier, divider, ras_multiplier, ras_divider, tmp;
  107. u8 vshift, xshift;
  108. s8 dsp_precision;
  109. multiplier = ((u32)pll->mclk_fb_div) * pll->vclk_post_div_real;
  110. divider = ((u32)pll->vclk_fb_div) * pll->xclk_ref_div;
  111. ras_multiplier = pll->xclkmaxrasdelay;
  112. ras_divider = 1;
  113. if (bpp>=8)
  114. divider = divider * (bpp >> 2);
  115. vshift = (6 - 2) - pll->xclk_post_div; /* FIFO is 64 bits wide in accelerator mode ... */
  116. if (bpp == 0)
  117. vshift--; /* ... but only 32 bits in VGA mode. */
  118. #ifdef CONFIG_FB_ATY_GENERIC_LCD
  119. if (pll->xres != 0) {
  120. struct atyfb_par *par = (struct atyfb_par *) info->par;
  121. multiplier = multiplier * par->lcd_width;
  122. divider = divider * pll->xres & ~7;
  123. ras_multiplier = ras_multiplier * par->lcd_width;
  124. ras_divider = ras_divider * pll->xres & ~7;
  125. }
  126. #endif
  127. /* If we don't do this, 32 bits for multiplier & divider won't be
  128. enough in certain situations! */
  129. while (((multiplier | divider) & 1) == 0) {
  130. multiplier = multiplier >> 1;
  131. divider = divider >> 1;
  132. }
  133. /* Determine DSP precision first */
  134. tmp = ((multiplier * pll->fifo_size) << vshift) / divider;
  135. for (dsp_precision = -5; tmp; dsp_precision++)
  136. tmp >>= 1;
  137. if (dsp_precision < 0)
  138. dsp_precision = 0;
  139. else if (dsp_precision > Maximum_DSP_PRECISION)
  140. dsp_precision = Maximum_DSP_PRECISION;
  141. xshift = 6 - dsp_precision;
  142. vshift += xshift;
  143. /* Move on to dsp_off */
  144. dsp_off = ((multiplier * (pll->fifo_size - 1)) << vshift) / divider -
  145. (1 << (vshift - xshift));
  146. /* if (bpp == 0)
  147. dsp_on = ((multiplier * 20 << vshift) + divider) / divider;
  148. else */
  149. {
  150. dsp_on = ((multiplier << vshift) + divider) / divider;
  151. tmp = ((ras_multiplier << xshift) + ras_divider) / ras_divider;
  152. if (dsp_on < tmp)
  153. dsp_on = tmp;
  154. dsp_on = dsp_on + (tmp * 2) + (pll->xclkpagefaultdelay << xshift);
  155. }
  156. /* Calculate rounding factor and apply it to dsp_on */
  157. tmp = ((1 << (Maximum_DSP_PRECISION - dsp_precision)) - 1) >> 1;
  158. dsp_on = ((dsp_on + tmp) / (tmp + 1)) * (tmp + 1);
  159. if (dsp_on >= ((dsp_off / (tmp + 1)) * (tmp + 1))) {
  160. dsp_on = dsp_off - (multiplier << vshift) / divider;
  161. dsp_on = (dsp_on / (tmp + 1)) * (tmp + 1);
  162. }
  163. /* Last but not least: dsp_xclks */
  164. dsp_xclks = ((multiplier << (vshift + 5)) + divider) / divider;
  165. /* Get register values. */
  166. pll->dsp_on_off = (dsp_on << 16) + dsp_off;
  167. pll->dsp_config = (dsp_precision << 20) | (pll->dsp_loop_latency << 16) | dsp_xclks;
  168. #ifdef DEBUG
  169. printk("atyfb(%s): dsp_config 0x%08x, dsp_on_off 0x%08x\n",
  170. __FUNCTION__, pll->dsp_config, pll->dsp_on_off);
  171. #endif
  172. return 0;
  173. }
  174. static int aty_valid_pll_ct(const struct fb_info *info, u32 vclk_per, struct pll_ct *pll)
  175. {
  176. u32 q;
  177. struct atyfb_par *par = (struct atyfb_par *) info->par;
  178. #ifdef DEBUG
  179. int pllvclk;
  180. #endif
  181. /* FIXME: use the VTB/GTB /{3,6,12} post dividers if they're better suited */
  182. q = par->ref_clk_per * pll->pll_ref_div * 4 / vclk_per;
  183. if (q < 16*8 || q > 255*8) {
  184. printk(KERN_CRIT "atyfb: vclk out of range\n");
  185. return -EINVAL;
  186. } else {
  187. pll->vclk_post_div = (q < 128*8);
  188. pll->vclk_post_div += (q < 64*8);
  189. pll->vclk_post_div += (q < 32*8);
  190. }
  191. pll->vclk_post_div_real = postdividers[pll->vclk_post_div];
  192. // pll->vclk_post_div <<= 6;
  193. pll->vclk_fb_div = q * pll->vclk_post_div_real / 8;
  194. #ifdef DEBUG
  195. pllvclk = (1000000 * 2 * pll->vclk_fb_div) /
  196. (par->ref_clk_per * pll->pll_ref_div);
  197. printk("atyfb(%s): pllvclk=%d MHz, vclk=%d MHz\n",
  198. __FUNCTION__, pllvclk, pllvclk / pll->vclk_post_div_real);
  199. #endif
  200. pll->pll_vclk_cntl = 0x03; /* VCLK = PLL_VCLK/VCLKx_POST */
  201. return 0;
  202. }
  203. static int aty_var_to_pll_ct(const struct fb_info *info, u32 vclk_per, u32 bpp, union aty_pll *pll)
  204. {
  205. struct atyfb_par *par = (struct atyfb_par *) info->par;
  206. int err;
  207. if ((err = aty_valid_pll_ct(info, vclk_per, &pll->ct)))
  208. return err;
  209. if (M64_HAS(GTB_DSP) && (err = aty_dsp_gt(info, bpp, &pll->ct)))
  210. return err;
  211. /*aty_calc_pll_ct(info, &pll->ct);*/
  212. return 0;
  213. }
  214. static u32 aty_pll_to_var_ct(const struct fb_info *info, const union aty_pll *pll)
  215. {
  216. struct atyfb_par *par = (struct atyfb_par *) info->par;
  217. u32 ret;
  218. ret = par->ref_clk_per * pll->ct.pll_ref_div * pll->ct.vclk_post_div_real / pll->ct.vclk_fb_div / 2;
  219. #ifdef CONFIG_FB_ATY_GENERIC_LCD
  220. if(pll->ct.xres > 0) {
  221. ret *= par->lcd_width;
  222. ret /= pll->ct.xres;
  223. }
  224. #endif
  225. #ifdef DEBUG
  226. printk("atyfb(%s): calculated 0x%08X(%i)\n", __FUNCTION__, ret, ret);
  227. #endif
  228. return ret;
  229. }
  230. void aty_set_pll_ct(const struct fb_info *info, const union aty_pll *pll)
  231. {
  232. struct atyfb_par *par = (struct atyfb_par *) info->par;
  233. u32 crtc_gen_cntl, lcd_gen_cntrl;
  234. u8 tmp, tmp2;
  235. lcd_gen_cntrl = 0;
  236. #ifdef DEBUG
  237. printk("atyfb(%s): about to program:\n"
  238. "pll_ext_cntl=0x%02x pll_gen_cntl=0x%02x pll_vclk_cntl=0x%02x\n",
  239. __FUNCTION__,
  240. pll->ct.pll_ext_cntl, pll->ct.pll_gen_cntl, pll->ct.pll_vclk_cntl);
  241. printk("atyfb(%s): setting clock %lu for FeedBackDivider %i, ReferenceDivider %i, PostDivider %i(%i)\n",
  242. __FUNCTION__,
  243. par->clk_wr_offset, pll->ct.vclk_fb_div,
  244. pll->ct.pll_ref_div, pll->ct.vclk_post_div, pll->ct.vclk_post_div_real);
  245. #endif
  246. #ifdef CONFIG_FB_ATY_GENERIC_LCD
  247. if (par->lcd_table != 0) {
  248. /* turn off LCD */
  249. lcd_gen_cntrl = aty_ld_lcd(LCD_GEN_CNTL, par);
  250. aty_st_lcd(LCD_GEN_CNTL, lcd_gen_cntrl & ~LCD_ON, par);
  251. }
  252. #endif
  253. aty_st_8(CLOCK_CNTL, par->clk_wr_offset | CLOCK_STROBE, par);
  254. /* Temporarily switch to accelerator mode */
  255. crtc_gen_cntl = aty_ld_le32(CRTC_GEN_CNTL, par);
  256. if (!(crtc_gen_cntl & CRTC_EXT_DISP_EN))
  257. aty_st_le32(CRTC_GEN_CNTL, crtc_gen_cntl | CRTC_EXT_DISP_EN, par);
  258. /* Reset VCLK generator */
  259. aty_st_pll_ct(PLL_VCLK_CNTL, pll->ct.pll_vclk_cntl, par);
  260. /* Set post-divider */
  261. tmp2 = par->clk_wr_offset << 1;
  262. tmp = aty_ld_pll_ct(VCLK_POST_DIV, par);
  263. tmp &= ~(0x03U << tmp2);
  264. tmp |= ((pll->ct.vclk_post_div & 0x03U) << tmp2);
  265. aty_st_pll_ct(VCLK_POST_DIV, tmp, par);
  266. /* Set extended post-divider */
  267. tmp = aty_ld_pll_ct(PLL_EXT_CNTL, par);
  268. tmp &= ~(0x10U << par->clk_wr_offset);
  269. tmp &= 0xF0U;
  270. tmp |= pll->ct.pll_ext_cntl;
  271. aty_st_pll_ct(PLL_EXT_CNTL, tmp, par);
  272. /* Set feedback divider */
  273. tmp = VCLK0_FB_DIV + par->clk_wr_offset;
  274. aty_st_pll_ct(tmp, (pll->ct.vclk_fb_div & 0xFFU), par);
  275. aty_st_pll_ct(PLL_GEN_CNTL, (pll->ct.pll_gen_cntl & (~(PLL_OVERRIDE | PLL_MCLK_RST))) | OSC_EN, par);
  276. /* End VCLK generator reset */
  277. aty_st_pll_ct(PLL_VCLK_CNTL, pll->ct.pll_vclk_cntl & ~(PLL_VCLK_RST), par);
  278. mdelay(5);
  279. aty_st_pll_ct(PLL_GEN_CNTL, pll->ct.pll_gen_cntl, par);
  280. aty_st_pll_ct(PLL_VCLK_CNTL, pll->ct.pll_vclk_cntl, par);
  281. mdelay(1);
  282. /* Restore mode register */
  283. if (!(crtc_gen_cntl & CRTC_EXT_DISP_EN))
  284. aty_st_le32(CRTC_GEN_CNTL, crtc_gen_cntl, par);
  285. if (M64_HAS(GTB_DSP)) {
  286. u8 dll_cntl;
  287. if (M64_HAS(XL_DLL))
  288. dll_cntl = 0x80;
  289. else if (par->ram_type >= SDRAM)
  290. dll_cntl = 0xa6;
  291. else
  292. dll_cntl = 0xa0;
  293. aty_st_pll_ct(DLL_CNTL, dll_cntl, par);
  294. aty_st_pll_ct(VFC_CNTL, 0x1b, par);
  295. aty_st_le32(DSP_CONFIG, pll->ct.dsp_config, par);
  296. aty_st_le32(DSP_ON_OFF, pll->ct.dsp_on_off, par);
  297. mdelay(10);
  298. aty_st_pll_ct(DLL_CNTL, dll_cntl, par);
  299. mdelay(10);
  300. aty_st_pll_ct(DLL_CNTL, dll_cntl | 0x40, par);
  301. mdelay(10);
  302. aty_st_pll_ct(DLL_CNTL, dll_cntl & ~0x40, par);
  303. }
  304. #ifdef CONFIG_FB_ATY_GENERIC_LCD
  305. if (par->lcd_table != 0) {
  306. /* restore LCD */
  307. aty_st_lcd(LCD_GEN_CNTL, lcd_gen_cntrl, par);
  308. }
  309. #endif
  310. }
  311. static void __init aty_get_pll_ct(const struct fb_info *info,
  312. union aty_pll *pll)
  313. {
  314. struct atyfb_par *par = (struct atyfb_par *) info->par;
  315. u8 tmp, clock;
  316. clock = aty_ld_8(CLOCK_CNTL, par) & 0x03U;
  317. tmp = clock << 1;
  318. pll->ct.vclk_post_div = (aty_ld_pll_ct(VCLK_POST_DIV, par) >> tmp) & 0x03U;
  319. pll->ct.pll_ext_cntl = aty_ld_pll_ct(PLL_EXT_CNTL, par) & 0x0FU;
  320. pll->ct.vclk_fb_div = aty_ld_pll_ct(VCLK0_FB_DIV + clock, par) & 0xFFU;
  321. pll->ct.pll_ref_div = aty_ld_pll_ct(PLL_REF_DIV, par);
  322. pll->ct.mclk_fb_div = aty_ld_pll_ct(MCLK_FB_DIV, par);
  323. pll->ct.pll_gen_cntl = aty_ld_pll_ct(PLL_GEN_CNTL, par);
  324. pll->ct.pll_vclk_cntl = aty_ld_pll_ct(PLL_VCLK_CNTL, par);
  325. if (M64_HAS(GTB_DSP)) {
  326. pll->ct.dsp_config = aty_ld_le32(DSP_CONFIG, par);
  327. pll->ct.dsp_on_off = aty_ld_le32(DSP_ON_OFF, par);
  328. }
  329. }
  330. static int __init aty_init_pll_ct(const struct fb_info *info,
  331. union aty_pll *pll)
  332. {
  333. struct atyfb_par *par = (struct atyfb_par *) info->par;
  334. u8 mpost_div, xpost_div, sclk_post_div_real, sclk_fb_div, spll_cntl2;
  335. u32 q, i, memcntl, trp;
  336. u32 dsp_config, dsp_on_off, vga_dsp_config, vga_dsp_on_off;
  337. #ifdef DEBUG
  338. int pllmclk, pllsclk;
  339. #endif
  340. pll->ct.pll_ext_cntl = aty_ld_pll_ct(PLL_EXT_CNTL, par);
  341. pll->ct.xclk_post_div = pll->ct.pll_ext_cntl & 0x07;
  342. pll->ct.xclk_ref_div = 1;
  343. switch (pll->ct.xclk_post_div) {
  344. case 0: case 1: case 2: case 3:
  345. break;
  346. case 4:
  347. pll->ct.xclk_ref_div = 3;
  348. pll->ct.xclk_post_div = 0;
  349. break;
  350. default:
  351. printk(KERN_CRIT "atyfb: Unsupported xclk source: %d.\n", pll->ct.xclk_post_div);
  352. return -EINVAL;
  353. }
  354. pll->ct.mclk_fb_mult = 2;
  355. if(pll->ct.pll_ext_cntl & PLL_MFB_TIMES_4_2B) {
  356. pll->ct.mclk_fb_mult = 4;
  357. pll->ct.xclk_post_div -= 1;
  358. }
  359. #ifdef DEBUG
  360. printk("atyfb(%s): mclk_fb_mult=%d, xclk_post_div=%d\n",
  361. __FUNCTION__, pll->ct.mclk_fb_mult, pll->ct.xclk_post_div);
  362. #endif
  363. memcntl = aty_ld_le32(MEM_CNTL, par);
  364. trp = (memcntl & 0x300) >> 8;
  365. pll->ct.xclkpagefaultdelay = ((memcntl & 0xc00) >> 10) + ((memcntl & 0x1000) >> 12) + trp + 2;
  366. pll->ct.xclkmaxrasdelay = ((memcntl & 0x70000) >> 16) + trp + 2;
  367. if (M64_HAS(FIFO_32)) {
  368. pll->ct.fifo_size = 32;
  369. } else {
  370. pll->ct.fifo_size = 24;
  371. pll->ct.xclkpagefaultdelay += 2;
  372. pll->ct.xclkmaxrasdelay += 3;
  373. }
  374. switch (par->ram_type) {
  375. case DRAM:
  376. if (info->fix.smem_len<=ONE_MB) {
  377. pll->ct.dsp_loop_latency = 10;
  378. } else {
  379. pll->ct.dsp_loop_latency = 8;
  380. pll->ct.xclkpagefaultdelay += 2;
  381. }
  382. break;
  383. case EDO:
  384. case PSEUDO_EDO:
  385. if (info->fix.smem_len<=ONE_MB) {
  386. pll->ct.dsp_loop_latency = 9;
  387. } else {
  388. pll->ct.dsp_loop_latency = 8;
  389. pll->ct.xclkpagefaultdelay += 1;
  390. }
  391. break;
  392. case SDRAM:
  393. if (info->fix.smem_len<=ONE_MB) {
  394. pll->ct.dsp_loop_latency = 11;
  395. } else {
  396. pll->ct.dsp_loop_latency = 10;
  397. pll->ct.xclkpagefaultdelay += 1;
  398. }
  399. break;
  400. case SGRAM:
  401. pll->ct.dsp_loop_latency = 8;
  402. pll->ct.xclkpagefaultdelay += 3;
  403. break;
  404. default:
  405. pll->ct.dsp_loop_latency = 11;
  406. pll->ct.xclkpagefaultdelay += 3;
  407. break;
  408. }
  409. if (pll->ct.xclkmaxrasdelay <= pll->ct.xclkpagefaultdelay)
  410. pll->ct.xclkmaxrasdelay = pll->ct.xclkpagefaultdelay + 1;
  411. /* Allow BIOS to override */
  412. dsp_config = aty_ld_le32(DSP_CONFIG, par);
  413. dsp_on_off = aty_ld_le32(DSP_ON_OFF, par);
  414. vga_dsp_config = aty_ld_le32(VGA_DSP_CONFIG, par);
  415. vga_dsp_on_off = aty_ld_le32(VGA_DSP_ON_OFF, par);
  416. if (dsp_config)
  417. pll->ct.dsp_loop_latency = (dsp_config & DSP_LOOP_LATENCY) >> 16;
  418. #if 0
  419. FIXME: is it relevant for us?
  420. if ((!dsp_on_off && !M64_HAS(RESET_3D)) ||
  421. ((dsp_on_off == vga_dsp_on_off) &&
  422. (!dsp_config || !((dsp_config ^ vga_dsp_config) & DSP_XCLKS_PER_QW)))) {
  423. vga_dsp_on_off &= VGA_DSP_OFF;
  424. vga_dsp_config &= VGA_DSP_XCLKS_PER_QW;
  425. if (ATIDivide(vga_dsp_on_off, vga_dsp_config, 5, 1) > 24)
  426. pll->ct.fifo_size = 32;
  427. else
  428. pll->ct.fifo_size = 24;
  429. }
  430. #endif
  431. /* Exit if the user does not want us to tamper with the clock
  432. rates of her chip. */
  433. if (par->mclk_per == 0) {
  434. u8 mclk_fb_div, pll_ext_cntl;
  435. pll->ct.pll_ref_div = aty_ld_pll_ct(PLL_REF_DIV, par);
  436. pll_ext_cntl = aty_ld_pll_ct(PLL_EXT_CNTL, par);
  437. pll->ct.xclk_post_div_real = postdividers[pll_ext_cntl & 0x07];
  438. mclk_fb_div = aty_ld_pll_ct(MCLK_FB_DIV, par);
  439. if (pll_ext_cntl & PLL_MFB_TIMES_4_2B)
  440. mclk_fb_div <<= 1;
  441. pll->ct.mclk_fb_div = mclk_fb_div;
  442. return 0;
  443. }
  444. pll->ct.pll_ref_div = par->pll_per * 2 * 255 / par->ref_clk_per;
  445. /* FIXME: use the VTB/GTB /3 post divider if it's better suited */
  446. q = par->ref_clk_per * pll->ct.pll_ref_div * 8 /
  447. (pll->ct.mclk_fb_mult * par->xclk_per);
  448. if (q < 16*8 || q > 255*8) {
  449. printk(KERN_CRIT "atxfb: xclk out of range\n");
  450. return -EINVAL;
  451. } else {
  452. xpost_div = (q < 128*8);
  453. xpost_div += (q < 64*8);
  454. xpost_div += (q < 32*8);
  455. }
  456. pll->ct.xclk_post_div_real = postdividers[xpost_div];
  457. pll->ct.mclk_fb_div = q * pll->ct.xclk_post_div_real / 8;
  458. #ifdef DEBUG
  459. pllmclk = (1000000 * pll->ct.mclk_fb_mult * pll->ct.mclk_fb_div) /
  460. (par->ref_clk_per * pll->ct.pll_ref_div);
  461. printk("atyfb(%s): pllmclk=%d MHz, xclk=%d MHz\n",
  462. __FUNCTION__, pllmclk, pllmclk / pll->ct.xclk_post_div_real);
  463. #endif
  464. if (M64_HAS(SDRAM_MAGIC_PLL) && (par->ram_type >= SDRAM))
  465. pll->ct.pll_gen_cntl = OSC_EN;
  466. else
  467. pll->ct.pll_gen_cntl = OSC_EN | DLL_PWDN /* | FORCE_DCLK_TRI_STATE */;
  468. if (M64_HAS(MAGIC_POSTDIV))
  469. pll->ct.pll_ext_cntl = 0;
  470. else
  471. pll->ct.pll_ext_cntl = xpost_div;
  472. if (pll->ct.mclk_fb_mult == 4)
  473. pll->ct.pll_ext_cntl |= PLL_MFB_TIMES_4_2B;
  474. if (par->mclk_per == par->xclk_per) {
  475. pll->ct.pll_gen_cntl |= (xpost_div << 4); /* mclk == xclk */
  476. } else {
  477. /*
  478. * The chip clock is not equal to the memory clock.
  479. * Therefore we will use sclk to clock the chip.
  480. */
  481. pll->ct.pll_gen_cntl |= (6 << 4); /* mclk == sclk */
  482. q = par->ref_clk_per * pll->ct.pll_ref_div * 4 / par->mclk_per;
  483. if (q < 16*8 || q > 255*8) {
  484. printk(KERN_CRIT "atyfb: mclk out of range\n");
  485. return -EINVAL;
  486. } else {
  487. mpost_div = (q < 128*8);
  488. mpost_div += (q < 64*8);
  489. mpost_div += (q < 32*8);
  490. }
  491. sclk_post_div_real = postdividers[mpost_div];
  492. sclk_fb_div = q * sclk_post_div_real / 8;
  493. spll_cntl2 = mpost_div << 4;
  494. #ifdef DEBUG
  495. pllsclk = (1000000 * 2 * sclk_fb_div) /
  496. (par->ref_clk_per * pll->ct.pll_ref_div);
  497. printk("atyfb(%s): use sclk, pllsclk=%d MHz, sclk=mclk=%d MHz\n",
  498. __FUNCTION__, pllsclk, pllsclk / sclk_post_div_real);
  499. #endif
  500. /*
  501. * This disables the sclk, crashes the computer as reported:
  502. * aty_st_pll_ct(SPLL_CNTL2, 3, info);
  503. *
  504. * So it seems the sclk must be enabled before it is used;
  505. * so PLL_GEN_CNTL must be programmed *after* the sclk.
  506. */
  507. aty_st_pll_ct(SCLK_FB_DIV, sclk_fb_div, par);
  508. aty_st_pll_ct(SPLL_CNTL2, spll_cntl2, par);
  509. /*
  510. * The sclk has been started. However, I believe the first clock
  511. * ticks it generates are not very stable. Hope this primitive loop
  512. * helps for Rage Mobilities that sometimes crash when
  513. * we switch to sclk. (Daniel Mantione, 13-05-2003)
  514. */
  515. for (i=0;i<=0x1ffff;i++);
  516. }
  517. aty_st_pll_ct(PLL_REF_DIV, pll->ct.pll_ref_div, par);
  518. aty_st_pll_ct(PLL_GEN_CNTL, pll->ct.pll_gen_cntl, par);
  519. aty_st_pll_ct(MCLK_FB_DIV, pll->ct.mclk_fb_div, par);
  520. aty_st_pll_ct(PLL_EXT_CNTL, pll->ct.pll_ext_cntl, par);
  521. /* Disable the extra precision pixel clock controls since we do not use them. */
  522. aty_st_pll_ct(EXT_VPLL_CNTL, aty_ld_pll_ct(EXT_VPLL_CNTL, par) &
  523. ~(EXT_VPLL_EN | EXT_VPLL_VGA_EN | EXT_VPLL_INSYNC), par);
  524. return 0;
  525. }
  526. static int dummy(void)
  527. {
  528. return 0;
  529. }
  530. const struct aty_dac_ops aty_dac_ct = {
  531. .set_dac = (void *) dummy,
  532. };
  533. const struct aty_pll_ops aty_pll_ct = {
  534. .var_to_pll = aty_var_to_pll_ct,
  535. .pll_to_var = aty_pll_to_var_ct,
  536. .set_pll = aty_set_pll_ct,
  537. .get_pll = aty_get_pll_ct,
  538. .init_pll = aty_init_pll_ct
  539. };