3 /* FIXME: remove the FAIL definition */
4 #define FAIL(x) do { printk_spew(x); return -EINVAL; } while (0)
6 static int aty_valid_pll_ct(const struct fb_info_aty *info, u32 vclk_per,
8 static int aty_dsp_gt(const struct fb_info_aty *info, u32 bpp,
10 static int aty_var_to_pll_ct(const struct fb_info_aty *info, u32 vclk_per,
11 u8 bpp, union aty_pll *pll);
13 static u32 aty_pll_ct_to_var(const struct fb_info_aty *info,
14 const union aty_pll *pll);
17 /* ------------------------------------------------------------------------- */
20 * PLL programming (Mach64 CT family)
22 static int aty_dsp_gt(const struct fb_info_aty *info, u32 bpp,
25 u32 dsp_xclks_per_row, dsp_loop_latency, dsp_precision, dsp_off, dsp_on;
26 u32 xclks_per_row, fifo_off, fifo_on, y, fifo_size;
27 u32 memcntl, n, t_pfc, t_rp, t_ras, t_rcd, t_crd, t_rcc, t_lat;
30 printk_debug("aty_dsp_gt : mclk_fb_mult=%d\n", pll->mclk_fb_mult);
33 /* (64*xclk/vclk/bpp)<<11 = xclocks_per_row<<11 */
34 xclks_per_row = ((u32)pll->mclk_fb_mult * (u32)pll->mclk_fb_div *
35 (u32)pll->vclk_post_div_real * 64) << 11;
37 (2 * (u32)pll->vclk_fb_div * (u32)pll->xclk_post_div_real * bpp);
39 if (xclks_per_row < (1<<11))
40 FAIL("Dotclock too high");
41 if (M64_HAS(FIFO_24)) {
49 y = (xclks_per_row*fifo_size)>>11;
57 fifo_off = ((xclks_per_row*(fifo_size-1))>>5); // + (3<<6);
59 if (info->total_vram > 1*1024*1024) {
60 switch (info->ram_type) {
63 dsp_loop_latency += 9;
69 dsp_loop_latency += 8;
74 dsp_loop_latency += 6;
79 if (info->ram_type >= SDRAM) {
81 dsp_loop_latency += 9;
85 dsp_loop_latency += 8;
90 memcntl = aty_ld_le32(MEM_CNTL, info);
91 t_rcd = ((memcntl >> 10) & 0x03) + 1;
92 t_crd = ((memcntl >> 12) & 0x01);
93 t_rp = ((memcntl >> 8) & 0x03) + 1;
94 t_ras = ((memcntl >> 16) & 0x07) + 1;
95 t_lat = (memcntl >> 4) & 0x03;
97 t_pfc = t_rp + t_rcd + t_crd;
99 t_rcc = max(t_rp + t_ras, t_pfc + n);
102 fifo_on = (2 * t_rcc + t_pfc + n - 1) << 6;
104 dsp_xclks_per_row = xclks_per_row>>dsp_precision;
105 dsp_on = fifo_on>>dsp_precision;
106 dsp_off = fifo_off>>dsp_precision;
108 pll->dsp_config = (dsp_xclks_per_row & 0x3fff) |
109 ((dsp_loop_latency & 0xf)<<16) |
110 ((dsp_precision & 7)<<20);
111 pll->dsp_on_off = (dsp_off & 0x7ff) | ((dsp_on & 0x7ff)<<16);
116 static int aty_valid_pll_ct(const struct fb_info_aty *info, u32 vclk_per,
120 int pllmclk, pllsclk;
123 u32 q, x; /* x is a workaround for sparc64-linux-gcc */
124 x = x; /* x is a workaround for sparc64-linux-gcc */
126 pll->pll_ref_div = info->pll_per*2*255/info->ref_clk_per;
128 /* FIXME: use the VTB/GTB /3 post divider if it's better suited */
131 q = info->ref_clk_per*pll->pll_ref_div*4/info->mclk_per;
133 if (q < 16*8 || q > 255*8)
134 FAIL("mclk out of range\n");
136 pll->mclk_post_div_real = 8;
138 pll->mclk_post_div_real = 4;
140 pll->mclk_post_div_real = 2;
142 pll->mclk_post_div_real = 1;
143 pll->sclk_fb_div = q*pll->mclk_post_div_real/8;
146 pllsclk = (1000000 * 2 * pll->sclk_fb_div) /
147 (info->ref_clk_per * pll->pll_ref_div);
149 printk_debug("aty_valid_pll_ct: pllsclk=%d MHz, mclk=%d MHz\n",
150 pllsclk, pllsclk / pll->mclk_post_div_real);
153 pll->mclk_fb_mult = M64_HAS(MFB_TIMES_4) ? 4 : 2;
156 q = info->ref_clk_per * pll->pll_ref_div * 8 /
157 (pll->mclk_fb_mult * info->xclk_per);
159 if (q < 16*8 || q > 255*8)
160 FAIL("mclk out of range\n");
162 pll->xclk_post_div_real = 8;
164 pll->xclk_post_div_real = 4;
166 pll->xclk_post_div_real = 2;
168 pll->xclk_post_div_real = 1;
169 pll->mclk_fb_div = q*pll->xclk_post_div_real/8;
172 pllmclk = (1000000 * pll->mclk_fb_mult * pll->mclk_fb_div) /
173 (info->ref_clk_per * pll->pll_ref_div);
174 printk_debug("aty_valid_pll_ct: pllmclk=%d MHz, xclk=%d MHz\n",
175 pllmclk, pllmclk / pll->xclk_post_div_real);
178 /* FIXME: use the VTB/GTB /{3,6,12} post dividers if they're better suited */
179 q = info->ref_clk_per*pll->pll_ref_div*4/vclk_per; /* actually 8*q */
180 if (q < 16*8 || q > 255*8)
181 FAIL("vclk out of range\n");
183 pll->vclk_post_div_real = 8;
185 pll->vclk_post_div_real = 4;
187 pll->vclk_post_div_real = 2;
189 pll->vclk_post_div_real = 1;
190 pll->vclk_fb_div = q*pll->vclk_post_div_real/8;
194 static void aty_calc_pll_ct(const struct fb_info_aty *info, struct pll_ct *pll)
200 if (M64_HAS(SDRAM_MAGIC_PLL) && (info->ram_type >= SDRAM))
201 pll->pll_gen_cntl = 0x64; /* mclk = sclk */
203 pll->pll_gen_cntl = 0xe4; /* mclk = sclk */
205 switch (pll->mclk_post_div_real) {
220 pll->spll_cntl2 = mpostdiv << 4; /* sclk == pllsclk / mpostdiv */
222 switch (pll->xclk_post_div_real) {
240 if (M64_HAS(MAGIC_POSTDIV))
241 pll->pll_ext_cntl = 0;
243 pll->pll_ext_cntl = xpostdiv; /* xclk == pllmclk / xpostdiv */
245 if (pll->mclk_fb_mult == 4)
246 pll->pll_ext_cntl |= 0x08;
248 switch (pll->vclk_post_div_real) {
253 pll->pll_ext_cntl |= 0x10;
258 pll->pll_ext_cntl |= 0x10;
263 pll->pll_ext_cntl |= 0x10;
269 pll->pll_vclk_cntl = 0x03; /* VCLK = PLL_VCLK/VCLKx_POST */
270 pll->vclk_post_div = vpostdiv;
273 int aty_var_to_pll_ct(const struct fb_info_aty *info, u32 vclk_per,
274 u8 bpp, union aty_pll *pll)
277 if ((err = aty_valid_pll_ct(info, vclk_per, &pll->ct)))
279 if (M64_HAS(GTB_DSP) && (err = aty_dsp_gt(info, bpp, &pll->ct)))
281 aty_calc_pll_ct(info, &pll->ct);
285 u32 aty_pll_ct_to_var(const struct fb_info_aty *info,
286 const union aty_pll *pll)
288 u32 ref_clk_per = info->ref_clk_per;
289 u8 pll_ref_div = pll->ct.pll_ref_div;
290 u8 vclk_fb_div = pll->ct.vclk_fb_div;
291 u8 vclk_post_div = pll->ct.vclk_post_div_real;
293 return ref_clk_per*pll_ref_div*vclk_post_div/vclk_fb_div/2;
296 void aty_set_pll_ct(const struct fb_info_aty *info, const union aty_pll *pll)
299 printk_debug("aty_set_pll_ct: about to program:\n"
300 "refdiv=%d, extcntl=0x%02x, mfbdiv=%d\n"
301 "spllcntl2=0x%02x, sfbdiv=%d, gencntl=0x%02x\n"
302 "vclkcntl=0x%02x, vpostdiv=0x%02x, vfbdiv=%d\n"
304 pll->ct.pll_ref_div, pll->ct.pll_ext_cntl,
305 pll->ct.mclk_fb_div, pll->ct.spll_cntl2,
306 pll->ct.sclk_fb_div, pll->ct.pll_gen_cntl,
307 pll->ct.pll_vclk_cntl, pll->ct.vclk_post_div,
308 pll->ct.vclk_fb_div, aty_ld_le32(CLOCK_CNTL, info) & 0x03);
311 aty_st_pll(PLL_REF_DIV, pll->ct.pll_ref_div, info);
313 aty_st_pll(PLL_EXT_CNTL, pll->ct.pll_ext_cntl, info);
314 aty_st_pll(MCLK_FB_DIV, pll->ct.mclk_fb_div, info); // for XCLK
316 aty_st_pll(SPLL_CNTL2, pll->ct.spll_cntl2, info);
317 aty_st_pll(SCLK_FB_DIV, pll->ct.sclk_fb_div, info); // for MCLK
319 aty_st_pll(PLL_GEN_CNTL, pll->ct.pll_gen_cntl, info);
321 aty_st_pll(EXT_VPLL_CNTL, 0, info);
322 aty_st_pll(PLL_VCLK_CNTL, pll->ct.pll_vclk_cntl, info);
323 aty_st_pll(VCLK_POST_DIV, pll->ct.vclk_post_div, info);
324 aty_st_pll(VCLK0_FB_DIV, pll->ct.vclk_fb_div, info);
326 if (M64_HAS(GTB_DSP)) {
331 else if (info->ram_type >= SDRAM)
335 aty_st_pll(DLL_CNTL, dll_cntl, info);
336 aty_st_pll(VFC_CNTL, 0x1b, info);
337 aty_st_le32(DSP_CONFIG, pll->ct.dsp_config, info);
338 aty_st_le32(DSP_ON_OFF, pll->ct.dsp_on_off, info);
341 aty_st_pll(DLL_CNTL, dll_cntl, info);
343 aty_st_pll(DLL_CNTL, dll_cntl | 0x40, info);
345 aty_st_pll(DLL_CNTL, dll_cntl & ~0x40, info);
349 static int dummy(void)
353 static struct aty_dac_ops aty_dac_ct = {
354 set_dac: (void *)dummy,
357 static struct aty_pll_ops aty_pll_ct = {
358 var_to_pll: aty_var_to_pll_ct,
360 pll_to_var: aty_pll_ct_to_var,
361 set_pll: aty_set_pll_ct,