162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci
362306a36Sopenharmony_ci/*
462306a36Sopenharmony_ci *  ATI Mach64 CT/VT/GT/LT Support
562306a36Sopenharmony_ci */
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci#include <linux/fb.h>
862306a36Sopenharmony_ci#include <linux/delay.h>
962306a36Sopenharmony_ci#include <asm/io.h>
1062306a36Sopenharmony_ci#include <video/mach64.h>
1162306a36Sopenharmony_ci#include "atyfb.h"
1262306a36Sopenharmony_ci#ifdef CONFIG_PPC
1362306a36Sopenharmony_ci#include <asm/machdep.h>
1462306a36Sopenharmony_ci#endif
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci#undef DEBUG
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_cistatic int aty_valid_pll_ct (const struct fb_info *info, u32 vclk_per, struct pll_ct *pll);
1962306a36Sopenharmony_cistatic int aty_dsp_gt       (const struct fb_info *info, u32 bpp, struct pll_ct *pll);
2062306a36Sopenharmony_cistatic int aty_var_to_pll_ct(const struct fb_info *info, u32 vclk_per, u32 bpp, union aty_pll *pll);
2162306a36Sopenharmony_cistatic u32 aty_pll_to_var_ct(const struct fb_info *info, const union aty_pll *pll);
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ciu8 aty_ld_pll_ct(int offset, const struct atyfb_par *par)
2462306a36Sopenharmony_ci{
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci	/* write addr byte */
2762306a36Sopenharmony_ci	aty_st_8(CLOCK_CNTL_ADDR, (offset << 2) & PLL_ADDR, par);
2862306a36Sopenharmony_ci	/* read the register value */
2962306a36Sopenharmony_ci	return aty_ld_8(CLOCK_CNTL_DATA, par);
3062306a36Sopenharmony_ci}
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_cistatic void aty_st_pll_ct(int offset, u8 val, const struct atyfb_par *par)
3362306a36Sopenharmony_ci{
3462306a36Sopenharmony_ci	/* write addr byte */
3562306a36Sopenharmony_ci	aty_st_8(CLOCK_CNTL_ADDR, ((offset << 2) & PLL_ADDR) | PLL_WR_EN, par);
3662306a36Sopenharmony_ci	/* write the register value */
3762306a36Sopenharmony_ci	aty_st_8(CLOCK_CNTL_DATA, val & PLL_DATA, par);
3862306a36Sopenharmony_ci	aty_st_8(CLOCK_CNTL_ADDR, ((offset << 2) & PLL_ADDR) & ~PLL_WR_EN, par);
3962306a36Sopenharmony_ci}
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci/*
4262306a36Sopenharmony_ci * by Daniel Mantione
4362306a36Sopenharmony_ci *                                  <daniel.mantione@freepascal.org>
4462306a36Sopenharmony_ci *
4562306a36Sopenharmony_ci *
4662306a36Sopenharmony_ci * ATI Mach64 CT clock synthesis description.
4762306a36Sopenharmony_ci *
4862306a36Sopenharmony_ci * All clocks on the Mach64 can be calculated using the same principle:
4962306a36Sopenharmony_ci *
5062306a36Sopenharmony_ci *       XTALIN * x * FB_DIV
5162306a36Sopenharmony_ci * CLK = ----------------------
5262306a36Sopenharmony_ci *       PLL_REF_DIV * POST_DIV
5362306a36Sopenharmony_ci *
5462306a36Sopenharmony_ci * XTALIN is a fixed speed clock. Common speeds are 14.31 MHz and 29.50 MHz.
5562306a36Sopenharmony_ci * PLL_REF_DIV can be set by the user, but is the same for all clocks.
5662306a36Sopenharmony_ci * FB_DIV can be set by the user for each clock individually, it should be set
5762306a36Sopenharmony_ci * between 128 and 255, the chip will generate a bad clock signal for too low
5862306a36Sopenharmony_ci * values.
5962306a36Sopenharmony_ci * x depends on the type of clock; usually it is 2, but for the MCLK it can also
6062306a36Sopenharmony_ci * be set to 4.
6162306a36Sopenharmony_ci * POST_DIV can be set by the user for each clock individually, Possible values
6262306a36Sopenharmony_ci * are 1,2,4,8 and for some clocks other values are available too.
6362306a36Sopenharmony_ci * CLK is of course the clock speed that is generated.
6462306a36Sopenharmony_ci *
6562306a36Sopenharmony_ci * The Mach64 has these clocks:
6662306a36Sopenharmony_ci *
6762306a36Sopenharmony_ci * MCLK			The clock rate of the chip
6862306a36Sopenharmony_ci * XCLK			The clock rate of the on-chip memory
6962306a36Sopenharmony_ci * VCLK0		First pixel clock of first CRT controller
7062306a36Sopenharmony_ci * VCLK1    Second pixel clock of first CRT controller
7162306a36Sopenharmony_ci * VCLK2		Third pixel clock of first CRT controller
7262306a36Sopenharmony_ci * VCLK3    Fourth pixel clock of first CRT controller
7362306a36Sopenharmony_ci * VCLK			Selected pixel clock, one of VCLK0, VCLK1, VCLK2, VCLK3
7462306a36Sopenharmony_ci * V2CLK		Pixel clock of the second CRT controller.
7562306a36Sopenharmony_ci * SCLK			Multi-purpose clock
7662306a36Sopenharmony_ci *
7762306a36Sopenharmony_ci * - MCLK and XCLK use the same FB_DIV
7862306a36Sopenharmony_ci * - VCLK0 .. VCLK3 use the same FB_DIV
7962306a36Sopenharmony_ci * - V2CLK is needed when the second CRTC is used (can be used for dualhead);
8062306a36Sopenharmony_ci *   i.e. CRT monitor connected to laptop has different resolution than built
8162306a36Sopenharmony_ci *   in LCD monitor.
8262306a36Sopenharmony_ci * - SCLK is not available on all cards; it is know to exist on the Rage LT-PRO,
8362306a36Sopenharmony_ci *   Rage XL and Rage Mobility. It is know not to exist on the Mach64 VT.
8462306a36Sopenharmony_ci * - V2CLK is not available on all cards, most likely only the Rage LT-PRO,
8562306a36Sopenharmony_ci *   the Rage XL and the Rage Mobility
8662306a36Sopenharmony_ci *
8762306a36Sopenharmony_ci * SCLK can be used to:
8862306a36Sopenharmony_ci * - Clock the chip instead of MCLK
8962306a36Sopenharmony_ci * - Replace XTALIN with a user defined frequency
9062306a36Sopenharmony_ci * - Generate the pixel clock for the LCD monitor (instead of VCLK)
9162306a36Sopenharmony_ci */
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_ci /*
9462306a36Sopenharmony_ci  * It can be quite hard to calculate XCLK and MCLK if they don't run at the
9562306a36Sopenharmony_ci  * same frequency. Luckily, until now all cards that need asynchrone clock
9662306a36Sopenharmony_ci  * speeds seem to have SCLK.
9762306a36Sopenharmony_ci  * So this driver uses SCLK to clock the chip and XCLK to clock the memory.
9862306a36Sopenharmony_ci  */
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_ci/* ------------------------------------------------------------------------- */
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_ci/*
10362306a36Sopenharmony_ci *  PLL programming (Mach64 CT family)
10462306a36Sopenharmony_ci *
10562306a36Sopenharmony_ci *
10662306a36Sopenharmony_ci * This procedure sets the display fifo. The display fifo is a buffer that
10762306a36Sopenharmony_ci * contains data read from the video memory that waits to be processed by
10862306a36Sopenharmony_ci * the CRT controller.
10962306a36Sopenharmony_ci *
11062306a36Sopenharmony_ci * On the more modern Mach64 variants, the chip doesn't calculate the
11162306a36Sopenharmony_ci * interval after which the display fifo has to be reloaded from memory
11262306a36Sopenharmony_ci * automatically, the driver has to do it instead.
11362306a36Sopenharmony_ci */
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_ci#define Maximum_DSP_PRECISION 7
11662306a36Sopenharmony_ciconst u8 aty_postdividers[8] = {1,2,4,8,3,5,6,12};
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_cistatic int aty_dsp_gt(const struct fb_info *info, u32 bpp, struct pll_ct *pll)
11962306a36Sopenharmony_ci{
12062306a36Sopenharmony_ci	u32 dsp_off, dsp_on, dsp_xclks;
12162306a36Sopenharmony_ci	u32 multiplier, divider, ras_multiplier, ras_divider, tmp;
12262306a36Sopenharmony_ci	u8 vshift, xshift;
12362306a36Sopenharmony_ci	s8 dsp_precision;
12462306a36Sopenharmony_ci
12562306a36Sopenharmony_ci	multiplier = ((u32)pll->mclk_fb_div) * pll->vclk_post_div_real;
12662306a36Sopenharmony_ci	divider = ((u32)pll->vclk_fb_div) * pll->xclk_ref_div;
12762306a36Sopenharmony_ci
12862306a36Sopenharmony_ci	ras_multiplier = pll->xclkmaxrasdelay;
12962306a36Sopenharmony_ci	ras_divider = 1;
13062306a36Sopenharmony_ci
13162306a36Sopenharmony_ci	if (bpp>=8)
13262306a36Sopenharmony_ci		divider = divider * (bpp >> 2);
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_ci	vshift = (6 - 2) - pll->xclk_post_div;	/* FIFO is 64 bits wide in accelerator mode ... */
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ci	if (bpp == 0)
13762306a36Sopenharmony_ci		vshift--;	/* ... but only 32 bits in VGA mode. */
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_ci#ifdef CONFIG_FB_ATY_GENERIC_LCD
14062306a36Sopenharmony_ci	if (pll->xres != 0) {
14162306a36Sopenharmony_ci		struct atyfb_par *par = (struct atyfb_par *) info->par;
14262306a36Sopenharmony_ci
14362306a36Sopenharmony_ci		multiplier = multiplier * par->lcd_width;
14462306a36Sopenharmony_ci		divider = divider * pll->xres & ~7;
14562306a36Sopenharmony_ci
14662306a36Sopenharmony_ci		ras_multiplier = ras_multiplier * par->lcd_width;
14762306a36Sopenharmony_ci		ras_divider = ras_divider * pll->xres & ~7;
14862306a36Sopenharmony_ci	}
14962306a36Sopenharmony_ci#endif
15062306a36Sopenharmony_ci	/* If we don't do this, 32 bits for multiplier & divider won't be
15162306a36Sopenharmony_ci	enough in certain situations! */
15262306a36Sopenharmony_ci	while (((multiplier | divider) & 1) == 0) {
15362306a36Sopenharmony_ci		multiplier = multiplier >> 1;
15462306a36Sopenharmony_ci		divider = divider >> 1;
15562306a36Sopenharmony_ci	}
15662306a36Sopenharmony_ci
15762306a36Sopenharmony_ci	/* Determine DSP precision first */
15862306a36Sopenharmony_ci	tmp = ((multiplier * pll->fifo_size) << vshift) / divider;
15962306a36Sopenharmony_ci
16062306a36Sopenharmony_ci	for (dsp_precision = -5;  tmp;  dsp_precision++)
16162306a36Sopenharmony_ci		tmp >>= 1;
16262306a36Sopenharmony_ci	if (dsp_precision < 0)
16362306a36Sopenharmony_ci		dsp_precision = 0;
16462306a36Sopenharmony_ci	else if (dsp_precision > Maximum_DSP_PRECISION)
16562306a36Sopenharmony_ci		dsp_precision = Maximum_DSP_PRECISION;
16662306a36Sopenharmony_ci
16762306a36Sopenharmony_ci	xshift = 6 - dsp_precision;
16862306a36Sopenharmony_ci	vshift += xshift;
16962306a36Sopenharmony_ci
17062306a36Sopenharmony_ci	/* Move on to dsp_off */
17162306a36Sopenharmony_ci	dsp_off = ((multiplier * (pll->fifo_size - 1)) << vshift) / divider -
17262306a36Sopenharmony_ci		(1 << (vshift - xshift));
17362306a36Sopenharmony_ci
17462306a36Sopenharmony_ci/*    if (bpp == 0)
17562306a36Sopenharmony_ci        dsp_on = ((multiplier * 20 << vshift) + divider) / divider;
17662306a36Sopenharmony_ci    else */
17762306a36Sopenharmony_ci	{
17862306a36Sopenharmony_ci		dsp_on = ((multiplier << vshift) + divider) / divider;
17962306a36Sopenharmony_ci		tmp = ((ras_multiplier << xshift) + ras_divider) / ras_divider;
18062306a36Sopenharmony_ci		if (dsp_on < tmp)
18162306a36Sopenharmony_ci			dsp_on = tmp;
18262306a36Sopenharmony_ci		dsp_on = dsp_on + (tmp * 2) + (pll->xclkpagefaultdelay << xshift);
18362306a36Sopenharmony_ci	}
18462306a36Sopenharmony_ci
18562306a36Sopenharmony_ci	/* Calculate rounding factor and apply it to dsp_on */
18662306a36Sopenharmony_ci	tmp = ((1 << (Maximum_DSP_PRECISION - dsp_precision)) - 1) >> 1;
18762306a36Sopenharmony_ci	dsp_on = ((dsp_on + tmp) / (tmp + 1)) * (tmp + 1);
18862306a36Sopenharmony_ci
18962306a36Sopenharmony_ci	if (dsp_on >= ((dsp_off / (tmp + 1)) * (tmp + 1))) {
19062306a36Sopenharmony_ci		dsp_on = dsp_off - (multiplier << vshift) / divider;
19162306a36Sopenharmony_ci		dsp_on = (dsp_on / (tmp + 1)) * (tmp + 1);
19262306a36Sopenharmony_ci	}
19362306a36Sopenharmony_ci
19462306a36Sopenharmony_ci	/* Last but not least:  dsp_xclks */
19562306a36Sopenharmony_ci	dsp_xclks = ((multiplier << (vshift + 5)) + divider) / divider;
19662306a36Sopenharmony_ci
19762306a36Sopenharmony_ci	/* Get register values. */
19862306a36Sopenharmony_ci	pll->dsp_on_off = (dsp_on << 16) + dsp_off;
19962306a36Sopenharmony_ci	pll->dsp_config = (dsp_precision << 20) | (pll->dsp_loop_latency << 16) | dsp_xclks;
20062306a36Sopenharmony_ci#ifdef DEBUG
20162306a36Sopenharmony_ci	printk("atyfb(%s): dsp_config 0x%08x, dsp_on_off 0x%08x\n",
20262306a36Sopenharmony_ci		__func__, pll->dsp_config, pll->dsp_on_off);
20362306a36Sopenharmony_ci#endif
20462306a36Sopenharmony_ci	return 0;
20562306a36Sopenharmony_ci}
20662306a36Sopenharmony_ci
20762306a36Sopenharmony_cistatic int aty_valid_pll_ct(const struct fb_info *info, u32 vclk_per, struct pll_ct *pll)
20862306a36Sopenharmony_ci{
20962306a36Sopenharmony_ci	u32 q;
21062306a36Sopenharmony_ci	struct atyfb_par *par = (struct atyfb_par *) info->par;
21162306a36Sopenharmony_ci	int pllvclk;
21262306a36Sopenharmony_ci
21362306a36Sopenharmony_ci	/* FIXME: use the VTB/GTB /{3,6,12} post dividers if they're better suited */
21462306a36Sopenharmony_ci	q = par->ref_clk_per * pll->pll_ref_div * 4 / vclk_per;
21562306a36Sopenharmony_ci	if (q < 16*8 || q > 255*8) {
21662306a36Sopenharmony_ci		printk(KERN_CRIT "atyfb: vclk out of range\n");
21762306a36Sopenharmony_ci		return -EINVAL;
21862306a36Sopenharmony_ci	} else {
21962306a36Sopenharmony_ci		pll->vclk_post_div  = (q < 128*8);
22062306a36Sopenharmony_ci		pll->vclk_post_div += (q <  64*8);
22162306a36Sopenharmony_ci		pll->vclk_post_div += (q <  32*8);
22262306a36Sopenharmony_ci	}
22362306a36Sopenharmony_ci	pll->vclk_post_div_real = aty_postdividers[pll->vclk_post_div];
22462306a36Sopenharmony_ci	//    pll->vclk_post_div <<= 6;
22562306a36Sopenharmony_ci	pll->vclk_fb_div = q * pll->vclk_post_div_real / 8;
22662306a36Sopenharmony_ci	pllvclk = (1000000 * 2 * pll->vclk_fb_div) /
22762306a36Sopenharmony_ci		(par->ref_clk_per * pll->pll_ref_div);
22862306a36Sopenharmony_ci#ifdef DEBUG
22962306a36Sopenharmony_ci	printk("atyfb(%s): pllvclk=%d MHz, vclk=%d MHz\n",
23062306a36Sopenharmony_ci		__func__, pllvclk, pllvclk / pll->vclk_post_div_real);
23162306a36Sopenharmony_ci#endif
23262306a36Sopenharmony_ci	pll->pll_vclk_cntl = 0x03; /* VCLK = PLL_VCLK/VCLKx_POST */
23362306a36Sopenharmony_ci
23462306a36Sopenharmony_ci	/* Set ECP (scaler/overlay clock) divider */
23562306a36Sopenharmony_ci	if (par->pll_limits.ecp_max) {
23662306a36Sopenharmony_ci		int ecp = pllvclk / pll->vclk_post_div_real;
23762306a36Sopenharmony_ci		int ecp_div = 0;
23862306a36Sopenharmony_ci
23962306a36Sopenharmony_ci		while (ecp > par->pll_limits.ecp_max && ecp_div < 2) {
24062306a36Sopenharmony_ci			ecp >>= 1;
24162306a36Sopenharmony_ci			ecp_div++;
24262306a36Sopenharmony_ci		}
24362306a36Sopenharmony_ci		pll->pll_vclk_cntl |= ecp_div << 4;
24462306a36Sopenharmony_ci	}
24562306a36Sopenharmony_ci
24662306a36Sopenharmony_ci	return 0;
24762306a36Sopenharmony_ci}
24862306a36Sopenharmony_ci
24962306a36Sopenharmony_cistatic int aty_var_to_pll_ct(const struct fb_info *info, u32 vclk_per, u32 bpp, union aty_pll *pll)
25062306a36Sopenharmony_ci{
25162306a36Sopenharmony_ci	struct atyfb_par *par = (struct atyfb_par *) info->par;
25262306a36Sopenharmony_ci	int err;
25362306a36Sopenharmony_ci
25462306a36Sopenharmony_ci	if ((err = aty_valid_pll_ct(info, vclk_per, &pll->ct)))
25562306a36Sopenharmony_ci		return err;
25662306a36Sopenharmony_ci	if (M64_HAS(GTB_DSP) && (err = aty_dsp_gt(info, bpp, &pll->ct)))
25762306a36Sopenharmony_ci		return err;
25862306a36Sopenharmony_ci	/*aty_calc_pll_ct(info, &pll->ct);*/
25962306a36Sopenharmony_ci	return 0;
26062306a36Sopenharmony_ci}
26162306a36Sopenharmony_ci
26262306a36Sopenharmony_cistatic u32 aty_pll_to_var_ct(const struct fb_info *info, const union aty_pll *pll)
26362306a36Sopenharmony_ci{
26462306a36Sopenharmony_ci	struct atyfb_par *par = (struct atyfb_par *) info->par;
26562306a36Sopenharmony_ci	u32 ret;
26662306a36Sopenharmony_ci	ret = par->ref_clk_per * pll->ct.pll_ref_div * pll->ct.vclk_post_div_real / pll->ct.vclk_fb_div / 2;
26762306a36Sopenharmony_ci#ifdef CONFIG_FB_ATY_GENERIC_LCD
26862306a36Sopenharmony_ci	if(pll->ct.xres > 0) {
26962306a36Sopenharmony_ci		ret *= par->lcd_width;
27062306a36Sopenharmony_ci		ret /= pll->ct.xres;
27162306a36Sopenharmony_ci	}
27262306a36Sopenharmony_ci#endif
27362306a36Sopenharmony_ci#ifdef DEBUG
27462306a36Sopenharmony_ci	printk("atyfb(%s): calculated 0x%08X(%i)\n", __func__, ret, ret);
27562306a36Sopenharmony_ci#endif
27662306a36Sopenharmony_ci	return ret;
27762306a36Sopenharmony_ci}
27862306a36Sopenharmony_ci
27962306a36Sopenharmony_civoid aty_set_pll_ct(const struct fb_info *info, const union aty_pll *pll)
28062306a36Sopenharmony_ci{
28162306a36Sopenharmony_ci	struct atyfb_par *par = (struct atyfb_par *) info->par;
28262306a36Sopenharmony_ci	u32 crtc_gen_cntl;
28362306a36Sopenharmony_ci	u8 tmp, tmp2;
28462306a36Sopenharmony_ci
28562306a36Sopenharmony_ci#ifdef CONFIG_FB_ATY_GENERIC_LCD
28662306a36Sopenharmony_ci	u32 lcd_gen_cntrl = 0;
28762306a36Sopenharmony_ci#endif
28862306a36Sopenharmony_ci
28962306a36Sopenharmony_ci#ifdef DEBUG
29062306a36Sopenharmony_ci	printk("atyfb(%s): about to program:\n"
29162306a36Sopenharmony_ci		"pll_ext_cntl=0x%02x pll_gen_cntl=0x%02x pll_vclk_cntl=0x%02x\n",
29262306a36Sopenharmony_ci		__func__,
29362306a36Sopenharmony_ci		pll->ct.pll_ext_cntl, pll->ct.pll_gen_cntl, pll->ct.pll_vclk_cntl);
29462306a36Sopenharmony_ci
29562306a36Sopenharmony_ci	printk("atyfb(%s): setting clock %lu for FeedBackDivider %i, ReferenceDivider %i, PostDivider %i(%i)\n",
29662306a36Sopenharmony_ci		__func__,
29762306a36Sopenharmony_ci		par->clk_wr_offset, pll->ct.vclk_fb_div,
29862306a36Sopenharmony_ci		pll->ct.pll_ref_div, pll->ct.vclk_post_div, pll->ct.vclk_post_div_real);
29962306a36Sopenharmony_ci#endif
30062306a36Sopenharmony_ci#ifdef CONFIG_FB_ATY_GENERIC_LCD
30162306a36Sopenharmony_ci	if (par->lcd_table != 0) {
30262306a36Sopenharmony_ci		/* turn off LCD */
30362306a36Sopenharmony_ci		lcd_gen_cntrl = aty_ld_lcd(LCD_GEN_CNTL, par);
30462306a36Sopenharmony_ci		aty_st_lcd(LCD_GEN_CNTL, lcd_gen_cntrl & ~LCD_ON, par);
30562306a36Sopenharmony_ci	}
30662306a36Sopenharmony_ci#endif
30762306a36Sopenharmony_ci	aty_st_8(CLOCK_CNTL, par->clk_wr_offset | CLOCK_STROBE, par);
30862306a36Sopenharmony_ci
30962306a36Sopenharmony_ci	/* Temporarily switch to accelerator mode */
31062306a36Sopenharmony_ci	crtc_gen_cntl = aty_ld_le32(CRTC_GEN_CNTL, par);
31162306a36Sopenharmony_ci	if (!(crtc_gen_cntl & CRTC_EXT_DISP_EN))
31262306a36Sopenharmony_ci		aty_st_le32(CRTC_GEN_CNTL, crtc_gen_cntl | CRTC_EXT_DISP_EN, par);
31362306a36Sopenharmony_ci
31462306a36Sopenharmony_ci	/* Reset VCLK generator */
31562306a36Sopenharmony_ci	aty_st_pll_ct(PLL_VCLK_CNTL, pll->ct.pll_vclk_cntl, par);
31662306a36Sopenharmony_ci
31762306a36Sopenharmony_ci	/* Set post-divider */
31862306a36Sopenharmony_ci	tmp2 = par->clk_wr_offset << 1;
31962306a36Sopenharmony_ci	tmp = aty_ld_pll_ct(VCLK_POST_DIV, par);
32062306a36Sopenharmony_ci	tmp &= ~(0x03U << tmp2);
32162306a36Sopenharmony_ci	tmp |= ((pll->ct.vclk_post_div & 0x03U) << tmp2);
32262306a36Sopenharmony_ci	aty_st_pll_ct(VCLK_POST_DIV, tmp, par);
32362306a36Sopenharmony_ci
32462306a36Sopenharmony_ci	/* Set extended post-divider */
32562306a36Sopenharmony_ci	tmp = aty_ld_pll_ct(PLL_EXT_CNTL, par);
32662306a36Sopenharmony_ci	tmp &= ~(0x10U << par->clk_wr_offset);
32762306a36Sopenharmony_ci	tmp &= 0xF0U;
32862306a36Sopenharmony_ci	tmp |= pll->ct.pll_ext_cntl;
32962306a36Sopenharmony_ci	aty_st_pll_ct(PLL_EXT_CNTL, tmp, par);
33062306a36Sopenharmony_ci
33162306a36Sopenharmony_ci	/* Set feedback divider */
33262306a36Sopenharmony_ci	tmp = VCLK0_FB_DIV + par->clk_wr_offset;
33362306a36Sopenharmony_ci	aty_st_pll_ct(tmp, (pll->ct.vclk_fb_div & 0xFFU), par);
33462306a36Sopenharmony_ci
33562306a36Sopenharmony_ci	aty_st_pll_ct(PLL_GEN_CNTL, (pll->ct.pll_gen_cntl & (~(PLL_OVERRIDE | PLL_MCLK_RST))) | OSC_EN, par);
33662306a36Sopenharmony_ci
33762306a36Sopenharmony_ci	/* End VCLK generator reset */
33862306a36Sopenharmony_ci	aty_st_pll_ct(PLL_VCLK_CNTL, pll->ct.pll_vclk_cntl & ~(PLL_VCLK_RST), par);
33962306a36Sopenharmony_ci	mdelay(5);
34062306a36Sopenharmony_ci
34162306a36Sopenharmony_ci	aty_st_pll_ct(PLL_GEN_CNTL, pll->ct.pll_gen_cntl, par);
34262306a36Sopenharmony_ci	aty_st_pll_ct(PLL_VCLK_CNTL, pll->ct.pll_vclk_cntl, par);
34362306a36Sopenharmony_ci	mdelay(1);
34462306a36Sopenharmony_ci
34562306a36Sopenharmony_ci	/* Restore mode register */
34662306a36Sopenharmony_ci	if (!(crtc_gen_cntl & CRTC_EXT_DISP_EN))
34762306a36Sopenharmony_ci		aty_st_le32(CRTC_GEN_CNTL, crtc_gen_cntl, par);
34862306a36Sopenharmony_ci
34962306a36Sopenharmony_ci	if (M64_HAS(GTB_DSP)) {
35062306a36Sopenharmony_ci		u8 dll_cntl;
35162306a36Sopenharmony_ci
35262306a36Sopenharmony_ci		if (M64_HAS(XL_DLL))
35362306a36Sopenharmony_ci			dll_cntl = 0x80;
35462306a36Sopenharmony_ci		else if (par->ram_type >= SDRAM)
35562306a36Sopenharmony_ci			dll_cntl = 0xa6;
35662306a36Sopenharmony_ci		else
35762306a36Sopenharmony_ci			dll_cntl = 0xa0;
35862306a36Sopenharmony_ci		aty_st_pll_ct(DLL_CNTL, dll_cntl, par);
35962306a36Sopenharmony_ci		aty_st_pll_ct(VFC_CNTL, 0x1b, par);
36062306a36Sopenharmony_ci		aty_st_le32(DSP_CONFIG, pll->ct.dsp_config, par);
36162306a36Sopenharmony_ci		aty_st_le32(DSP_ON_OFF, pll->ct.dsp_on_off, par);
36262306a36Sopenharmony_ci
36362306a36Sopenharmony_ci		mdelay(10);
36462306a36Sopenharmony_ci		aty_st_pll_ct(DLL_CNTL, dll_cntl, par);
36562306a36Sopenharmony_ci		mdelay(10);
36662306a36Sopenharmony_ci		aty_st_pll_ct(DLL_CNTL, dll_cntl | 0x40, par);
36762306a36Sopenharmony_ci		mdelay(10);
36862306a36Sopenharmony_ci		aty_st_pll_ct(DLL_CNTL, dll_cntl & ~0x40, par);
36962306a36Sopenharmony_ci	}
37062306a36Sopenharmony_ci#ifdef CONFIG_FB_ATY_GENERIC_LCD
37162306a36Sopenharmony_ci	if (par->lcd_table != 0) {
37262306a36Sopenharmony_ci		/* restore LCD */
37362306a36Sopenharmony_ci		aty_st_lcd(LCD_GEN_CNTL, lcd_gen_cntrl, par);
37462306a36Sopenharmony_ci	}
37562306a36Sopenharmony_ci#endif
37662306a36Sopenharmony_ci}
37762306a36Sopenharmony_ci
37862306a36Sopenharmony_cistatic void aty_get_pll_ct(const struct fb_info *info, union aty_pll *pll)
37962306a36Sopenharmony_ci{
38062306a36Sopenharmony_ci	struct atyfb_par *par = (struct atyfb_par *) info->par;
38162306a36Sopenharmony_ci	u8 tmp, clock;
38262306a36Sopenharmony_ci
38362306a36Sopenharmony_ci	clock = aty_ld_8(CLOCK_CNTL, par) & 0x03U;
38462306a36Sopenharmony_ci	tmp = clock << 1;
38562306a36Sopenharmony_ci	pll->ct.vclk_post_div = (aty_ld_pll_ct(VCLK_POST_DIV, par) >> tmp) & 0x03U;
38662306a36Sopenharmony_ci
38762306a36Sopenharmony_ci	pll->ct.pll_ext_cntl = aty_ld_pll_ct(PLL_EXT_CNTL, par) & 0x0FU;
38862306a36Sopenharmony_ci	pll->ct.vclk_fb_div = aty_ld_pll_ct(VCLK0_FB_DIV + clock, par) & 0xFFU;
38962306a36Sopenharmony_ci	pll->ct.pll_ref_div = aty_ld_pll_ct(PLL_REF_DIV, par);
39062306a36Sopenharmony_ci	pll->ct.mclk_fb_div = aty_ld_pll_ct(MCLK_FB_DIV, par);
39162306a36Sopenharmony_ci
39262306a36Sopenharmony_ci	pll->ct.pll_gen_cntl = aty_ld_pll_ct(PLL_GEN_CNTL, par);
39362306a36Sopenharmony_ci	pll->ct.pll_vclk_cntl = aty_ld_pll_ct(PLL_VCLK_CNTL, par);
39462306a36Sopenharmony_ci
39562306a36Sopenharmony_ci	if (M64_HAS(GTB_DSP)) {
39662306a36Sopenharmony_ci		pll->ct.dsp_config = aty_ld_le32(DSP_CONFIG, par);
39762306a36Sopenharmony_ci		pll->ct.dsp_on_off = aty_ld_le32(DSP_ON_OFF, par);
39862306a36Sopenharmony_ci	}
39962306a36Sopenharmony_ci}
40062306a36Sopenharmony_ci
40162306a36Sopenharmony_cistatic int aty_init_pll_ct(const struct fb_info *info, union aty_pll *pll)
40262306a36Sopenharmony_ci{
40362306a36Sopenharmony_ci	struct atyfb_par *par = (struct atyfb_par *) info->par;
40462306a36Sopenharmony_ci	u8 mpost_div, xpost_div, sclk_post_div_real;
40562306a36Sopenharmony_ci	u32 q, memcntl, trp;
40662306a36Sopenharmony_ci	u32 dsp_config;
40762306a36Sopenharmony_ci#ifdef DEBUG
40862306a36Sopenharmony_ci	int pllmclk, pllsclk;
40962306a36Sopenharmony_ci#endif
41062306a36Sopenharmony_ci	pll->ct.pll_ext_cntl = aty_ld_pll_ct(PLL_EXT_CNTL, par);
41162306a36Sopenharmony_ci	pll->ct.xclk_post_div = pll->ct.pll_ext_cntl & 0x07;
41262306a36Sopenharmony_ci	pll->ct.xclk_ref_div = 1;
41362306a36Sopenharmony_ci	switch (pll->ct.xclk_post_div) {
41462306a36Sopenharmony_ci	case 0:  case 1:  case 2:  case 3:
41562306a36Sopenharmony_ci		break;
41662306a36Sopenharmony_ci
41762306a36Sopenharmony_ci	case 4:
41862306a36Sopenharmony_ci		pll->ct.xclk_ref_div = 3;
41962306a36Sopenharmony_ci		pll->ct.xclk_post_div = 0;
42062306a36Sopenharmony_ci		break;
42162306a36Sopenharmony_ci
42262306a36Sopenharmony_ci	default:
42362306a36Sopenharmony_ci		printk(KERN_CRIT "atyfb: Unsupported xclk source:  %d.\n", pll->ct.xclk_post_div);
42462306a36Sopenharmony_ci		return -EINVAL;
42562306a36Sopenharmony_ci	}
42662306a36Sopenharmony_ci	pll->ct.mclk_fb_mult = 2;
42762306a36Sopenharmony_ci	if(pll->ct.pll_ext_cntl & PLL_MFB_TIMES_4_2B) {
42862306a36Sopenharmony_ci		pll->ct.mclk_fb_mult = 4;
42962306a36Sopenharmony_ci		pll->ct.xclk_post_div -= 1;
43062306a36Sopenharmony_ci	}
43162306a36Sopenharmony_ci
43262306a36Sopenharmony_ci#ifdef DEBUG
43362306a36Sopenharmony_ci	printk("atyfb(%s): mclk_fb_mult=%d, xclk_post_div=%d\n",
43462306a36Sopenharmony_ci		__func__, pll->ct.mclk_fb_mult, pll->ct.xclk_post_div);
43562306a36Sopenharmony_ci#endif
43662306a36Sopenharmony_ci
43762306a36Sopenharmony_ci	memcntl = aty_ld_le32(MEM_CNTL, par);
43862306a36Sopenharmony_ci	trp = (memcntl & 0x300) >> 8;
43962306a36Sopenharmony_ci
44062306a36Sopenharmony_ci	pll->ct.xclkpagefaultdelay = ((memcntl & 0xc00) >> 10) + ((memcntl & 0x1000) >> 12) + trp + 2;
44162306a36Sopenharmony_ci	pll->ct.xclkmaxrasdelay = ((memcntl & 0x70000) >> 16) + trp + 2;
44262306a36Sopenharmony_ci
44362306a36Sopenharmony_ci	if (M64_HAS(FIFO_32)) {
44462306a36Sopenharmony_ci		pll->ct.fifo_size = 32;
44562306a36Sopenharmony_ci	} else {
44662306a36Sopenharmony_ci		pll->ct.fifo_size = 24;
44762306a36Sopenharmony_ci		pll->ct.xclkpagefaultdelay += 2;
44862306a36Sopenharmony_ci		pll->ct.xclkmaxrasdelay += 3;
44962306a36Sopenharmony_ci	}
45062306a36Sopenharmony_ci
45162306a36Sopenharmony_ci	switch (par->ram_type) {
45262306a36Sopenharmony_ci	case DRAM:
45362306a36Sopenharmony_ci		if (info->fix.smem_len<=ONE_MB) {
45462306a36Sopenharmony_ci			pll->ct.dsp_loop_latency = 10;
45562306a36Sopenharmony_ci		} else {
45662306a36Sopenharmony_ci			pll->ct.dsp_loop_latency = 8;
45762306a36Sopenharmony_ci			pll->ct.xclkpagefaultdelay += 2;
45862306a36Sopenharmony_ci		}
45962306a36Sopenharmony_ci		break;
46062306a36Sopenharmony_ci	case EDO:
46162306a36Sopenharmony_ci	case PSEUDO_EDO:
46262306a36Sopenharmony_ci		if (info->fix.smem_len<=ONE_MB) {
46362306a36Sopenharmony_ci			pll->ct.dsp_loop_latency = 9;
46462306a36Sopenharmony_ci		} else {
46562306a36Sopenharmony_ci			pll->ct.dsp_loop_latency = 8;
46662306a36Sopenharmony_ci			pll->ct.xclkpagefaultdelay += 1;
46762306a36Sopenharmony_ci		}
46862306a36Sopenharmony_ci		break;
46962306a36Sopenharmony_ci	case SDRAM:
47062306a36Sopenharmony_ci		if (info->fix.smem_len<=ONE_MB) {
47162306a36Sopenharmony_ci			pll->ct.dsp_loop_latency = 11;
47262306a36Sopenharmony_ci		} else {
47362306a36Sopenharmony_ci			pll->ct.dsp_loop_latency = 10;
47462306a36Sopenharmony_ci			pll->ct.xclkpagefaultdelay += 1;
47562306a36Sopenharmony_ci		}
47662306a36Sopenharmony_ci		break;
47762306a36Sopenharmony_ci	case SGRAM:
47862306a36Sopenharmony_ci		pll->ct.dsp_loop_latency = 8;
47962306a36Sopenharmony_ci		pll->ct.xclkpagefaultdelay += 3;
48062306a36Sopenharmony_ci		break;
48162306a36Sopenharmony_ci	default:
48262306a36Sopenharmony_ci		pll->ct.dsp_loop_latency = 11;
48362306a36Sopenharmony_ci		pll->ct.xclkpagefaultdelay += 3;
48462306a36Sopenharmony_ci		break;
48562306a36Sopenharmony_ci	}
48662306a36Sopenharmony_ci
48762306a36Sopenharmony_ci	if (pll->ct.xclkmaxrasdelay <= pll->ct.xclkpagefaultdelay)
48862306a36Sopenharmony_ci		pll->ct.xclkmaxrasdelay = pll->ct.xclkpagefaultdelay + 1;
48962306a36Sopenharmony_ci
49062306a36Sopenharmony_ci	/* Allow BIOS to override */
49162306a36Sopenharmony_ci	dsp_config = aty_ld_le32(DSP_CONFIG, par);
49262306a36Sopenharmony_ci	aty_ld_le32(DSP_ON_OFF, par);
49362306a36Sopenharmony_ci	aty_ld_le32(VGA_DSP_CONFIG, par);
49462306a36Sopenharmony_ci	aty_ld_le32(VGA_DSP_ON_OFF, par);
49562306a36Sopenharmony_ci
49662306a36Sopenharmony_ci	if (dsp_config)
49762306a36Sopenharmony_ci		pll->ct.dsp_loop_latency = (dsp_config & DSP_LOOP_LATENCY) >> 16;
49862306a36Sopenharmony_ci#if 0
49962306a36Sopenharmony_ci	FIXME: is it relevant for us?
50062306a36Sopenharmony_ci	if ((!dsp_on_off && !M64_HAS(RESET_3D)) ||
50162306a36Sopenharmony_ci		((dsp_on_off == vga_dsp_on_off) &&
50262306a36Sopenharmony_ci		(!dsp_config || !((dsp_config ^ vga_dsp_config) & DSP_XCLKS_PER_QW)))) {
50362306a36Sopenharmony_ci		vga_dsp_on_off &= VGA_DSP_OFF;
50462306a36Sopenharmony_ci		vga_dsp_config &= VGA_DSP_XCLKS_PER_QW;
50562306a36Sopenharmony_ci		if (ATIDivide(vga_dsp_on_off, vga_dsp_config, 5, 1) > 24)
50662306a36Sopenharmony_ci			pll->ct.fifo_size = 32;
50762306a36Sopenharmony_ci		else
50862306a36Sopenharmony_ci			pll->ct.fifo_size = 24;
50962306a36Sopenharmony_ci	}
51062306a36Sopenharmony_ci#endif
51162306a36Sopenharmony_ci	/* Exit if the user does not want us to tamper with the clock
51262306a36Sopenharmony_ci	rates of her chip. */
51362306a36Sopenharmony_ci	if (par->mclk_per == 0) {
51462306a36Sopenharmony_ci		u8 mclk_fb_div, pll_ext_cntl;
51562306a36Sopenharmony_ci		pll->ct.pll_ref_div = aty_ld_pll_ct(PLL_REF_DIV, par);
51662306a36Sopenharmony_ci		pll_ext_cntl = aty_ld_pll_ct(PLL_EXT_CNTL, par);
51762306a36Sopenharmony_ci		pll->ct.xclk_post_div_real = aty_postdividers[pll_ext_cntl & 0x07];
51862306a36Sopenharmony_ci		mclk_fb_div = aty_ld_pll_ct(MCLK_FB_DIV, par);
51962306a36Sopenharmony_ci		if (pll_ext_cntl & PLL_MFB_TIMES_4_2B)
52062306a36Sopenharmony_ci			mclk_fb_div <<= 1;
52162306a36Sopenharmony_ci		pll->ct.mclk_fb_div = mclk_fb_div;
52262306a36Sopenharmony_ci		return 0;
52362306a36Sopenharmony_ci	}
52462306a36Sopenharmony_ci
52562306a36Sopenharmony_ci	pll->ct.pll_ref_div = par->pll_per * 2 * 255 / par->ref_clk_per;
52662306a36Sopenharmony_ci
52762306a36Sopenharmony_ci	/* FIXME: use the VTB/GTB /3 post divider if it's better suited */
52862306a36Sopenharmony_ci	q = par->ref_clk_per * pll->ct.pll_ref_div * 8 /
52962306a36Sopenharmony_ci		(pll->ct.mclk_fb_mult * par->xclk_per);
53062306a36Sopenharmony_ci
53162306a36Sopenharmony_ci	if (q < 16*8 || q > 255*8) {
53262306a36Sopenharmony_ci		printk(KERN_CRIT "atxfb: xclk out of range\n");
53362306a36Sopenharmony_ci		return -EINVAL;
53462306a36Sopenharmony_ci	} else {
53562306a36Sopenharmony_ci		xpost_div  = (q < 128*8);
53662306a36Sopenharmony_ci		xpost_div += (q <  64*8);
53762306a36Sopenharmony_ci		xpost_div += (q <  32*8);
53862306a36Sopenharmony_ci	}
53962306a36Sopenharmony_ci	pll->ct.xclk_post_div_real = aty_postdividers[xpost_div];
54062306a36Sopenharmony_ci	pll->ct.mclk_fb_div = q * pll->ct.xclk_post_div_real / 8;
54162306a36Sopenharmony_ci
54262306a36Sopenharmony_ci#ifdef CONFIG_PPC
54362306a36Sopenharmony_ci	if (machine_is(powermac)) {
54462306a36Sopenharmony_ci		/* Override PLL_EXT_CNTL & 0x07. */
54562306a36Sopenharmony_ci		pll->ct.xclk_post_div = xpost_div;
54662306a36Sopenharmony_ci		pll->ct.xclk_ref_div = 1;
54762306a36Sopenharmony_ci	}
54862306a36Sopenharmony_ci#endif
54962306a36Sopenharmony_ci
55062306a36Sopenharmony_ci#ifdef DEBUG
55162306a36Sopenharmony_ci	pllmclk = (1000000 * pll->ct.mclk_fb_mult * pll->ct.mclk_fb_div) /
55262306a36Sopenharmony_ci			(par->ref_clk_per * pll->ct.pll_ref_div);
55362306a36Sopenharmony_ci	printk("atyfb(%s): pllmclk=%d MHz, xclk=%d MHz\n",
55462306a36Sopenharmony_ci		__func__, pllmclk, pllmclk / pll->ct.xclk_post_div_real);
55562306a36Sopenharmony_ci#endif
55662306a36Sopenharmony_ci
55762306a36Sopenharmony_ci	if (M64_HAS(SDRAM_MAGIC_PLL) && (par->ram_type >= SDRAM))
55862306a36Sopenharmony_ci		pll->ct.pll_gen_cntl = OSC_EN;
55962306a36Sopenharmony_ci	else
56062306a36Sopenharmony_ci		pll->ct.pll_gen_cntl = OSC_EN | DLL_PWDN /* | FORCE_DCLK_TRI_STATE */;
56162306a36Sopenharmony_ci
56262306a36Sopenharmony_ci	if (M64_HAS(MAGIC_POSTDIV))
56362306a36Sopenharmony_ci		pll->ct.pll_ext_cntl = 0;
56462306a36Sopenharmony_ci	else
56562306a36Sopenharmony_ci		pll->ct.pll_ext_cntl = xpost_div;
56662306a36Sopenharmony_ci
56762306a36Sopenharmony_ci	if (pll->ct.mclk_fb_mult == 4)
56862306a36Sopenharmony_ci		pll->ct.pll_ext_cntl |= PLL_MFB_TIMES_4_2B;
56962306a36Sopenharmony_ci
57062306a36Sopenharmony_ci	if (par->mclk_per == par->xclk_per) {
57162306a36Sopenharmony_ci		pll->ct.pll_gen_cntl |= (xpost_div << 4); /* mclk == xclk */
57262306a36Sopenharmony_ci	} else {
57362306a36Sopenharmony_ci		/*
57462306a36Sopenharmony_ci		* The chip clock is not equal to the memory clock.
57562306a36Sopenharmony_ci		* Therefore we will use sclk to clock the chip.
57662306a36Sopenharmony_ci		*/
57762306a36Sopenharmony_ci		pll->ct.pll_gen_cntl |= (6 << 4); /* mclk == sclk */
57862306a36Sopenharmony_ci
57962306a36Sopenharmony_ci		q = par->ref_clk_per * pll->ct.pll_ref_div * 4 / par->mclk_per;
58062306a36Sopenharmony_ci		if (q < 16*8 || q > 255*8) {
58162306a36Sopenharmony_ci			printk(KERN_CRIT "atyfb: mclk out of range\n");
58262306a36Sopenharmony_ci			return -EINVAL;
58362306a36Sopenharmony_ci		} else {
58462306a36Sopenharmony_ci			mpost_div  = (q < 128*8);
58562306a36Sopenharmony_ci			mpost_div += (q <  64*8);
58662306a36Sopenharmony_ci			mpost_div += (q <  32*8);
58762306a36Sopenharmony_ci		}
58862306a36Sopenharmony_ci		sclk_post_div_real = aty_postdividers[mpost_div];
58962306a36Sopenharmony_ci		pll->ct.sclk_fb_div = q * sclk_post_div_real / 8;
59062306a36Sopenharmony_ci		pll->ct.spll_cntl2 = mpost_div << 4;
59162306a36Sopenharmony_ci#ifdef DEBUG
59262306a36Sopenharmony_ci		pllsclk = (1000000 * 2 * pll->ct.sclk_fb_div) /
59362306a36Sopenharmony_ci			(par->ref_clk_per * pll->ct.pll_ref_div);
59462306a36Sopenharmony_ci		printk("atyfb(%s): use sclk, pllsclk=%d MHz, sclk=mclk=%d MHz\n",
59562306a36Sopenharmony_ci			__func__, pllsclk, pllsclk / sclk_post_div_real);
59662306a36Sopenharmony_ci#endif
59762306a36Sopenharmony_ci	}
59862306a36Sopenharmony_ci
59962306a36Sopenharmony_ci	/* Disable the extra precision pixel clock controls since we do not use them. */
60062306a36Sopenharmony_ci	pll->ct.ext_vpll_cntl = aty_ld_pll_ct(EXT_VPLL_CNTL, par);
60162306a36Sopenharmony_ci	pll->ct.ext_vpll_cntl &= ~(EXT_VPLL_EN | EXT_VPLL_VGA_EN | EXT_VPLL_INSYNC);
60262306a36Sopenharmony_ci
60362306a36Sopenharmony_ci	return 0;
60462306a36Sopenharmony_ci}
60562306a36Sopenharmony_ci
60662306a36Sopenharmony_cistatic void aty_resume_pll_ct(const struct fb_info *info,
60762306a36Sopenharmony_ci			      union aty_pll *pll)
60862306a36Sopenharmony_ci{
60962306a36Sopenharmony_ci	struct atyfb_par *par = info->par;
61062306a36Sopenharmony_ci
61162306a36Sopenharmony_ci	if (par->mclk_per != par->xclk_per) {
61262306a36Sopenharmony_ci		/*
61362306a36Sopenharmony_ci		* This disables the sclk, crashes the computer as reported:
61462306a36Sopenharmony_ci		* aty_st_pll_ct(SPLL_CNTL2, 3, info);
61562306a36Sopenharmony_ci		*
61662306a36Sopenharmony_ci		* So it seems the sclk must be enabled before it is used;
61762306a36Sopenharmony_ci		* so PLL_GEN_CNTL must be programmed *after* the sclk.
61862306a36Sopenharmony_ci		*/
61962306a36Sopenharmony_ci		aty_st_pll_ct(SCLK_FB_DIV, pll->ct.sclk_fb_div, par);
62062306a36Sopenharmony_ci		aty_st_pll_ct(SPLL_CNTL2, pll->ct.spll_cntl2, par);
62162306a36Sopenharmony_ci		/*
62262306a36Sopenharmony_ci		 * SCLK has been started. Wait for the PLL to lock. 5 ms
62362306a36Sopenharmony_ci		 * should be enough according to mach64 programmer's guide.
62462306a36Sopenharmony_ci		 */
62562306a36Sopenharmony_ci		mdelay(5);
62662306a36Sopenharmony_ci	}
62762306a36Sopenharmony_ci
62862306a36Sopenharmony_ci	aty_st_pll_ct(PLL_REF_DIV, pll->ct.pll_ref_div, par);
62962306a36Sopenharmony_ci	aty_st_pll_ct(PLL_GEN_CNTL, pll->ct.pll_gen_cntl, par);
63062306a36Sopenharmony_ci	aty_st_pll_ct(MCLK_FB_DIV, pll->ct.mclk_fb_div, par);
63162306a36Sopenharmony_ci	aty_st_pll_ct(PLL_EXT_CNTL, pll->ct.pll_ext_cntl, par);
63262306a36Sopenharmony_ci	aty_st_pll_ct(EXT_VPLL_CNTL, pll->ct.ext_vpll_cntl, par);
63362306a36Sopenharmony_ci}
63462306a36Sopenharmony_ci
63562306a36Sopenharmony_cistatic int dummy(void)
63662306a36Sopenharmony_ci{
63762306a36Sopenharmony_ci	return 0;
63862306a36Sopenharmony_ci}
63962306a36Sopenharmony_ci
64062306a36Sopenharmony_ciconst struct aty_dac_ops aty_dac_ct = {
64162306a36Sopenharmony_ci	.set_dac	= (void *) dummy,
64262306a36Sopenharmony_ci};
64362306a36Sopenharmony_ci
64462306a36Sopenharmony_ciconst struct aty_pll_ops aty_pll_ct = {
64562306a36Sopenharmony_ci	.var_to_pll	= aty_var_to_pll_ct,
64662306a36Sopenharmony_ci	.pll_to_var	= aty_pll_to_var_ct,
64762306a36Sopenharmony_ci	.set_pll	= aty_set_pll_ct,
64862306a36Sopenharmony_ci	.get_pll	= aty_get_pll_ct,
64962306a36Sopenharmony_ci	.init_pll	= aty_init_pll_ct,
65062306a36Sopenharmony_ci	.resume_pll	= aty_resume_pll_ct,
65162306a36Sopenharmony_ci};
652