18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci 38c2ecf20Sopenharmony_ci/* 48c2ecf20Sopenharmony_ci * ATI Mach64 CT/VT/GT/LT Support 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#include <linux/fb.h> 88c2ecf20Sopenharmony_ci#include <linux/delay.h> 98c2ecf20Sopenharmony_ci#include <asm/io.h> 108c2ecf20Sopenharmony_ci#include <video/mach64.h> 118c2ecf20Sopenharmony_ci#include "atyfb.h" 128c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC 138c2ecf20Sopenharmony_ci#include <asm/machdep.h> 148c2ecf20Sopenharmony_ci#endif 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci#undef DEBUG 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_cistatic int aty_valid_pll_ct (const struct fb_info *info, u32 vclk_per, struct pll_ct *pll); 198c2ecf20Sopenharmony_cistatic int aty_dsp_gt (const struct fb_info *info, u32 bpp, struct pll_ct *pll); 208c2ecf20Sopenharmony_cistatic int aty_var_to_pll_ct(const struct fb_info *info, u32 vclk_per, u32 bpp, union aty_pll *pll); 218c2ecf20Sopenharmony_cistatic u32 aty_pll_to_var_ct(const struct fb_info *info, const union aty_pll *pll); 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ciu8 aty_ld_pll_ct(int offset, const struct atyfb_par *par) 248c2ecf20Sopenharmony_ci{ 258c2ecf20Sopenharmony_ci u8 res; 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci /* write addr byte */ 288c2ecf20Sopenharmony_ci aty_st_8(CLOCK_CNTL_ADDR, (offset << 2) & PLL_ADDR, par); 298c2ecf20Sopenharmony_ci /* read the register value */ 308c2ecf20Sopenharmony_ci res = aty_ld_8(CLOCK_CNTL_DATA, par); 318c2ecf20Sopenharmony_ci return res; 328c2ecf20Sopenharmony_ci} 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_cistatic void aty_st_pll_ct(int offset, u8 val, const struct atyfb_par *par) 358c2ecf20Sopenharmony_ci{ 368c2ecf20Sopenharmony_ci /* write addr byte */ 378c2ecf20Sopenharmony_ci aty_st_8(CLOCK_CNTL_ADDR, ((offset << 2) & PLL_ADDR) | PLL_WR_EN, par); 388c2ecf20Sopenharmony_ci /* write the register value */ 398c2ecf20Sopenharmony_ci aty_st_8(CLOCK_CNTL_DATA, val & PLL_DATA, par); 408c2ecf20Sopenharmony_ci aty_st_8(CLOCK_CNTL_ADDR, ((offset << 2) & PLL_ADDR) & ~PLL_WR_EN, par); 418c2ecf20Sopenharmony_ci} 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci/* 448c2ecf20Sopenharmony_ci * by Daniel Mantione 458c2ecf20Sopenharmony_ci * <daniel.mantione@freepascal.org> 468c2ecf20Sopenharmony_ci * 478c2ecf20Sopenharmony_ci * 488c2ecf20Sopenharmony_ci * ATI Mach64 CT clock synthesis description. 498c2ecf20Sopenharmony_ci * 508c2ecf20Sopenharmony_ci * All clocks on the Mach64 can be calculated using the same principle: 518c2ecf20Sopenharmony_ci * 528c2ecf20Sopenharmony_ci * XTALIN * x * FB_DIV 538c2ecf20Sopenharmony_ci * CLK = ---------------------- 548c2ecf20Sopenharmony_ci * PLL_REF_DIV * POST_DIV 558c2ecf20Sopenharmony_ci * 568c2ecf20Sopenharmony_ci * XTALIN is a fixed speed clock. Common speeds are 14.31 MHz and 29.50 MHz. 578c2ecf20Sopenharmony_ci * PLL_REF_DIV can be set by the user, but is the same for all clocks. 588c2ecf20Sopenharmony_ci * FB_DIV can be set by the user for each clock individually, it should be set 598c2ecf20Sopenharmony_ci * between 128 and 255, the chip will generate a bad clock signal for too low 608c2ecf20Sopenharmony_ci * values. 618c2ecf20Sopenharmony_ci * x depends on the type of clock; usually it is 2, but for the MCLK it can also 628c2ecf20Sopenharmony_ci * be set to 4. 638c2ecf20Sopenharmony_ci * POST_DIV can be set by the user for each clock individually, Possible values 648c2ecf20Sopenharmony_ci * are 1,2,4,8 and for some clocks other values are available too. 658c2ecf20Sopenharmony_ci * CLK is of course the clock speed that is generated. 668c2ecf20Sopenharmony_ci * 678c2ecf20Sopenharmony_ci * The Mach64 has these clocks: 688c2ecf20Sopenharmony_ci * 698c2ecf20Sopenharmony_ci * MCLK The clock rate of the chip 708c2ecf20Sopenharmony_ci * XCLK The clock rate of the on-chip memory 718c2ecf20Sopenharmony_ci * VCLK0 First pixel clock of first CRT controller 728c2ecf20Sopenharmony_ci * VCLK1 Second pixel clock of first CRT controller 738c2ecf20Sopenharmony_ci * VCLK2 Third pixel clock of first CRT controller 748c2ecf20Sopenharmony_ci * VCLK3 Fourth pixel clock of first CRT controller 758c2ecf20Sopenharmony_ci * VCLK Selected pixel clock, one of VCLK0, VCLK1, VCLK2, VCLK3 768c2ecf20Sopenharmony_ci * V2CLK Pixel clock of the second CRT controller. 778c2ecf20Sopenharmony_ci * SCLK Multi-purpose clock 788c2ecf20Sopenharmony_ci * 798c2ecf20Sopenharmony_ci * - MCLK and XCLK use the same FB_DIV 808c2ecf20Sopenharmony_ci * - VCLK0 .. VCLK3 use the same FB_DIV 818c2ecf20Sopenharmony_ci * - V2CLK is needed when the second CRTC is used (can be used for dualhead); 828c2ecf20Sopenharmony_ci * i.e. CRT monitor connected to laptop has different resolution than built 838c2ecf20Sopenharmony_ci * in LCD monitor. 848c2ecf20Sopenharmony_ci * - SCLK is not available on all cards; it is know to exist on the Rage LT-PRO, 858c2ecf20Sopenharmony_ci * Rage XL and Rage Mobility. It is know not to exist on the Mach64 VT. 868c2ecf20Sopenharmony_ci * - V2CLK is not available on all cards, most likely only the Rage LT-PRO, 878c2ecf20Sopenharmony_ci * the Rage XL and the Rage Mobility 888c2ecf20Sopenharmony_ci * 898c2ecf20Sopenharmony_ci * SCLK can be used to: 908c2ecf20Sopenharmony_ci * - Clock the chip instead of MCLK 918c2ecf20Sopenharmony_ci * - Replace XTALIN with a user defined frequency 928c2ecf20Sopenharmony_ci * - Generate the pixel clock for the LCD monitor (instead of VCLK) 938c2ecf20Sopenharmony_ci */ 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci /* 968c2ecf20Sopenharmony_ci * It can be quite hard to calculate XCLK and MCLK if they don't run at the 978c2ecf20Sopenharmony_ci * same frequency. Luckily, until now all cards that need asynchrone clock 988c2ecf20Sopenharmony_ci * speeds seem to have SCLK. 998c2ecf20Sopenharmony_ci * So this driver uses SCLK to clock the chip and XCLK to clock the memory. 1008c2ecf20Sopenharmony_ci */ 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci/* ------------------------------------------------------------------------- */ 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci/* 1058c2ecf20Sopenharmony_ci * PLL programming (Mach64 CT family) 1068c2ecf20Sopenharmony_ci * 1078c2ecf20Sopenharmony_ci * 1088c2ecf20Sopenharmony_ci * This procedure sets the display fifo. The display fifo is a buffer that 1098c2ecf20Sopenharmony_ci * contains data read from the video memory that waits to be processed by 1108c2ecf20Sopenharmony_ci * the CRT controller. 1118c2ecf20Sopenharmony_ci * 1128c2ecf20Sopenharmony_ci * On the more modern Mach64 variants, the chip doesn't calculate the 1138c2ecf20Sopenharmony_ci * interval after which the display fifo has to be reloaded from memory 1148c2ecf20Sopenharmony_ci * automatically, the driver has to do it instead. 1158c2ecf20Sopenharmony_ci */ 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci#define Maximum_DSP_PRECISION 7 1188c2ecf20Sopenharmony_ciconst u8 aty_postdividers[8] = {1,2,4,8,3,5,6,12}; 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_cistatic int aty_dsp_gt(const struct fb_info *info, u32 bpp, struct pll_ct *pll) 1218c2ecf20Sopenharmony_ci{ 1228c2ecf20Sopenharmony_ci u32 dsp_off, dsp_on, dsp_xclks; 1238c2ecf20Sopenharmony_ci u32 multiplier, divider, ras_multiplier, ras_divider, tmp; 1248c2ecf20Sopenharmony_ci u8 vshift, xshift; 1258c2ecf20Sopenharmony_ci s8 dsp_precision; 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci multiplier = ((u32)pll->mclk_fb_div) * pll->vclk_post_div_real; 1288c2ecf20Sopenharmony_ci divider = ((u32)pll->vclk_fb_div) * pll->xclk_ref_div; 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci ras_multiplier = pll->xclkmaxrasdelay; 1318c2ecf20Sopenharmony_ci ras_divider = 1; 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci if (bpp>=8) 1348c2ecf20Sopenharmony_ci divider = divider * (bpp >> 2); 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci vshift = (6 - 2) - pll->xclk_post_div; /* FIFO is 64 bits wide in accelerator mode ... */ 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ci if (bpp == 0) 1398c2ecf20Sopenharmony_ci vshift--; /* ... but only 32 bits in VGA mode. */ 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_ci#ifdef CONFIG_FB_ATY_GENERIC_LCD 1428c2ecf20Sopenharmony_ci if (pll->xres != 0) { 1438c2ecf20Sopenharmony_ci struct atyfb_par *par = (struct atyfb_par *) info->par; 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci multiplier = multiplier * par->lcd_width; 1468c2ecf20Sopenharmony_ci divider = divider * pll->xres & ~7; 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci ras_multiplier = ras_multiplier * par->lcd_width; 1498c2ecf20Sopenharmony_ci ras_divider = ras_divider * pll->xres & ~7; 1508c2ecf20Sopenharmony_ci } 1518c2ecf20Sopenharmony_ci#endif 1528c2ecf20Sopenharmony_ci /* If we don't do this, 32 bits for multiplier & divider won't be 1538c2ecf20Sopenharmony_ci enough in certain situations! */ 1548c2ecf20Sopenharmony_ci while (((multiplier | divider) & 1) == 0) { 1558c2ecf20Sopenharmony_ci multiplier = multiplier >> 1; 1568c2ecf20Sopenharmony_ci divider = divider >> 1; 1578c2ecf20Sopenharmony_ci } 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci /* Determine DSP precision first */ 1608c2ecf20Sopenharmony_ci tmp = ((multiplier * pll->fifo_size) << vshift) / divider; 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_ci for (dsp_precision = -5; tmp; dsp_precision++) 1638c2ecf20Sopenharmony_ci tmp >>= 1; 1648c2ecf20Sopenharmony_ci if (dsp_precision < 0) 1658c2ecf20Sopenharmony_ci dsp_precision = 0; 1668c2ecf20Sopenharmony_ci else if (dsp_precision > Maximum_DSP_PRECISION) 1678c2ecf20Sopenharmony_ci dsp_precision = Maximum_DSP_PRECISION; 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_ci xshift = 6 - dsp_precision; 1708c2ecf20Sopenharmony_ci vshift += xshift; 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ci /* Move on to dsp_off */ 1738c2ecf20Sopenharmony_ci dsp_off = ((multiplier * (pll->fifo_size - 1)) << vshift) / divider - 1748c2ecf20Sopenharmony_ci (1 << (vshift - xshift)); 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci/* if (bpp == 0) 1778c2ecf20Sopenharmony_ci dsp_on = ((multiplier * 20 << vshift) + divider) / divider; 1788c2ecf20Sopenharmony_ci else */ 1798c2ecf20Sopenharmony_ci { 1808c2ecf20Sopenharmony_ci dsp_on = ((multiplier << vshift) + divider) / divider; 1818c2ecf20Sopenharmony_ci tmp = ((ras_multiplier << xshift) + ras_divider) / ras_divider; 1828c2ecf20Sopenharmony_ci if (dsp_on < tmp) 1838c2ecf20Sopenharmony_ci dsp_on = tmp; 1848c2ecf20Sopenharmony_ci dsp_on = dsp_on + (tmp * 2) + (pll->xclkpagefaultdelay << xshift); 1858c2ecf20Sopenharmony_ci } 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ci /* Calculate rounding factor and apply it to dsp_on */ 1888c2ecf20Sopenharmony_ci tmp = ((1 << (Maximum_DSP_PRECISION - dsp_precision)) - 1) >> 1; 1898c2ecf20Sopenharmony_ci dsp_on = ((dsp_on + tmp) / (tmp + 1)) * (tmp + 1); 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_ci if (dsp_on >= ((dsp_off / (tmp + 1)) * (tmp + 1))) { 1928c2ecf20Sopenharmony_ci dsp_on = dsp_off - (multiplier << vshift) / divider; 1938c2ecf20Sopenharmony_ci dsp_on = (dsp_on / (tmp + 1)) * (tmp + 1); 1948c2ecf20Sopenharmony_ci } 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_ci /* Last but not least: dsp_xclks */ 1978c2ecf20Sopenharmony_ci dsp_xclks = ((multiplier << (vshift + 5)) + divider) / divider; 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_ci /* Get register values. */ 2008c2ecf20Sopenharmony_ci pll->dsp_on_off = (dsp_on << 16) + dsp_off; 2018c2ecf20Sopenharmony_ci pll->dsp_config = (dsp_precision << 20) | (pll->dsp_loop_latency << 16) | dsp_xclks; 2028c2ecf20Sopenharmony_ci#ifdef DEBUG 2038c2ecf20Sopenharmony_ci printk("atyfb(%s): dsp_config 0x%08x, dsp_on_off 0x%08x\n", 2048c2ecf20Sopenharmony_ci __func__, pll->dsp_config, pll->dsp_on_off); 2058c2ecf20Sopenharmony_ci#endif 2068c2ecf20Sopenharmony_ci return 0; 2078c2ecf20Sopenharmony_ci} 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_cistatic int aty_valid_pll_ct(const struct fb_info *info, u32 vclk_per, struct pll_ct *pll) 2108c2ecf20Sopenharmony_ci{ 2118c2ecf20Sopenharmony_ci u32 q; 2128c2ecf20Sopenharmony_ci struct atyfb_par *par = (struct atyfb_par *) info->par; 2138c2ecf20Sopenharmony_ci int pllvclk; 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_ci /* FIXME: use the VTB/GTB /{3,6,12} post dividers if they're better suited */ 2168c2ecf20Sopenharmony_ci q = par->ref_clk_per * pll->pll_ref_div * 4 / vclk_per; 2178c2ecf20Sopenharmony_ci if (q < 16*8 || q > 255*8) { 2188c2ecf20Sopenharmony_ci printk(KERN_CRIT "atyfb: vclk out of range\n"); 2198c2ecf20Sopenharmony_ci return -EINVAL; 2208c2ecf20Sopenharmony_ci } else { 2218c2ecf20Sopenharmony_ci pll->vclk_post_div = (q < 128*8); 2228c2ecf20Sopenharmony_ci pll->vclk_post_div += (q < 64*8); 2238c2ecf20Sopenharmony_ci pll->vclk_post_div += (q < 32*8); 2248c2ecf20Sopenharmony_ci } 2258c2ecf20Sopenharmony_ci pll->vclk_post_div_real = aty_postdividers[pll->vclk_post_div]; 2268c2ecf20Sopenharmony_ci // pll->vclk_post_div <<= 6; 2278c2ecf20Sopenharmony_ci pll->vclk_fb_div = q * pll->vclk_post_div_real / 8; 2288c2ecf20Sopenharmony_ci pllvclk = (1000000 * 2 * pll->vclk_fb_div) / 2298c2ecf20Sopenharmony_ci (par->ref_clk_per * pll->pll_ref_div); 2308c2ecf20Sopenharmony_ci#ifdef DEBUG 2318c2ecf20Sopenharmony_ci printk("atyfb(%s): pllvclk=%d MHz, vclk=%d MHz\n", 2328c2ecf20Sopenharmony_ci __func__, pllvclk, pllvclk / pll->vclk_post_div_real); 2338c2ecf20Sopenharmony_ci#endif 2348c2ecf20Sopenharmony_ci pll->pll_vclk_cntl = 0x03; /* VCLK = PLL_VCLK/VCLKx_POST */ 2358c2ecf20Sopenharmony_ci 2368c2ecf20Sopenharmony_ci /* Set ECP (scaler/overlay clock) divider */ 2378c2ecf20Sopenharmony_ci if (par->pll_limits.ecp_max) { 2388c2ecf20Sopenharmony_ci int ecp = pllvclk / pll->vclk_post_div_real; 2398c2ecf20Sopenharmony_ci int ecp_div = 0; 2408c2ecf20Sopenharmony_ci 2418c2ecf20Sopenharmony_ci while (ecp > par->pll_limits.ecp_max && ecp_div < 2) { 2428c2ecf20Sopenharmony_ci ecp >>= 1; 2438c2ecf20Sopenharmony_ci ecp_div++; 2448c2ecf20Sopenharmony_ci } 2458c2ecf20Sopenharmony_ci pll->pll_vclk_cntl |= ecp_div << 4; 2468c2ecf20Sopenharmony_ci } 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_ci return 0; 2498c2ecf20Sopenharmony_ci} 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_cistatic int aty_var_to_pll_ct(const struct fb_info *info, u32 vclk_per, u32 bpp, union aty_pll *pll) 2528c2ecf20Sopenharmony_ci{ 2538c2ecf20Sopenharmony_ci struct atyfb_par *par = (struct atyfb_par *) info->par; 2548c2ecf20Sopenharmony_ci int err; 2558c2ecf20Sopenharmony_ci 2568c2ecf20Sopenharmony_ci if ((err = aty_valid_pll_ct(info, vclk_per, &pll->ct))) 2578c2ecf20Sopenharmony_ci return err; 2588c2ecf20Sopenharmony_ci if (M64_HAS(GTB_DSP) && (err = aty_dsp_gt(info, bpp, &pll->ct))) 2598c2ecf20Sopenharmony_ci return err; 2608c2ecf20Sopenharmony_ci /*aty_calc_pll_ct(info, &pll->ct);*/ 2618c2ecf20Sopenharmony_ci return 0; 2628c2ecf20Sopenharmony_ci} 2638c2ecf20Sopenharmony_ci 2648c2ecf20Sopenharmony_cistatic u32 aty_pll_to_var_ct(const struct fb_info *info, const union aty_pll *pll) 2658c2ecf20Sopenharmony_ci{ 2668c2ecf20Sopenharmony_ci struct atyfb_par *par = (struct atyfb_par *) info->par; 2678c2ecf20Sopenharmony_ci u32 ret; 2688c2ecf20Sopenharmony_ci ret = par->ref_clk_per * pll->ct.pll_ref_div * pll->ct.vclk_post_div_real / pll->ct.vclk_fb_div / 2; 2698c2ecf20Sopenharmony_ci#ifdef CONFIG_FB_ATY_GENERIC_LCD 2708c2ecf20Sopenharmony_ci if(pll->ct.xres > 0) { 2718c2ecf20Sopenharmony_ci ret *= par->lcd_width; 2728c2ecf20Sopenharmony_ci ret /= pll->ct.xres; 2738c2ecf20Sopenharmony_ci } 2748c2ecf20Sopenharmony_ci#endif 2758c2ecf20Sopenharmony_ci#ifdef DEBUG 2768c2ecf20Sopenharmony_ci printk("atyfb(%s): calculated 0x%08X(%i)\n", __func__, ret, ret); 2778c2ecf20Sopenharmony_ci#endif 2788c2ecf20Sopenharmony_ci return ret; 2798c2ecf20Sopenharmony_ci} 2808c2ecf20Sopenharmony_ci 2818c2ecf20Sopenharmony_civoid aty_set_pll_ct(const struct fb_info *info, const union aty_pll *pll) 2828c2ecf20Sopenharmony_ci{ 2838c2ecf20Sopenharmony_ci struct atyfb_par *par = (struct atyfb_par *) info->par; 2848c2ecf20Sopenharmony_ci u32 crtc_gen_cntl, lcd_gen_cntrl; 2858c2ecf20Sopenharmony_ci u8 tmp, tmp2; 2868c2ecf20Sopenharmony_ci 2878c2ecf20Sopenharmony_ci lcd_gen_cntrl = 0; 2888c2ecf20Sopenharmony_ci#ifdef DEBUG 2898c2ecf20Sopenharmony_ci printk("atyfb(%s): about to program:\n" 2908c2ecf20Sopenharmony_ci "pll_ext_cntl=0x%02x pll_gen_cntl=0x%02x pll_vclk_cntl=0x%02x\n", 2918c2ecf20Sopenharmony_ci __func__, 2928c2ecf20Sopenharmony_ci pll->ct.pll_ext_cntl, pll->ct.pll_gen_cntl, pll->ct.pll_vclk_cntl); 2938c2ecf20Sopenharmony_ci 2948c2ecf20Sopenharmony_ci printk("atyfb(%s): setting clock %lu for FeedBackDivider %i, ReferenceDivider %i, PostDivider %i(%i)\n", 2958c2ecf20Sopenharmony_ci __func__, 2968c2ecf20Sopenharmony_ci par->clk_wr_offset, pll->ct.vclk_fb_div, 2978c2ecf20Sopenharmony_ci pll->ct.pll_ref_div, pll->ct.vclk_post_div, pll->ct.vclk_post_div_real); 2988c2ecf20Sopenharmony_ci#endif 2998c2ecf20Sopenharmony_ci#ifdef CONFIG_FB_ATY_GENERIC_LCD 3008c2ecf20Sopenharmony_ci if (par->lcd_table != 0) { 3018c2ecf20Sopenharmony_ci /* turn off LCD */ 3028c2ecf20Sopenharmony_ci lcd_gen_cntrl = aty_ld_lcd(LCD_GEN_CNTL, par); 3038c2ecf20Sopenharmony_ci aty_st_lcd(LCD_GEN_CNTL, lcd_gen_cntrl & ~LCD_ON, par); 3048c2ecf20Sopenharmony_ci } 3058c2ecf20Sopenharmony_ci#endif 3068c2ecf20Sopenharmony_ci aty_st_8(CLOCK_CNTL, par->clk_wr_offset | CLOCK_STROBE, par); 3078c2ecf20Sopenharmony_ci 3088c2ecf20Sopenharmony_ci /* Temporarily switch to accelerator mode */ 3098c2ecf20Sopenharmony_ci crtc_gen_cntl = aty_ld_le32(CRTC_GEN_CNTL, par); 3108c2ecf20Sopenharmony_ci if (!(crtc_gen_cntl & CRTC_EXT_DISP_EN)) 3118c2ecf20Sopenharmony_ci aty_st_le32(CRTC_GEN_CNTL, crtc_gen_cntl | CRTC_EXT_DISP_EN, par); 3128c2ecf20Sopenharmony_ci 3138c2ecf20Sopenharmony_ci /* Reset VCLK generator */ 3148c2ecf20Sopenharmony_ci aty_st_pll_ct(PLL_VCLK_CNTL, pll->ct.pll_vclk_cntl, par); 3158c2ecf20Sopenharmony_ci 3168c2ecf20Sopenharmony_ci /* Set post-divider */ 3178c2ecf20Sopenharmony_ci tmp2 = par->clk_wr_offset << 1; 3188c2ecf20Sopenharmony_ci tmp = aty_ld_pll_ct(VCLK_POST_DIV, par); 3198c2ecf20Sopenharmony_ci tmp &= ~(0x03U << tmp2); 3208c2ecf20Sopenharmony_ci tmp |= ((pll->ct.vclk_post_div & 0x03U) << tmp2); 3218c2ecf20Sopenharmony_ci aty_st_pll_ct(VCLK_POST_DIV, tmp, par); 3228c2ecf20Sopenharmony_ci 3238c2ecf20Sopenharmony_ci /* Set extended post-divider */ 3248c2ecf20Sopenharmony_ci tmp = aty_ld_pll_ct(PLL_EXT_CNTL, par); 3258c2ecf20Sopenharmony_ci tmp &= ~(0x10U << par->clk_wr_offset); 3268c2ecf20Sopenharmony_ci tmp &= 0xF0U; 3278c2ecf20Sopenharmony_ci tmp |= pll->ct.pll_ext_cntl; 3288c2ecf20Sopenharmony_ci aty_st_pll_ct(PLL_EXT_CNTL, tmp, par); 3298c2ecf20Sopenharmony_ci 3308c2ecf20Sopenharmony_ci /* Set feedback divider */ 3318c2ecf20Sopenharmony_ci tmp = VCLK0_FB_DIV + par->clk_wr_offset; 3328c2ecf20Sopenharmony_ci aty_st_pll_ct(tmp, (pll->ct.vclk_fb_div & 0xFFU), par); 3338c2ecf20Sopenharmony_ci 3348c2ecf20Sopenharmony_ci aty_st_pll_ct(PLL_GEN_CNTL, (pll->ct.pll_gen_cntl & (~(PLL_OVERRIDE | PLL_MCLK_RST))) | OSC_EN, par); 3358c2ecf20Sopenharmony_ci 3368c2ecf20Sopenharmony_ci /* End VCLK generator reset */ 3378c2ecf20Sopenharmony_ci aty_st_pll_ct(PLL_VCLK_CNTL, pll->ct.pll_vclk_cntl & ~(PLL_VCLK_RST), par); 3388c2ecf20Sopenharmony_ci mdelay(5); 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_ci aty_st_pll_ct(PLL_GEN_CNTL, pll->ct.pll_gen_cntl, par); 3418c2ecf20Sopenharmony_ci aty_st_pll_ct(PLL_VCLK_CNTL, pll->ct.pll_vclk_cntl, par); 3428c2ecf20Sopenharmony_ci mdelay(1); 3438c2ecf20Sopenharmony_ci 3448c2ecf20Sopenharmony_ci /* Restore mode register */ 3458c2ecf20Sopenharmony_ci if (!(crtc_gen_cntl & CRTC_EXT_DISP_EN)) 3468c2ecf20Sopenharmony_ci aty_st_le32(CRTC_GEN_CNTL, crtc_gen_cntl, par); 3478c2ecf20Sopenharmony_ci 3488c2ecf20Sopenharmony_ci if (M64_HAS(GTB_DSP)) { 3498c2ecf20Sopenharmony_ci u8 dll_cntl; 3508c2ecf20Sopenharmony_ci 3518c2ecf20Sopenharmony_ci if (M64_HAS(XL_DLL)) 3528c2ecf20Sopenharmony_ci dll_cntl = 0x80; 3538c2ecf20Sopenharmony_ci else if (par->ram_type >= SDRAM) 3548c2ecf20Sopenharmony_ci dll_cntl = 0xa6; 3558c2ecf20Sopenharmony_ci else 3568c2ecf20Sopenharmony_ci dll_cntl = 0xa0; 3578c2ecf20Sopenharmony_ci aty_st_pll_ct(DLL_CNTL, dll_cntl, par); 3588c2ecf20Sopenharmony_ci aty_st_pll_ct(VFC_CNTL, 0x1b, par); 3598c2ecf20Sopenharmony_ci aty_st_le32(DSP_CONFIG, pll->ct.dsp_config, par); 3608c2ecf20Sopenharmony_ci aty_st_le32(DSP_ON_OFF, pll->ct.dsp_on_off, par); 3618c2ecf20Sopenharmony_ci 3628c2ecf20Sopenharmony_ci mdelay(10); 3638c2ecf20Sopenharmony_ci aty_st_pll_ct(DLL_CNTL, dll_cntl, par); 3648c2ecf20Sopenharmony_ci mdelay(10); 3658c2ecf20Sopenharmony_ci aty_st_pll_ct(DLL_CNTL, dll_cntl | 0x40, par); 3668c2ecf20Sopenharmony_ci mdelay(10); 3678c2ecf20Sopenharmony_ci aty_st_pll_ct(DLL_CNTL, dll_cntl & ~0x40, par); 3688c2ecf20Sopenharmony_ci } 3698c2ecf20Sopenharmony_ci#ifdef CONFIG_FB_ATY_GENERIC_LCD 3708c2ecf20Sopenharmony_ci if (par->lcd_table != 0) { 3718c2ecf20Sopenharmony_ci /* restore LCD */ 3728c2ecf20Sopenharmony_ci aty_st_lcd(LCD_GEN_CNTL, lcd_gen_cntrl, par); 3738c2ecf20Sopenharmony_ci } 3748c2ecf20Sopenharmony_ci#endif 3758c2ecf20Sopenharmony_ci} 3768c2ecf20Sopenharmony_ci 3778c2ecf20Sopenharmony_cistatic void aty_get_pll_ct(const struct fb_info *info, union aty_pll *pll) 3788c2ecf20Sopenharmony_ci{ 3798c2ecf20Sopenharmony_ci struct atyfb_par *par = (struct atyfb_par *) info->par; 3808c2ecf20Sopenharmony_ci u8 tmp, clock; 3818c2ecf20Sopenharmony_ci 3828c2ecf20Sopenharmony_ci clock = aty_ld_8(CLOCK_CNTL, par) & 0x03U; 3838c2ecf20Sopenharmony_ci tmp = clock << 1; 3848c2ecf20Sopenharmony_ci pll->ct.vclk_post_div = (aty_ld_pll_ct(VCLK_POST_DIV, par) >> tmp) & 0x03U; 3858c2ecf20Sopenharmony_ci 3868c2ecf20Sopenharmony_ci pll->ct.pll_ext_cntl = aty_ld_pll_ct(PLL_EXT_CNTL, par) & 0x0FU; 3878c2ecf20Sopenharmony_ci pll->ct.vclk_fb_div = aty_ld_pll_ct(VCLK0_FB_DIV + clock, par) & 0xFFU; 3888c2ecf20Sopenharmony_ci pll->ct.pll_ref_div = aty_ld_pll_ct(PLL_REF_DIV, par); 3898c2ecf20Sopenharmony_ci pll->ct.mclk_fb_div = aty_ld_pll_ct(MCLK_FB_DIV, par); 3908c2ecf20Sopenharmony_ci 3918c2ecf20Sopenharmony_ci pll->ct.pll_gen_cntl = aty_ld_pll_ct(PLL_GEN_CNTL, par); 3928c2ecf20Sopenharmony_ci pll->ct.pll_vclk_cntl = aty_ld_pll_ct(PLL_VCLK_CNTL, par); 3938c2ecf20Sopenharmony_ci 3948c2ecf20Sopenharmony_ci if (M64_HAS(GTB_DSP)) { 3958c2ecf20Sopenharmony_ci pll->ct.dsp_config = aty_ld_le32(DSP_CONFIG, par); 3968c2ecf20Sopenharmony_ci pll->ct.dsp_on_off = aty_ld_le32(DSP_ON_OFF, par); 3978c2ecf20Sopenharmony_ci } 3988c2ecf20Sopenharmony_ci} 3998c2ecf20Sopenharmony_ci 4008c2ecf20Sopenharmony_cistatic int aty_init_pll_ct(const struct fb_info *info, union aty_pll *pll) 4018c2ecf20Sopenharmony_ci{ 4028c2ecf20Sopenharmony_ci struct atyfb_par *par = (struct atyfb_par *) info->par; 4038c2ecf20Sopenharmony_ci u8 mpost_div, xpost_div, sclk_post_div_real; 4048c2ecf20Sopenharmony_ci u32 q, memcntl, trp; 4058c2ecf20Sopenharmony_ci u32 dsp_config, dsp_on_off, vga_dsp_config, vga_dsp_on_off; 4068c2ecf20Sopenharmony_ci#ifdef DEBUG 4078c2ecf20Sopenharmony_ci int pllmclk, pllsclk; 4088c2ecf20Sopenharmony_ci#endif 4098c2ecf20Sopenharmony_ci pll->ct.pll_ext_cntl = aty_ld_pll_ct(PLL_EXT_CNTL, par); 4108c2ecf20Sopenharmony_ci pll->ct.xclk_post_div = pll->ct.pll_ext_cntl & 0x07; 4118c2ecf20Sopenharmony_ci pll->ct.xclk_ref_div = 1; 4128c2ecf20Sopenharmony_ci switch (pll->ct.xclk_post_div) { 4138c2ecf20Sopenharmony_ci case 0: case 1: case 2: case 3: 4148c2ecf20Sopenharmony_ci break; 4158c2ecf20Sopenharmony_ci 4168c2ecf20Sopenharmony_ci case 4: 4178c2ecf20Sopenharmony_ci pll->ct.xclk_ref_div = 3; 4188c2ecf20Sopenharmony_ci pll->ct.xclk_post_div = 0; 4198c2ecf20Sopenharmony_ci break; 4208c2ecf20Sopenharmony_ci 4218c2ecf20Sopenharmony_ci default: 4228c2ecf20Sopenharmony_ci printk(KERN_CRIT "atyfb: Unsupported xclk source: %d.\n", pll->ct.xclk_post_div); 4238c2ecf20Sopenharmony_ci return -EINVAL; 4248c2ecf20Sopenharmony_ci } 4258c2ecf20Sopenharmony_ci pll->ct.mclk_fb_mult = 2; 4268c2ecf20Sopenharmony_ci if(pll->ct.pll_ext_cntl & PLL_MFB_TIMES_4_2B) { 4278c2ecf20Sopenharmony_ci pll->ct.mclk_fb_mult = 4; 4288c2ecf20Sopenharmony_ci pll->ct.xclk_post_div -= 1; 4298c2ecf20Sopenharmony_ci } 4308c2ecf20Sopenharmony_ci 4318c2ecf20Sopenharmony_ci#ifdef DEBUG 4328c2ecf20Sopenharmony_ci printk("atyfb(%s): mclk_fb_mult=%d, xclk_post_div=%d\n", 4338c2ecf20Sopenharmony_ci __func__, pll->ct.mclk_fb_mult, pll->ct.xclk_post_div); 4348c2ecf20Sopenharmony_ci#endif 4358c2ecf20Sopenharmony_ci 4368c2ecf20Sopenharmony_ci memcntl = aty_ld_le32(MEM_CNTL, par); 4378c2ecf20Sopenharmony_ci trp = (memcntl & 0x300) >> 8; 4388c2ecf20Sopenharmony_ci 4398c2ecf20Sopenharmony_ci pll->ct.xclkpagefaultdelay = ((memcntl & 0xc00) >> 10) + ((memcntl & 0x1000) >> 12) + trp + 2; 4408c2ecf20Sopenharmony_ci pll->ct.xclkmaxrasdelay = ((memcntl & 0x70000) >> 16) + trp + 2; 4418c2ecf20Sopenharmony_ci 4428c2ecf20Sopenharmony_ci if (M64_HAS(FIFO_32)) { 4438c2ecf20Sopenharmony_ci pll->ct.fifo_size = 32; 4448c2ecf20Sopenharmony_ci } else { 4458c2ecf20Sopenharmony_ci pll->ct.fifo_size = 24; 4468c2ecf20Sopenharmony_ci pll->ct.xclkpagefaultdelay += 2; 4478c2ecf20Sopenharmony_ci pll->ct.xclkmaxrasdelay += 3; 4488c2ecf20Sopenharmony_ci } 4498c2ecf20Sopenharmony_ci 4508c2ecf20Sopenharmony_ci switch (par->ram_type) { 4518c2ecf20Sopenharmony_ci case DRAM: 4528c2ecf20Sopenharmony_ci if (info->fix.smem_len<=ONE_MB) { 4538c2ecf20Sopenharmony_ci pll->ct.dsp_loop_latency = 10; 4548c2ecf20Sopenharmony_ci } else { 4558c2ecf20Sopenharmony_ci pll->ct.dsp_loop_latency = 8; 4568c2ecf20Sopenharmony_ci pll->ct.xclkpagefaultdelay += 2; 4578c2ecf20Sopenharmony_ci } 4588c2ecf20Sopenharmony_ci break; 4598c2ecf20Sopenharmony_ci case EDO: 4608c2ecf20Sopenharmony_ci case PSEUDO_EDO: 4618c2ecf20Sopenharmony_ci if (info->fix.smem_len<=ONE_MB) { 4628c2ecf20Sopenharmony_ci pll->ct.dsp_loop_latency = 9; 4638c2ecf20Sopenharmony_ci } else { 4648c2ecf20Sopenharmony_ci pll->ct.dsp_loop_latency = 8; 4658c2ecf20Sopenharmony_ci pll->ct.xclkpagefaultdelay += 1; 4668c2ecf20Sopenharmony_ci } 4678c2ecf20Sopenharmony_ci break; 4688c2ecf20Sopenharmony_ci case SDRAM: 4698c2ecf20Sopenharmony_ci if (info->fix.smem_len<=ONE_MB) { 4708c2ecf20Sopenharmony_ci pll->ct.dsp_loop_latency = 11; 4718c2ecf20Sopenharmony_ci } else { 4728c2ecf20Sopenharmony_ci pll->ct.dsp_loop_latency = 10; 4738c2ecf20Sopenharmony_ci pll->ct.xclkpagefaultdelay += 1; 4748c2ecf20Sopenharmony_ci } 4758c2ecf20Sopenharmony_ci break; 4768c2ecf20Sopenharmony_ci case SGRAM: 4778c2ecf20Sopenharmony_ci pll->ct.dsp_loop_latency = 8; 4788c2ecf20Sopenharmony_ci pll->ct.xclkpagefaultdelay += 3; 4798c2ecf20Sopenharmony_ci break; 4808c2ecf20Sopenharmony_ci default: 4818c2ecf20Sopenharmony_ci pll->ct.dsp_loop_latency = 11; 4828c2ecf20Sopenharmony_ci pll->ct.xclkpagefaultdelay += 3; 4838c2ecf20Sopenharmony_ci break; 4848c2ecf20Sopenharmony_ci } 4858c2ecf20Sopenharmony_ci 4868c2ecf20Sopenharmony_ci if (pll->ct.xclkmaxrasdelay <= pll->ct.xclkpagefaultdelay) 4878c2ecf20Sopenharmony_ci pll->ct.xclkmaxrasdelay = pll->ct.xclkpagefaultdelay + 1; 4888c2ecf20Sopenharmony_ci 4898c2ecf20Sopenharmony_ci /* Allow BIOS to override */ 4908c2ecf20Sopenharmony_ci dsp_config = aty_ld_le32(DSP_CONFIG, par); 4918c2ecf20Sopenharmony_ci dsp_on_off = aty_ld_le32(DSP_ON_OFF, par); 4928c2ecf20Sopenharmony_ci vga_dsp_config = aty_ld_le32(VGA_DSP_CONFIG, par); 4938c2ecf20Sopenharmony_ci vga_dsp_on_off = aty_ld_le32(VGA_DSP_ON_OFF, par); 4948c2ecf20Sopenharmony_ci 4958c2ecf20Sopenharmony_ci if (dsp_config) 4968c2ecf20Sopenharmony_ci pll->ct.dsp_loop_latency = (dsp_config & DSP_LOOP_LATENCY) >> 16; 4978c2ecf20Sopenharmony_ci#if 0 4988c2ecf20Sopenharmony_ci FIXME: is it relevant for us? 4998c2ecf20Sopenharmony_ci if ((!dsp_on_off && !M64_HAS(RESET_3D)) || 5008c2ecf20Sopenharmony_ci ((dsp_on_off == vga_dsp_on_off) && 5018c2ecf20Sopenharmony_ci (!dsp_config || !((dsp_config ^ vga_dsp_config) & DSP_XCLKS_PER_QW)))) { 5028c2ecf20Sopenharmony_ci vga_dsp_on_off &= VGA_DSP_OFF; 5038c2ecf20Sopenharmony_ci vga_dsp_config &= VGA_DSP_XCLKS_PER_QW; 5048c2ecf20Sopenharmony_ci if (ATIDivide(vga_dsp_on_off, vga_dsp_config, 5, 1) > 24) 5058c2ecf20Sopenharmony_ci pll->ct.fifo_size = 32; 5068c2ecf20Sopenharmony_ci else 5078c2ecf20Sopenharmony_ci pll->ct.fifo_size = 24; 5088c2ecf20Sopenharmony_ci } 5098c2ecf20Sopenharmony_ci#endif 5108c2ecf20Sopenharmony_ci /* Exit if the user does not want us to tamper with the clock 5118c2ecf20Sopenharmony_ci rates of her chip. */ 5128c2ecf20Sopenharmony_ci if (par->mclk_per == 0) { 5138c2ecf20Sopenharmony_ci u8 mclk_fb_div, pll_ext_cntl; 5148c2ecf20Sopenharmony_ci pll->ct.pll_ref_div = aty_ld_pll_ct(PLL_REF_DIV, par); 5158c2ecf20Sopenharmony_ci pll_ext_cntl = aty_ld_pll_ct(PLL_EXT_CNTL, par); 5168c2ecf20Sopenharmony_ci pll->ct.xclk_post_div_real = aty_postdividers[pll_ext_cntl & 0x07]; 5178c2ecf20Sopenharmony_ci mclk_fb_div = aty_ld_pll_ct(MCLK_FB_DIV, par); 5188c2ecf20Sopenharmony_ci if (pll_ext_cntl & PLL_MFB_TIMES_4_2B) 5198c2ecf20Sopenharmony_ci mclk_fb_div <<= 1; 5208c2ecf20Sopenharmony_ci pll->ct.mclk_fb_div = mclk_fb_div; 5218c2ecf20Sopenharmony_ci return 0; 5228c2ecf20Sopenharmony_ci } 5238c2ecf20Sopenharmony_ci 5248c2ecf20Sopenharmony_ci pll->ct.pll_ref_div = par->pll_per * 2 * 255 / par->ref_clk_per; 5258c2ecf20Sopenharmony_ci 5268c2ecf20Sopenharmony_ci /* FIXME: use the VTB/GTB /3 post divider if it's better suited */ 5278c2ecf20Sopenharmony_ci q = par->ref_clk_per * pll->ct.pll_ref_div * 8 / 5288c2ecf20Sopenharmony_ci (pll->ct.mclk_fb_mult * par->xclk_per); 5298c2ecf20Sopenharmony_ci 5308c2ecf20Sopenharmony_ci if (q < 16*8 || q > 255*8) { 5318c2ecf20Sopenharmony_ci printk(KERN_CRIT "atxfb: xclk out of range\n"); 5328c2ecf20Sopenharmony_ci return -EINVAL; 5338c2ecf20Sopenharmony_ci } else { 5348c2ecf20Sopenharmony_ci xpost_div = (q < 128*8); 5358c2ecf20Sopenharmony_ci xpost_div += (q < 64*8); 5368c2ecf20Sopenharmony_ci xpost_div += (q < 32*8); 5378c2ecf20Sopenharmony_ci } 5388c2ecf20Sopenharmony_ci pll->ct.xclk_post_div_real = aty_postdividers[xpost_div]; 5398c2ecf20Sopenharmony_ci pll->ct.mclk_fb_div = q * pll->ct.xclk_post_div_real / 8; 5408c2ecf20Sopenharmony_ci 5418c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC 5428c2ecf20Sopenharmony_ci if (machine_is(powermac)) { 5438c2ecf20Sopenharmony_ci /* Override PLL_EXT_CNTL & 0x07. */ 5448c2ecf20Sopenharmony_ci pll->ct.xclk_post_div = xpost_div; 5458c2ecf20Sopenharmony_ci pll->ct.xclk_ref_div = 1; 5468c2ecf20Sopenharmony_ci } 5478c2ecf20Sopenharmony_ci#endif 5488c2ecf20Sopenharmony_ci 5498c2ecf20Sopenharmony_ci#ifdef DEBUG 5508c2ecf20Sopenharmony_ci pllmclk = (1000000 * pll->ct.mclk_fb_mult * pll->ct.mclk_fb_div) / 5518c2ecf20Sopenharmony_ci (par->ref_clk_per * pll->ct.pll_ref_div); 5528c2ecf20Sopenharmony_ci printk("atyfb(%s): pllmclk=%d MHz, xclk=%d MHz\n", 5538c2ecf20Sopenharmony_ci __func__, pllmclk, pllmclk / pll->ct.xclk_post_div_real); 5548c2ecf20Sopenharmony_ci#endif 5558c2ecf20Sopenharmony_ci 5568c2ecf20Sopenharmony_ci if (M64_HAS(SDRAM_MAGIC_PLL) && (par->ram_type >= SDRAM)) 5578c2ecf20Sopenharmony_ci pll->ct.pll_gen_cntl = OSC_EN; 5588c2ecf20Sopenharmony_ci else 5598c2ecf20Sopenharmony_ci pll->ct.pll_gen_cntl = OSC_EN | DLL_PWDN /* | FORCE_DCLK_TRI_STATE */; 5608c2ecf20Sopenharmony_ci 5618c2ecf20Sopenharmony_ci if (M64_HAS(MAGIC_POSTDIV)) 5628c2ecf20Sopenharmony_ci pll->ct.pll_ext_cntl = 0; 5638c2ecf20Sopenharmony_ci else 5648c2ecf20Sopenharmony_ci pll->ct.pll_ext_cntl = xpost_div; 5658c2ecf20Sopenharmony_ci 5668c2ecf20Sopenharmony_ci if (pll->ct.mclk_fb_mult == 4) 5678c2ecf20Sopenharmony_ci pll->ct.pll_ext_cntl |= PLL_MFB_TIMES_4_2B; 5688c2ecf20Sopenharmony_ci 5698c2ecf20Sopenharmony_ci if (par->mclk_per == par->xclk_per) { 5708c2ecf20Sopenharmony_ci pll->ct.pll_gen_cntl |= (xpost_div << 4); /* mclk == xclk */ 5718c2ecf20Sopenharmony_ci } else { 5728c2ecf20Sopenharmony_ci /* 5738c2ecf20Sopenharmony_ci * The chip clock is not equal to the memory clock. 5748c2ecf20Sopenharmony_ci * Therefore we will use sclk to clock the chip. 5758c2ecf20Sopenharmony_ci */ 5768c2ecf20Sopenharmony_ci pll->ct.pll_gen_cntl |= (6 << 4); /* mclk == sclk */ 5778c2ecf20Sopenharmony_ci 5788c2ecf20Sopenharmony_ci q = par->ref_clk_per * pll->ct.pll_ref_div * 4 / par->mclk_per; 5798c2ecf20Sopenharmony_ci if (q < 16*8 || q > 255*8) { 5808c2ecf20Sopenharmony_ci printk(KERN_CRIT "atyfb: mclk out of range\n"); 5818c2ecf20Sopenharmony_ci return -EINVAL; 5828c2ecf20Sopenharmony_ci } else { 5838c2ecf20Sopenharmony_ci mpost_div = (q < 128*8); 5848c2ecf20Sopenharmony_ci mpost_div += (q < 64*8); 5858c2ecf20Sopenharmony_ci mpost_div += (q < 32*8); 5868c2ecf20Sopenharmony_ci } 5878c2ecf20Sopenharmony_ci sclk_post_div_real = aty_postdividers[mpost_div]; 5888c2ecf20Sopenharmony_ci pll->ct.sclk_fb_div = q * sclk_post_div_real / 8; 5898c2ecf20Sopenharmony_ci pll->ct.spll_cntl2 = mpost_div << 4; 5908c2ecf20Sopenharmony_ci#ifdef DEBUG 5918c2ecf20Sopenharmony_ci pllsclk = (1000000 * 2 * pll->ct.sclk_fb_div) / 5928c2ecf20Sopenharmony_ci (par->ref_clk_per * pll->ct.pll_ref_div); 5938c2ecf20Sopenharmony_ci printk("atyfb(%s): use sclk, pllsclk=%d MHz, sclk=mclk=%d MHz\n", 5948c2ecf20Sopenharmony_ci __func__, pllsclk, pllsclk / sclk_post_div_real); 5958c2ecf20Sopenharmony_ci#endif 5968c2ecf20Sopenharmony_ci } 5978c2ecf20Sopenharmony_ci 5988c2ecf20Sopenharmony_ci /* Disable the extra precision pixel clock controls since we do not use them. */ 5998c2ecf20Sopenharmony_ci pll->ct.ext_vpll_cntl = aty_ld_pll_ct(EXT_VPLL_CNTL, par); 6008c2ecf20Sopenharmony_ci pll->ct.ext_vpll_cntl &= ~(EXT_VPLL_EN | EXT_VPLL_VGA_EN | EXT_VPLL_INSYNC); 6018c2ecf20Sopenharmony_ci 6028c2ecf20Sopenharmony_ci return 0; 6038c2ecf20Sopenharmony_ci} 6048c2ecf20Sopenharmony_ci 6058c2ecf20Sopenharmony_cistatic void aty_resume_pll_ct(const struct fb_info *info, 6068c2ecf20Sopenharmony_ci union aty_pll *pll) 6078c2ecf20Sopenharmony_ci{ 6088c2ecf20Sopenharmony_ci struct atyfb_par *par = info->par; 6098c2ecf20Sopenharmony_ci 6108c2ecf20Sopenharmony_ci if (par->mclk_per != par->xclk_per) { 6118c2ecf20Sopenharmony_ci /* 6128c2ecf20Sopenharmony_ci * This disables the sclk, crashes the computer as reported: 6138c2ecf20Sopenharmony_ci * aty_st_pll_ct(SPLL_CNTL2, 3, info); 6148c2ecf20Sopenharmony_ci * 6158c2ecf20Sopenharmony_ci * So it seems the sclk must be enabled before it is used; 6168c2ecf20Sopenharmony_ci * so PLL_GEN_CNTL must be programmed *after* the sclk. 6178c2ecf20Sopenharmony_ci */ 6188c2ecf20Sopenharmony_ci aty_st_pll_ct(SCLK_FB_DIV, pll->ct.sclk_fb_div, par); 6198c2ecf20Sopenharmony_ci aty_st_pll_ct(SPLL_CNTL2, pll->ct.spll_cntl2, par); 6208c2ecf20Sopenharmony_ci /* 6218c2ecf20Sopenharmony_ci * SCLK has been started. Wait for the PLL to lock. 5 ms 6228c2ecf20Sopenharmony_ci * should be enough according to mach64 programmer's guide. 6238c2ecf20Sopenharmony_ci */ 6248c2ecf20Sopenharmony_ci mdelay(5); 6258c2ecf20Sopenharmony_ci } 6268c2ecf20Sopenharmony_ci 6278c2ecf20Sopenharmony_ci aty_st_pll_ct(PLL_REF_DIV, pll->ct.pll_ref_div, par); 6288c2ecf20Sopenharmony_ci aty_st_pll_ct(PLL_GEN_CNTL, pll->ct.pll_gen_cntl, par); 6298c2ecf20Sopenharmony_ci aty_st_pll_ct(MCLK_FB_DIV, pll->ct.mclk_fb_div, par); 6308c2ecf20Sopenharmony_ci aty_st_pll_ct(PLL_EXT_CNTL, pll->ct.pll_ext_cntl, par); 6318c2ecf20Sopenharmony_ci aty_st_pll_ct(EXT_VPLL_CNTL, pll->ct.ext_vpll_cntl, par); 6328c2ecf20Sopenharmony_ci} 6338c2ecf20Sopenharmony_ci 6348c2ecf20Sopenharmony_cistatic int dummy(void) 6358c2ecf20Sopenharmony_ci{ 6368c2ecf20Sopenharmony_ci return 0; 6378c2ecf20Sopenharmony_ci} 6388c2ecf20Sopenharmony_ci 6398c2ecf20Sopenharmony_ciconst struct aty_dac_ops aty_dac_ct = { 6408c2ecf20Sopenharmony_ci .set_dac = (void *) dummy, 6418c2ecf20Sopenharmony_ci}; 6428c2ecf20Sopenharmony_ci 6438c2ecf20Sopenharmony_ciconst struct aty_pll_ops aty_pll_ct = { 6448c2ecf20Sopenharmony_ci .var_to_pll = aty_var_to_pll_ct, 6458c2ecf20Sopenharmony_ci .pll_to_var = aty_pll_to_var_ct, 6468c2ecf20Sopenharmony_ci .set_pll = aty_set_pll_ct, 6478c2ecf20Sopenharmony_ci .get_pll = aty_get_pll_ct, 6488c2ecf20Sopenharmony_ci .init_pll = aty_init_pll_ct, 6498c2ecf20Sopenharmony_ci .resume_pll = aty_resume_pll_ct, 6508c2ecf20Sopenharmony_ci}; 651