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