18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright 2008 Advanced Micro Devices, Inc.
38c2ecf20Sopenharmony_ci * Copyright 2008 Red Hat Inc.
48c2ecf20Sopenharmony_ci * Copyright 2009 Jerome Glisse.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
78c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
88c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation
98c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
108c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
118c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
128c2ecf20Sopenharmony_ci *
138c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice shall be included in
148c2ecf20Sopenharmony_ci * all copies or substantial portions of the Software.
158c2ecf20Sopenharmony_ci *
168c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
178c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
188c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
198c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
208c2ecf20Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
218c2ecf20Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
228c2ecf20Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE.
238c2ecf20Sopenharmony_ci *
248c2ecf20Sopenharmony_ci * Authors: Dave Airlie
258c2ecf20Sopenharmony_ci *          Alex Deucher
268c2ecf20Sopenharmony_ci *          Jerome Glisse
278c2ecf20Sopenharmony_ci */
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci#include <linux/pci.h>
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci#include <drm/drm_device.h>
328c2ecf20Sopenharmony_ci#include <drm/radeon_drm.h>
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#include "atom.h"
358c2ecf20Sopenharmony_ci#include "radeon.h"
368c2ecf20Sopenharmony_ci#include "radeon_asic.h"
378c2ecf20Sopenharmony_ci#include "radeon_reg.h"
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci/* 10 khz */
408c2ecf20Sopenharmony_ciuint32_t radeon_legacy_get_engine_clock(struct radeon_device *rdev)
418c2ecf20Sopenharmony_ci{
428c2ecf20Sopenharmony_ci	struct radeon_pll *spll = &rdev->clock.spll;
438c2ecf20Sopenharmony_ci	uint32_t fb_div, ref_div, post_div, sclk;
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci	fb_div = RREG32_PLL(RADEON_M_SPLL_REF_FB_DIV);
468c2ecf20Sopenharmony_ci	fb_div = (fb_div >> RADEON_SPLL_FB_DIV_SHIFT) & RADEON_SPLL_FB_DIV_MASK;
478c2ecf20Sopenharmony_ci	fb_div <<= 1;
488c2ecf20Sopenharmony_ci	fb_div *= spll->reference_freq;
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci	ref_div =
518c2ecf20Sopenharmony_ci	    RREG32_PLL(RADEON_M_SPLL_REF_FB_DIV) & RADEON_M_SPLL_REF_DIV_MASK;
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci	if (ref_div == 0)
548c2ecf20Sopenharmony_ci		return 0;
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci	sclk = fb_div / ref_div;
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci	post_div = RREG32_PLL(RADEON_SCLK_CNTL) & RADEON_SCLK_SRC_SEL_MASK;
598c2ecf20Sopenharmony_ci	if (post_div == 2)
608c2ecf20Sopenharmony_ci		sclk >>= 1;
618c2ecf20Sopenharmony_ci	else if (post_div == 3)
628c2ecf20Sopenharmony_ci		sclk >>= 2;
638c2ecf20Sopenharmony_ci	else if (post_div == 4)
648c2ecf20Sopenharmony_ci		sclk >>= 3;
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci	return sclk;
678c2ecf20Sopenharmony_ci}
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci/* 10 khz */
708c2ecf20Sopenharmony_ciuint32_t radeon_legacy_get_memory_clock(struct radeon_device *rdev)
718c2ecf20Sopenharmony_ci{
728c2ecf20Sopenharmony_ci	struct radeon_pll *mpll = &rdev->clock.mpll;
738c2ecf20Sopenharmony_ci	uint32_t fb_div, ref_div, post_div, mclk;
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci	fb_div = RREG32_PLL(RADEON_M_SPLL_REF_FB_DIV);
768c2ecf20Sopenharmony_ci	fb_div = (fb_div >> RADEON_MPLL_FB_DIV_SHIFT) & RADEON_MPLL_FB_DIV_MASK;
778c2ecf20Sopenharmony_ci	fb_div <<= 1;
788c2ecf20Sopenharmony_ci	fb_div *= mpll->reference_freq;
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci	ref_div =
818c2ecf20Sopenharmony_ci	    RREG32_PLL(RADEON_M_SPLL_REF_FB_DIV) & RADEON_M_SPLL_REF_DIV_MASK;
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci	if (ref_div == 0)
848c2ecf20Sopenharmony_ci		return 0;
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci	mclk = fb_div / ref_div;
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci	post_div = RREG32_PLL(RADEON_MCLK_CNTL) & 0x7;
898c2ecf20Sopenharmony_ci	if (post_div == 2)
908c2ecf20Sopenharmony_ci		mclk >>= 1;
918c2ecf20Sopenharmony_ci	else if (post_div == 3)
928c2ecf20Sopenharmony_ci		mclk >>= 2;
938c2ecf20Sopenharmony_ci	else if (post_div == 4)
948c2ecf20Sopenharmony_ci		mclk >>= 3;
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci	return mclk;
978c2ecf20Sopenharmony_ci}
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci#ifdef CONFIG_OF
1008c2ecf20Sopenharmony_ci/*
1018c2ecf20Sopenharmony_ci * Read XTAL (ref clock), SCLK and MCLK from Open Firmware device
1028c2ecf20Sopenharmony_ci * tree. Hopefully, ATI OF driver is kind enough to fill these
1038c2ecf20Sopenharmony_ci */
1048c2ecf20Sopenharmony_cistatic bool radeon_read_clocks_OF(struct drm_device *dev)
1058c2ecf20Sopenharmony_ci{
1068c2ecf20Sopenharmony_ci	struct radeon_device *rdev = dev->dev_private;
1078c2ecf20Sopenharmony_ci	struct device_node *dp = rdev->pdev->dev.of_node;
1088c2ecf20Sopenharmony_ci	const u32 *val;
1098c2ecf20Sopenharmony_ci	struct radeon_pll *p1pll = &rdev->clock.p1pll;
1108c2ecf20Sopenharmony_ci	struct radeon_pll *p2pll = &rdev->clock.p2pll;
1118c2ecf20Sopenharmony_ci	struct radeon_pll *spll = &rdev->clock.spll;
1128c2ecf20Sopenharmony_ci	struct radeon_pll *mpll = &rdev->clock.mpll;
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci	if (dp == NULL)
1158c2ecf20Sopenharmony_ci		return false;
1168c2ecf20Sopenharmony_ci	val = of_get_property(dp, "ATY,RefCLK", NULL);
1178c2ecf20Sopenharmony_ci	if (!val || !*val) {
1188c2ecf20Sopenharmony_ci		pr_warn("radeonfb: No ATY,RefCLK property !\n");
1198c2ecf20Sopenharmony_ci		return false;
1208c2ecf20Sopenharmony_ci	}
1218c2ecf20Sopenharmony_ci	p1pll->reference_freq = p2pll->reference_freq = (*val) / 10;
1228c2ecf20Sopenharmony_ci	p1pll->reference_div = RREG32_PLL(RADEON_PPLL_REF_DIV) & 0x3ff;
1238c2ecf20Sopenharmony_ci	if (p1pll->reference_div < 2)
1248c2ecf20Sopenharmony_ci		p1pll->reference_div = 12;
1258c2ecf20Sopenharmony_ci	p2pll->reference_div = p1pll->reference_div;
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci	/* These aren't in the device-tree */
1288c2ecf20Sopenharmony_ci	if (rdev->family >= CHIP_R420) {
1298c2ecf20Sopenharmony_ci		p1pll->pll_in_min = 100;
1308c2ecf20Sopenharmony_ci		p1pll->pll_in_max = 1350;
1318c2ecf20Sopenharmony_ci		p1pll->pll_out_min = 20000;
1328c2ecf20Sopenharmony_ci		p1pll->pll_out_max = 50000;
1338c2ecf20Sopenharmony_ci		p2pll->pll_in_min = 100;
1348c2ecf20Sopenharmony_ci		p2pll->pll_in_max = 1350;
1358c2ecf20Sopenharmony_ci		p2pll->pll_out_min = 20000;
1368c2ecf20Sopenharmony_ci		p2pll->pll_out_max = 50000;
1378c2ecf20Sopenharmony_ci	} else {
1388c2ecf20Sopenharmony_ci		p1pll->pll_in_min = 40;
1398c2ecf20Sopenharmony_ci		p1pll->pll_in_max = 500;
1408c2ecf20Sopenharmony_ci		p1pll->pll_out_min = 12500;
1418c2ecf20Sopenharmony_ci		p1pll->pll_out_max = 35000;
1428c2ecf20Sopenharmony_ci		p2pll->pll_in_min = 40;
1438c2ecf20Sopenharmony_ci		p2pll->pll_in_max = 500;
1448c2ecf20Sopenharmony_ci		p2pll->pll_out_min = 12500;
1458c2ecf20Sopenharmony_ci		p2pll->pll_out_max = 35000;
1468c2ecf20Sopenharmony_ci	}
1478c2ecf20Sopenharmony_ci	/* not sure what the max should be in all cases */
1488c2ecf20Sopenharmony_ci	rdev->clock.max_pixel_clock = 35000;
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci	spll->reference_freq = mpll->reference_freq = p1pll->reference_freq;
1518c2ecf20Sopenharmony_ci	spll->reference_div = mpll->reference_div =
1528c2ecf20Sopenharmony_ci		RREG32_PLL(RADEON_M_SPLL_REF_FB_DIV) &
1538c2ecf20Sopenharmony_ci			    RADEON_M_SPLL_REF_DIV_MASK;
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ci	val = of_get_property(dp, "ATY,SCLK", NULL);
1568c2ecf20Sopenharmony_ci	if (val && *val)
1578c2ecf20Sopenharmony_ci		rdev->clock.default_sclk = (*val) / 10;
1588c2ecf20Sopenharmony_ci	else
1598c2ecf20Sopenharmony_ci		rdev->clock.default_sclk =
1608c2ecf20Sopenharmony_ci			radeon_legacy_get_engine_clock(rdev);
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci	val = of_get_property(dp, "ATY,MCLK", NULL);
1638c2ecf20Sopenharmony_ci	if (val && *val)
1648c2ecf20Sopenharmony_ci		rdev->clock.default_mclk = (*val) / 10;
1658c2ecf20Sopenharmony_ci	else
1668c2ecf20Sopenharmony_ci		rdev->clock.default_mclk =
1678c2ecf20Sopenharmony_ci			radeon_legacy_get_memory_clock(rdev);
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci	DRM_INFO("Using device-tree clock info\n");
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci	return true;
1728c2ecf20Sopenharmony_ci}
1738c2ecf20Sopenharmony_ci#else
1748c2ecf20Sopenharmony_cistatic bool radeon_read_clocks_OF(struct drm_device *dev)
1758c2ecf20Sopenharmony_ci{
1768c2ecf20Sopenharmony_ci	return false;
1778c2ecf20Sopenharmony_ci}
1788c2ecf20Sopenharmony_ci#endif /* CONFIG_OF */
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_civoid radeon_get_clock_info(struct drm_device *dev)
1818c2ecf20Sopenharmony_ci{
1828c2ecf20Sopenharmony_ci	struct radeon_device *rdev = dev->dev_private;
1838c2ecf20Sopenharmony_ci	struct radeon_pll *p1pll = &rdev->clock.p1pll;
1848c2ecf20Sopenharmony_ci	struct radeon_pll *p2pll = &rdev->clock.p2pll;
1858c2ecf20Sopenharmony_ci	struct radeon_pll *dcpll = &rdev->clock.dcpll;
1868c2ecf20Sopenharmony_ci	struct radeon_pll *spll = &rdev->clock.spll;
1878c2ecf20Sopenharmony_ci	struct radeon_pll *mpll = &rdev->clock.mpll;
1888c2ecf20Sopenharmony_ci	int ret;
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_ci	if (rdev->is_atom_bios)
1918c2ecf20Sopenharmony_ci		ret = radeon_atom_get_clock_info(dev);
1928c2ecf20Sopenharmony_ci	else
1938c2ecf20Sopenharmony_ci		ret = radeon_combios_get_clock_info(dev);
1948c2ecf20Sopenharmony_ci	if (!ret)
1958c2ecf20Sopenharmony_ci		ret = radeon_read_clocks_OF(dev);
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_ci	if (ret) {
1988c2ecf20Sopenharmony_ci		if (p1pll->reference_div < 2) {
1998c2ecf20Sopenharmony_ci			if (!ASIC_IS_AVIVO(rdev)) {
2008c2ecf20Sopenharmony_ci				u32 tmp = RREG32_PLL(RADEON_PPLL_REF_DIV);
2018c2ecf20Sopenharmony_ci				if (ASIC_IS_R300(rdev))
2028c2ecf20Sopenharmony_ci					p1pll->reference_div =
2038c2ecf20Sopenharmony_ci						(tmp & R300_PPLL_REF_DIV_ACC_MASK) >> R300_PPLL_REF_DIV_ACC_SHIFT;
2048c2ecf20Sopenharmony_ci				else
2058c2ecf20Sopenharmony_ci					p1pll->reference_div = tmp & RADEON_PPLL_REF_DIV_MASK;
2068c2ecf20Sopenharmony_ci				if (p1pll->reference_div < 2)
2078c2ecf20Sopenharmony_ci					p1pll->reference_div = 12;
2088c2ecf20Sopenharmony_ci			} else
2098c2ecf20Sopenharmony_ci				p1pll->reference_div = 12;
2108c2ecf20Sopenharmony_ci		}
2118c2ecf20Sopenharmony_ci		if (p2pll->reference_div < 2)
2128c2ecf20Sopenharmony_ci			p2pll->reference_div = 12;
2138c2ecf20Sopenharmony_ci		if (rdev->family < CHIP_RS600) {
2148c2ecf20Sopenharmony_ci			if (spll->reference_div < 2)
2158c2ecf20Sopenharmony_ci				spll->reference_div =
2168c2ecf20Sopenharmony_ci					RREG32_PLL(RADEON_M_SPLL_REF_FB_DIV) &
2178c2ecf20Sopenharmony_ci					RADEON_M_SPLL_REF_DIV_MASK;
2188c2ecf20Sopenharmony_ci		}
2198c2ecf20Sopenharmony_ci		if (mpll->reference_div < 2)
2208c2ecf20Sopenharmony_ci			mpll->reference_div = spll->reference_div;
2218c2ecf20Sopenharmony_ci	} else {
2228c2ecf20Sopenharmony_ci		if (ASIC_IS_AVIVO(rdev)) {
2238c2ecf20Sopenharmony_ci			/* TODO FALLBACK */
2248c2ecf20Sopenharmony_ci		} else {
2258c2ecf20Sopenharmony_ci			DRM_INFO("Using generic clock info\n");
2268c2ecf20Sopenharmony_ci
2278c2ecf20Sopenharmony_ci			/* may need to be per card */
2288c2ecf20Sopenharmony_ci			rdev->clock.max_pixel_clock = 35000;
2298c2ecf20Sopenharmony_ci
2308c2ecf20Sopenharmony_ci			if (rdev->flags & RADEON_IS_IGP) {
2318c2ecf20Sopenharmony_ci				p1pll->reference_freq = 1432;
2328c2ecf20Sopenharmony_ci				p2pll->reference_freq = 1432;
2338c2ecf20Sopenharmony_ci				spll->reference_freq = 1432;
2348c2ecf20Sopenharmony_ci				mpll->reference_freq = 1432;
2358c2ecf20Sopenharmony_ci			} else {
2368c2ecf20Sopenharmony_ci				p1pll->reference_freq = 2700;
2378c2ecf20Sopenharmony_ci				p2pll->reference_freq = 2700;
2388c2ecf20Sopenharmony_ci				spll->reference_freq = 2700;
2398c2ecf20Sopenharmony_ci				mpll->reference_freq = 2700;
2408c2ecf20Sopenharmony_ci			}
2418c2ecf20Sopenharmony_ci			p1pll->reference_div =
2428c2ecf20Sopenharmony_ci			    RREG32_PLL(RADEON_PPLL_REF_DIV) & 0x3ff;
2438c2ecf20Sopenharmony_ci			if (p1pll->reference_div < 2)
2448c2ecf20Sopenharmony_ci				p1pll->reference_div = 12;
2458c2ecf20Sopenharmony_ci			p2pll->reference_div = p1pll->reference_div;
2468c2ecf20Sopenharmony_ci
2478c2ecf20Sopenharmony_ci			if (rdev->family >= CHIP_R420) {
2488c2ecf20Sopenharmony_ci				p1pll->pll_in_min = 100;
2498c2ecf20Sopenharmony_ci				p1pll->pll_in_max = 1350;
2508c2ecf20Sopenharmony_ci				p1pll->pll_out_min = 20000;
2518c2ecf20Sopenharmony_ci				p1pll->pll_out_max = 50000;
2528c2ecf20Sopenharmony_ci				p2pll->pll_in_min = 100;
2538c2ecf20Sopenharmony_ci				p2pll->pll_in_max = 1350;
2548c2ecf20Sopenharmony_ci				p2pll->pll_out_min = 20000;
2558c2ecf20Sopenharmony_ci				p2pll->pll_out_max = 50000;
2568c2ecf20Sopenharmony_ci			} else {
2578c2ecf20Sopenharmony_ci				p1pll->pll_in_min = 40;
2588c2ecf20Sopenharmony_ci				p1pll->pll_in_max = 500;
2598c2ecf20Sopenharmony_ci				p1pll->pll_out_min = 12500;
2608c2ecf20Sopenharmony_ci				p1pll->pll_out_max = 35000;
2618c2ecf20Sopenharmony_ci				p2pll->pll_in_min = 40;
2628c2ecf20Sopenharmony_ci				p2pll->pll_in_max = 500;
2638c2ecf20Sopenharmony_ci				p2pll->pll_out_min = 12500;
2648c2ecf20Sopenharmony_ci				p2pll->pll_out_max = 35000;
2658c2ecf20Sopenharmony_ci			}
2668c2ecf20Sopenharmony_ci
2678c2ecf20Sopenharmony_ci			spll->reference_div =
2688c2ecf20Sopenharmony_ci			    RREG32_PLL(RADEON_M_SPLL_REF_FB_DIV) &
2698c2ecf20Sopenharmony_ci			    RADEON_M_SPLL_REF_DIV_MASK;
2708c2ecf20Sopenharmony_ci			mpll->reference_div = spll->reference_div;
2718c2ecf20Sopenharmony_ci			rdev->clock.default_sclk =
2728c2ecf20Sopenharmony_ci			    radeon_legacy_get_engine_clock(rdev);
2738c2ecf20Sopenharmony_ci			rdev->clock.default_mclk =
2748c2ecf20Sopenharmony_ci			    radeon_legacy_get_memory_clock(rdev);
2758c2ecf20Sopenharmony_ci		}
2768c2ecf20Sopenharmony_ci	}
2778c2ecf20Sopenharmony_ci
2788c2ecf20Sopenharmony_ci	/* pixel clocks */
2798c2ecf20Sopenharmony_ci	if (ASIC_IS_AVIVO(rdev)) {
2808c2ecf20Sopenharmony_ci		p1pll->min_post_div = 2;
2818c2ecf20Sopenharmony_ci		p1pll->max_post_div = 0x7f;
2828c2ecf20Sopenharmony_ci		p1pll->min_frac_feedback_div = 0;
2838c2ecf20Sopenharmony_ci		p1pll->max_frac_feedback_div = 9;
2848c2ecf20Sopenharmony_ci		p2pll->min_post_div = 2;
2858c2ecf20Sopenharmony_ci		p2pll->max_post_div = 0x7f;
2868c2ecf20Sopenharmony_ci		p2pll->min_frac_feedback_div = 0;
2878c2ecf20Sopenharmony_ci		p2pll->max_frac_feedback_div = 9;
2888c2ecf20Sopenharmony_ci	} else {
2898c2ecf20Sopenharmony_ci		p1pll->min_post_div = 1;
2908c2ecf20Sopenharmony_ci		p1pll->max_post_div = 16;
2918c2ecf20Sopenharmony_ci		p1pll->min_frac_feedback_div = 0;
2928c2ecf20Sopenharmony_ci		p1pll->max_frac_feedback_div = 0;
2938c2ecf20Sopenharmony_ci		p2pll->min_post_div = 1;
2948c2ecf20Sopenharmony_ci		p2pll->max_post_div = 12;
2958c2ecf20Sopenharmony_ci		p2pll->min_frac_feedback_div = 0;
2968c2ecf20Sopenharmony_ci		p2pll->max_frac_feedback_div = 0;
2978c2ecf20Sopenharmony_ci	}
2988c2ecf20Sopenharmony_ci
2998c2ecf20Sopenharmony_ci	/* dcpll is DCE4 only */
3008c2ecf20Sopenharmony_ci	dcpll->min_post_div = 2;
3018c2ecf20Sopenharmony_ci	dcpll->max_post_div = 0x7f;
3028c2ecf20Sopenharmony_ci	dcpll->min_frac_feedback_div = 0;
3038c2ecf20Sopenharmony_ci	dcpll->max_frac_feedback_div = 9;
3048c2ecf20Sopenharmony_ci	dcpll->min_ref_div = 2;
3058c2ecf20Sopenharmony_ci	dcpll->max_ref_div = 0x3ff;
3068c2ecf20Sopenharmony_ci	dcpll->min_feedback_div = 4;
3078c2ecf20Sopenharmony_ci	dcpll->max_feedback_div = 0xfff;
3088c2ecf20Sopenharmony_ci	dcpll->best_vco = 0;
3098c2ecf20Sopenharmony_ci
3108c2ecf20Sopenharmony_ci	p1pll->min_ref_div = 2;
3118c2ecf20Sopenharmony_ci	p1pll->max_ref_div = 0x3ff;
3128c2ecf20Sopenharmony_ci	p1pll->min_feedback_div = 4;
3138c2ecf20Sopenharmony_ci	p1pll->max_feedback_div = 0x7ff;
3148c2ecf20Sopenharmony_ci	p1pll->best_vco = 0;
3158c2ecf20Sopenharmony_ci
3168c2ecf20Sopenharmony_ci	p2pll->min_ref_div = 2;
3178c2ecf20Sopenharmony_ci	p2pll->max_ref_div = 0x3ff;
3188c2ecf20Sopenharmony_ci	p2pll->min_feedback_div = 4;
3198c2ecf20Sopenharmony_ci	p2pll->max_feedback_div = 0x7ff;
3208c2ecf20Sopenharmony_ci	p2pll->best_vco = 0;
3218c2ecf20Sopenharmony_ci
3228c2ecf20Sopenharmony_ci	/* system clock */
3238c2ecf20Sopenharmony_ci	spll->min_post_div = 1;
3248c2ecf20Sopenharmony_ci	spll->max_post_div = 1;
3258c2ecf20Sopenharmony_ci	spll->min_ref_div = 2;
3268c2ecf20Sopenharmony_ci	spll->max_ref_div = 0xff;
3278c2ecf20Sopenharmony_ci	spll->min_feedback_div = 4;
3288c2ecf20Sopenharmony_ci	spll->max_feedback_div = 0xff;
3298c2ecf20Sopenharmony_ci	spll->best_vco = 0;
3308c2ecf20Sopenharmony_ci
3318c2ecf20Sopenharmony_ci	/* memory clock */
3328c2ecf20Sopenharmony_ci	mpll->min_post_div = 1;
3338c2ecf20Sopenharmony_ci	mpll->max_post_div = 1;
3348c2ecf20Sopenharmony_ci	mpll->min_ref_div = 2;
3358c2ecf20Sopenharmony_ci	mpll->max_ref_div = 0xff;
3368c2ecf20Sopenharmony_ci	mpll->min_feedback_div = 4;
3378c2ecf20Sopenharmony_ci	mpll->max_feedback_div = 0xff;
3388c2ecf20Sopenharmony_ci	mpll->best_vco = 0;
3398c2ecf20Sopenharmony_ci
3408c2ecf20Sopenharmony_ci	if (!rdev->clock.default_sclk)
3418c2ecf20Sopenharmony_ci		rdev->clock.default_sclk = radeon_get_engine_clock(rdev);
3428c2ecf20Sopenharmony_ci	if ((!rdev->clock.default_mclk) && rdev->asic->pm.get_memory_clock)
3438c2ecf20Sopenharmony_ci		rdev->clock.default_mclk = radeon_get_memory_clock(rdev);
3448c2ecf20Sopenharmony_ci
3458c2ecf20Sopenharmony_ci	rdev->pm.current_sclk = rdev->clock.default_sclk;
3468c2ecf20Sopenharmony_ci	rdev->pm.current_mclk = rdev->clock.default_mclk;
3478c2ecf20Sopenharmony_ci
3488c2ecf20Sopenharmony_ci}
3498c2ecf20Sopenharmony_ci
3508c2ecf20Sopenharmony_ci/* 10 khz */
3518c2ecf20Sopenharmony_cistatic uint32_t calc_eng_mem_clock(struct radeon_device *rdev,
3528c2ecf20Sopenharmony_ci				   uint32_t req_clock,
3538c2ecf20Sopenharmony_ci				   int *fb_div, int *post_div)
3548c2ecf20Sopenharmony_ci{
3558c2ecf20Sopenharmony_ci	struct radeon_pll *spll = &rdev->clock.spll;
3568c2ecf20Sopenharmony_ci	int ref_div = spll->reference_div;
3578c2ecf20Sopenharmony_ci
3588c2ecf20Sopenharmony_ci	if (!ref_div)
3598c2ecf20Sopenharmony_ci		ref_div =
3608c2ecf20Sopenharmony_ci		    RREG32_PLL(RADEON_M_SPLL_REF_FB_DIV) &
3618c2ecf20Sopenharmony_ci		    RADEON_M_SPLL_REF_DIV_MASK;
3628c2ecf20Sopenharmony_ci
3638c2ecf20Sopenharmony_ci	if (req_clock < 15000) {
3648c2ecf20Sopenharmony_ci		*post_div = 8;
3658c2ecf20Sopenharmony_ci		req_clock *= 8;
3668c2ecf20Sopenharmony_ci	} else if (req_clock < 30000) {
3678c2ecf20Sopenharmony_ci		*post_div = 4;
3688c2ecf20Sopenharmony_ci		req_clock *= 4;
3698c2ecf20Sopenharmony_ci	} else if (req_clock < 60000) {
3708c2ecf20Sopenharmony_ci		*post_div = 2;
3718c2ecf20Sopenharmony_ci		req_clock *= 2;
3728c2ecf20Sopenharmony_ci	} else
3738c2ecf20Sopenharmony_ci		*post_div = 1;
3748c2ecf20Sopenharmony_ci
3758c2ecf20Sopenharmony_ci	req_clock *= ref_div;
3768c2ecf20Sopenharmony_ci	req_clock += spll->reference_freq;
3778c2ecf20Sopenharmony_ci	req_clock /= (2 * spll->reference_freq);
3788c2ecf20Sopenharmony_ci
3798c2ecf20Sopenharmony_ci	*fb_div = req_clock & 0xff;
3808c2ecf20Sopenharmony_ci
3818c2ecf20Sopenharmony_ci	req_clock = (req_clock & 0xffff) << 1;
3828c2ecf20Sopenharmony_ci	req_clock *= spll->reference_freq;
3838c2ecf20Sopenharmony_ci	req_clock /= ref_div;
3848c2ecf20Sopenharmony_ci	req_clock /= *post_div;
3858c2ecf20Sopenharmony_ci
3868c2ecf20Sopenharmony_ci	return req_clock;
3878c2ecf20Sopenharmony_ci}
3888c2ecf20Sopenharmony_ci
3898c2ecf20Sopenharmony_ci/* 10 khz */
3908c2ecf20Sopenharmony_civoid radeon_legacy_set_engine_clock(struct radeon_device *rdev,
3918c2ecf20Sopenharmony_ci				    uint32_t eng_clock)
3928c2ecf20Sopenharmony_ci{
3938c2ecf20Sopenharmony_ci	uint32_t tmp;
3948c2ecf20Sopenharmony_ci	int fb_div, post_div;
3958c2ecf20Sopenharmony_ci
3968c2ecf20Sopenharmony_ci	/* XXX: wait for idle */
3978c2ecf20Sopenharmony_ci
3988c2ecf20Sopenharmony_ci	eng_clock = calc_eng_mem_clock(rdev, eng_clock, &fb_div, &post_div);
3998c2ecf20Sopenharmony_ci
4008c2ecf20Sopenharmony_ci	tmp = RREG32_PLL(RADEON_CLK_PIN_CNTL);
4018c2ecf20Sopenharmony_ci	tmp &= ~RADEON_DONT_USE_XTALIN;
4028c2ecf20Sopenharmony_ci	WREG32_PLL(RADEON_CLK_PIN_CNTL, tmp);
4038c2ecf20Sopenharmony_ci
4048c2ecf20Sopenharmony_ci	tmp = RREG32_PLL(RADEON_SCLK_CNTL);
4058c2ecf20Sopenharmony_ci	tmp &= ~RADEON_SCLK_SRC_SEL_MASK;
4068c2ecf20Sopenharmony_ci	WREG32_PLL(RADEON_SCLK_CNTL, tmp);
4078c2ecf20Sopenharmony_ci
4088c2ecf20Sopenharmony_ci	udelay(10);
4098c2ecf20Sopenharmony_ci
4108c2ecf20Sopenharmony_ci	tmp = RREG32_PLL(RADEON_SPLL_CNTL);
4118c2ecf20Sopenharmony_ci	tmp |= RADEON_SPLL_SLEEP;
4128c2ecf20Sopenharmony_ci	WREG32_PLL(RADEON_SPLL_CNTL, tmp);
4138c2ecf20Sopenharmony_ci
4148c2ecf20Sopenharmony_ci	udelay(2);
4158c2ecf20Sopenharmony_ci
4168c2ecf20Sopenharmony_ci	tmp = RREG32_PLL(RADEON_SPLL_CNTL);
4178c2ecf20Sopenharmony_ci	tmp |= RADEON_SPLL_RESET;
4188c2ecf20Sopenharmony_ci	WREG32_PLL(RADEON_SPLL_CNTL, tmp);
4198c2ecf20Sopenharmony_ci
4208c2ecf20Sopenharmony_ci	udelay(200);
4218c2ecf20Sopenharmony_ci
4228c2ecf20Sopenharmony_ci	tmp = RREG32_PLL(RADEON_M_SPLL_REF_FB_DIV);
4238c2ecf20Sopenharmony_ci	tmp &= ~(RADEON_SPLL_FB_DIV_MASK << RADEON_SPLL_FB_DIV_SHIFT);
4248c2ecf20Sopenharmony_ci	tmp |= (fb_div & RADEON_SPLL_FB_DIV_MASK) << RADEON_SPLL_FB_DIV_SHIFT;
4258c2ecf20Sopenharmony_ci	WREG32_PLL(RADEON_M_SPLL_REF_FB_DIV, tmp);
4268c2ecf20Sopenharmony_ci
4278c2ecf20Sopenharmony_ci	/* XXX: verify on different asics */
4288c2ecf20Sopenharmony_ci	tmp = RREG32_PLL(RADEON_SPLL_CNTL);
4298c2ecf20Sopenharmony_ci	tmp &= ~RADEON_SPLL_PVG_MASK;
4308c2ecf20Sopenharmony_ci	if ((eng_clock * post_div) >= 90000)
4318c2ecf20Sopenharmony_ci		tmp |= (0x7 << RADEON_SPLL_PVG_SHIFT);
4328c2ecf20Sopenharmony_ci	else
4338c2ecf20Sopenharmony_ci		tmp |= (0x4 << RADEON_SPLL_PVG_SHIFT);
4348c2ecf20Sopenharmony_ci	WREG32_PLL(RADEON_SPLL_CNTL, tmp);
4358c2ecf20Sopenharmony_ci
4368c2ecf20Sopenharmony_ci	tmp = RREG32_PLL(RADEON_SPLL_CNTL);
4378c2ecf20Sopenharmony_ci	tmp &= ~RADEON_SPLL_SLEEP;
4388c2ecf20Sopenharmony_ci	WREG32_PLL(RADEON_SPLL_CNTL, tmp);
4398c2ecf20Sopenharmony_ci
4408c2ecf20Sopenharmony_ci	udelay(2);
4418c2ecf20Sopenharmony_ci
4428c2ecf20Sopenharmony_ci	tmp = RREG32_PLL(RADEON_SPLL_CNTL);
4438c2ecf20Sopenharmony_ci	tmp &= ~RADEON_SPLL_RESET;
4448c2ecf20Sopenharmony_ci	WREG32_PLL(RADEON_SPLL_CNTL, tmp);
4458c2ecf20Sopenharmony_ci
4468c2ecf20Sopenharmony_ci	udelay(200);
4478c2ecf20Sopenharmony_ci
4488c2ecf20Sopenharmony_ci	tmp = RREG32_PLL(RADEON_SCLK_CNTL);
4498c2ecf20Sopenharmony_ci	tmp &= ~RADEON_SCLK_SRC_SEL_MASK;
4508c2ecf20Sopenharmony_ci	switch (post_div) {
4518c2ecf20Sopenharmony_ci	case 1:
4528c2ecf20Sopenharmony_ci	default:
4538c2ecf20Sopenharmony_ci		tmp |= 1;
4548c2ecf20Sopenharmony_ci		break;
4558c2ecf20Sopenharmony_ci	case 2:
4568c2ecf20Sopenharmony_ci		tmp |= 2;
4578c2ecf20Sopenharmony_ci		break;
4588c2ecf20Sopenharmony_ci	case 4:
4598c2ecf20Sopenharmony_ci		tmp |= 3;
4608c2ecf20Sopenharmony_ci		break;
4618c2ecf20Sopenharmony_ci	case 8:
4628c2ecf20Sopenharmony_ci		tmp |= 4;
4638c2ecf20Sopenharmony_ci		break;
4648c2ecf20Sopenharmony_ci	}
4658c2ecf20Sopenharmony_ci	WREG32_PLL(RADEON_SCLK_CNTL, tmp);
4668c2ecf20Sopenharmony_ci
4678c2ecf20Sopenharmony_ci	udelay(20);
4688c2ecf20Sopenharmony_ci
4698c2ecf20Sopenharmony_ci	tmp = RREG32_PLL(RADEON_CLK_PIN_CNTL);
4708c2ecf20Sopenharmony_ci	tmp |= RADEON_DONT_USE_XTALIN;
4718c2ecf20Sopenharmony_ci	WREG32_PLL(RADEON_CLK_PIN_CNTL, tmp);
4728c2ecf20Sopenharmony_ci
4738c2ecf20Sopenharmony_ci	udelay(10);
4748c2ecf20Sopenharmony_ci}
4758c2ecf20Sopenharmony_ci
4768c2ecf20Sopenharmony_civoid radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enable)
4778c2ecf20Sopenharmony_ci{
4788c2ecf20Sopenharmony_ci	uint32_t tmp;
4798c2ecf20Sopenharmony_ci
4808c2ecf20Sopenharmony_ci	if (enable) {
4818c2ecf20Sopenharmony_ci		if (rdev->flags & RADEON_SINGLE_CRTC) {
4828c2ecf20Sopenharmony_ci			tmp = RREG32_PLL(RADEON_SCLK_CNTL);
4838c2ecf20Sopenharmony_ci			if ((RREG32(RADEON_CONFIG_CNTL) &
4848c2ecf20Sopenharmony_ci			     RADEON_CFG_ATI_REV_ID_MASK) >
4858c2ecf20Sopenharmony_ci			    RADEON_CFG_ATI_REV_A13) {
4868c2ecf20Sopenharmony_ci				tmp &=
4878c2ecf20Sopenharmony_ci				    ~(RADEON_SCLK_FORCE_CP |
4888c2ecf20Sopenharmony_ci				      RADEON_SCLK_FORCE_RB);
4898c2ecf20Sopenharmony_ci			}
4908c2ecf20Sopenharmony_ci			tmp &=
4918c2ecf20Sopenharmony_ci			    ~(RADEON_SCLK_FORCE_HDP | RADEON_SCLK_FORCE_DISP1 |
4928c2ecf20Sopenharmony_ci			      RADEON_SCLK_FORCE_TOP | RADEON_SCLK_FORCE_SE |
4938c2ecf20Sopenharmony_ci			      RADEON_SCLK_FORCE_IDCT | RADEON_SCLK_FORCE_RE |
4948c2ecf20Sopenharmony_ci			      RADEON_SCLK_FORCE_PB | RADEON_SCLK_FORCE_TAM |
4958c2ecf20Sopenharmony_ci			      RADEON_SCLK_FORCE_TDM);
4968c2ecf20Sopenharmony_ci			WREG32_PLL(RADEON_SCLK_CNTL, tmp);
4978c2ecf20Sopenharmony_ci		} else if (ASIC_IS_R300(rdev)) {
4988c2ecf20Sopenharmony_ci			if ((rdev->family == CHIP_RS400) ||
4998c2ecf20Sopenharmony_ci			    (rdev->family == CHIP_RS480)) {
5008c2ecf20Sopenharmony_ci				tmp = RREG32_PLL(RADEON_SCLK_CNTL);
5018c2ecf20Sopenharmony_ci				tmp &=
5028c2ecf20Sopenharmony_ci				    ~(RADEON_SCLK_FORCE_DISP2 |
5038c2ecf20Sopenharmony_ci				      RADEON_SCLK_FORCE_CP |
5048c2ecf20Sopenharmony_ci				      RADEON_SCLK_FORCE_HDP |
5058c2ecf20Sopenharmony_ci				      RADEON_SCLK_FORCE_DISP1 |
5068c2ecf20Sopenharmony_ci				      RADEON_SCLK_FORCE_TOP |
5078c2ecf20Sopenharmony_ci				      RADEON_SCLK_FORCE_E2 | R300_SCLK_FORCE_VAP
5088c2ecf20Sopenharmony_ci				      | RADEON_SCLK_FORCE_IDCT |
5098c2ecf20Sopenharmony_ci				      RADEON_SCLK_FORCE_VIP | R300_SCLK_FORCE_SR
5108c2ecf20Sopenharmony_ci				      | R300_SCLK_FORCE_PX | R300_SCLK_FORCE_TX
5118c2ecf20Sopenharmony_ci				      | R300_SCLK_FORCE_US |
5128c2ecf20Sopenharmony_ci				      RADEON_SCLK_FORCE_TV_SCLK |
5138c2ecf20Sopenharmony_ci				      R300_SCLK_FORCE_SU |
5148c2ecf20Sopenharmony_ci				      RADEON_SCLK_FORCE_OV0);
5158c2ecf20Sopenharmony_ci				tmp |= RADEON_DYN_STOP_LAT_MASK;
5168c2ecf20Sopenharmony_ci				tmp |=
5178c2ecf20Sopenharmony_ci				    RADEON_SCLK_FORCE_TOP |
5188c2ecf20Sopenharmony_ci				    RADEON_SCLK_FORCE_VIP;
5198c2ecf20Sopenharmony_ci				WREG32_PLL(RADEON_SCLK_CNTL, tmp);
5208c2ecf20Sopenharmony_ci
5218c2ecf20Sopenharmony_ci				tmp = RREG32_PLL(RADEON_SCLK_MORE_CNTL);
5228c2ecf20Sopenharmony_ci				tmp &= ~RADEON_SCLK_MORE_FORCEON;
5238c2ecf20Sopenharmony_ci				tmp |= RADEON_SCLK_MORE_MAX_DYN_STOP_LAT;
5248c2ecf20Sopenharmony_ci				WREG32_PLL(RADEON_SCLK_MORE_CNTL, tmp);
5258c2ecf20Sopenharmony_ci
5268c2ecf20Sopenharmony_ci				tmp = RREG32_PLL(RADEON_VCLK_ECP_CNTL);
5278c2ecf20Sopenharmony_ci				tmp |= (RADEON_PIXCLK_ALWAYS_ONb |
5288c2ecf20Sopenharmony_ci					RADEON_PIXCLK_DAC_ALWAYS_ONb);
5298c2ecf20Sopenharmony_ci				WREG32_PLL(RADEON_VCLK_ECP_CNTL, tmp);
5308c2ecf20Sopenharmony_ci
5318c2ecf20Sopenharmony_ci				tmp = RREG32_PLL(RADEON_PIXCLKS_CNTL);
5328c2ecf20Sopenharmony_ci				tmp |= (RADEON_PIX2CLK_ALWAYS_ONb |
5338c2ecf20Sopenharmony_ci					RADEON_PIX2CLK_DAC_ALWAYS_ONb |
5348c2ecf20Sopenharmony_ci					RADEON_DISP_TVOUT_PIXCLK_TV_ALWAYS_ONb |
5358c2ecf20Sopenharmony_ci					R300_DVOCLK_ALWAYS_ONb |
5368c2ecf20Sopenharmony_ci					RADEON_PIXCLK_BLEND_ALWAYS_ONb |
5378c2ecf20Sopenharmony_ci					RADEON_PIXCLK_GV_ALWAYS_ONb |
5388c2ecf20Sopenharmony_ci					R300_PIXCLK_DVO_ALWAYS_ONb |
5398c2ecf20Sopenharmony_ci					RADEON_PIXCLK_LVDS_ALWAYS_ONb |
5408c2ecf20Sopenharmony_ci					RADEON_PIXCLK_TMDS_ALWAYS_ONb |
5418c2ecf20Sopenharmony_ci					R300_PIXCLK_TRANS_ALWAYS_ONb |
5428c2ecf20Sopenharmony_ci					R300_PIXCLK_TVO_ALWAYS_ONb |
5438c2ecf20Sopenharmony_ci					R300_P2G2CLK_ALWAYS_ONb |
5448c2ecf20Sopenharmony_ci					R300_P2G2CLK_DAC_ALWAYS_ONb);
5458c2ecf20Sopenharmony_ci				WREG32_PLL(RADEON_PIXCLKS_CNTL, tmp);
5468c2ecf20Sopenharmony_ci			} else if (rdev->family >= CHIP_RV350) {
5478c2ecf20Sopenharmony_ci				tmp = RREG32_PLL(R300_SCLK_CNTL2);
5488c2ecf20Sopenharmony_ci				tmp &= ~(R300_SCLK_FORCE_TCL |
5498c2ecf20Sopenharmony_ci					 R300_SCLK_FORCE_GA |
5508c2ecf20Sopenharmony_ci					 R300_SCLK_FORCE_CBA);
5518c2ecf20Sopenharmony_ci				tmp |= (R300_SCLK_TCL_MAX_DYN_STOP_LAT |
5528c2ecf20Sopenharmony_ci					R300_SCLK_GA_MAX_DYN_STOP_LAT |
5538c2ecf20Sopenharmony_ci					R300_SCLK_CBA_MAX_DYN_STOP_LAT);
5548c2ecf20Sopenharmony_ci				WREG32_PLL(R300_SCLK_CNTL2, tmp);
5558c2ecf20Sopenharmony_ci
5568c2ecf20Sopenharmony_ci				tmp = RREG32_PLL(RADEON_SCLK_CNTL);
5578c2ecf20Sopenharmony_ci				tmp &=
5588c2ecf20Sopenharmony_ci				    ~(RADEON_SCLK_FORCE_DISP2 |
5598c2ecf20Sopenharmony_ci				      RADEON_SCLK_FORCE_CP |
5608c2ecf20Sopenharmony_ci				      RADEON_SCLK_FORCE_HDP |
5618c2ecf20Sopenharmony_ci				      RADEON_SCLK_FORCE_DISP1 |
5628c2ecf20Sopenharmony_ci				      RADEON_SCLK_FORCE_TOP |
5638c2ecf20Sopenharmony_ci				      RADEON_SCLK_FORCE_E2 | R300_SCLK_FORCE_VAP
5648c2ecf20Sopenharmony_ci				      | RADEON_SCLK_FORCE_IDCT |
5658c2ecf20Sopenharmony_ci				      RADEON_SCLK_FORCE_VIP | R300_SCLK_FORCE_SR
5668c2ecf20Sopenharmony_ci				      | R300_SCLK_FORCE_PX | R300_SCLK_FORCE_TX
5678c2ecf20Sopenharmony_ci				      | R300_SCLK_FORCE_US |
5688c2ecf20Sopenharmony_ci				      RADEON_SCLK_FORCE_TV_SCLK |
5698c2ecf20Sopenharmony_ci				      R300_SCLK_FORCE_SU |
5708c2ecf20Sopenharmony_ci				      RADEON_SCLK_FORCE_OV0);
5718c2ecf20Sopenharmony_ci				tmp |= RADEON_DYN_STOP_LAT_MASK;
5728c2ecf20Sopenharmony_ci				WREG32_PLL(RADEON_SCLK_CNTL, tmp);
5738c2ecf20Sopenharmony_ci
5748c2ecf20Sopenharmony_ci				tmp = RREG32_PLL(RADEON_SCLK_MORE_CNTL);
5758c2ecf20Sopenharmony_ci				tmp &= ~RADEON_SCLK_MORE_FORCEON;
5768c2ecf20Sopenharmony_ci				tmp |= RADEON_SCLK_MORE_MAX_DYN_STOP_LAT;
5778c2ecf20Sopenharmony_ci				WREG32_PLL(RADEON_SCLK_MORE_CNTL, tmp);
5788c2ecf20Sopenharmony_ci
5798c2ecf20Sopenharmony_ci				tmp = RREG32_PLL(RADEON_VCLK_ECP_CNTL);
5808c2ecf20Sopenharmony_ci				tmp |= (RADEON_PIXCLK_ALWAYS_ONb |
5818c2ecf20Sopenharmony_ci					RADEON_PIXCLK_DAC_ALWAYS_ONb);
5828c2ecf20Sopenharmony_ci				WREG32_PLL(RADEON_VCLK_ECP_CNTL, tmp);
5838c2ecf20Sopenharmony_ci
5848c2ecf20Sopenharmony_ci				tmp = RREG32_PLL(RADEON_PIXCLKS_CNTL);
5858c2ecf20Sopenharmony_ci				tmp |= (RADEON_PIX2CLK_ALWAYS_ONb |
5868c2ecf20Sopenharmony_ci					RADEON_PIX2CLK_DAC_ALWAYS_ONb |
5878c2ecf20Sopenharmony_ci					RADEON_DISP_TVOUT_PIXCLK_TV_ALWAYS_ONb |
5888c2ecf20Sopenharmony_ci					R300_DVOCLK_ALWAYS_ONb |
5898c2ecf20Sopenharmony_ci					RADEON_PIXCLK_BLEND_ALWAYS_ONb |
5908c2ecf20Sopenharmony_ci					RADEON_PIXCLK_GV_ALWAYS_ONb |
5918c2ecf20Sopenharmony_ci					R300_PIXCLK_DVO_ALWAYS_ONb |
5928c2ecf20Sopenharmony_ci					RADEON_PIXCLK_LVDS_ALWAYS_ONb |
5938c2ecf20Sopenharmony_ci					RADEON_PIXCLK_TMDS_ALWAYS_ONb |
5948c2ecf20Sopenharmony_ci					R300_PIXCLK_TRANS_ALWAYS_ONb |
5958c2ecf20Sopenharmony_ci					R300_PIXCLK_TVO_ALWAYS_ONb |
5968c2ecf20Sopenharmony_ci					R300_P2G2CLK_ALWAYS_ONb |
5978c2ecf20Sopenharmony_ci					R300_P2G2CLK_DAC_ALWAYS_ONb);
5988c2ecf20Sopenharmony_ci				WREG32_PLL(RADEON_PIXCLKS_CNTL, tmp);
5998c2ecf20Sopenharmony_ci
6008c2ecf20Sopenharmony_ci				tmp = RREG32_PLL(RADEON_MCLK_MISC);
6018c2ecf20Sopenharmony_ci				tmp |= (RADEON_MC_MCLK_DYN_ENABLE |
6028c2ecf20Sopenharmony_ci					RADEON_IO_MCLK_DYN_ENABLE);
6038c2ecf20Sopenharmony_ci				WREG32_PLL(RADEON_MCLK_MISC, tmp);
6048c2ecf20Sopenharmony_ci
6058c2ecf20Sopenharmony_ci				tmp = RREG32_PLL(RADEON_MCLK_CNTL);
6068c2ecf20Sopenharmony_ci				tmp |= (RADEON_FORCEON_MCLKA |
6078c2ecf20Sopenharmony_ci					RADEON_FORCEON_MCLKB);
6088c2ecf20Sopenharmony_ci
6098c2ecf20Sopenharmony_ci				tmp &= ~(RADEON_FORCEON_YCLKA |
6108c2ecf20Sopenharmony_ci					 RADEON_FORCEON_YCLKB |
6118c2ecf20Sopenharmony_ci					 RADEON_FORCEON_MC);
6128c2ecf20Sopenharmony_ci
6138c2ecf20Sopenharmony_ci				/* Some releases of vbios have set DISABLE_MC_MCLKA
6148c2ecf20Sopenharmony_ci				   and DISABLE_MC_MCLKB bits in the vbios table.  Setting these
6158c2ecf20Sopenharmony_ci				   bits will cause H/W hang when reading video memory with dynamic clocking
6168c2ecf20Sopenharmony_ci				   enabled. */
6178c2ecf20Sopenharmony_ci				if ((tmp & R300_DISABLE_MC_MCLKA) &&
6188c2ecf20Sopenharmony_ci				    (tmp & R300_DISABLE_MC_MCLKB)) {
6198c2ecf20Sopenharmony_ci					/* If both bits are set, then check the active channels */
6208c2ecf20Sopenharmony_ci					tmp = RREG32_PLL(RADEON_MCLK_CNTL);
6218c2ecf20Sopenharmony_ci					if (rdev->mc.vram_width == 64) {
6228c2ecf20Sopenharmony_ci						if (RREG32(RADEON_MEM_CNTL) &
6238c2ecf20Sopenharmony_ci						    R300_MEM_USE_CD_CH_ONLY)
6248c2ecf20Sopenharmony_ci							tmp &=
6258c2ecf20Sopenharmony_ci							    ~R300_DISABLE_MC_MCLKB;
6268c2ecf20Sopenharmony_ci						else
6278c2ecf20Sopenharmony_ci							tmp &=
6288c2ecf20Sopenharmony_ci							    ~R300_DISABLE_MC_MCLKA;
6298c2ecf20Sopenharmony_ci					} else {
6308c2ecf20Sopenharmony_ci						tmp &= ~(R300_DISABLE_MC_MCLKA |
6318c2ecf20Sopenharmony_ci							 R300_DISABLE_MC_MCLKB);
6328c2ecf20Sopenharmony_ci					}
6338c2ecf20Sopenharmony_ci				}
6348c2ecf20Sopenharmony_ci
6358c2ecf20Sopenharmony_ci				WREG32_PLL(RADEON_MCLK_CNTL, tmp);
6368c2ecf20Sopenharmony_ci			} else {
6378c2ecf20Sopenharmony_ci				tmp = RREG32_PLL(RADEON_SCLK_CNTL);
6388c2ecf20Sopenharmony_ci				tmp &= ~(R300_SCLK_FORCE_VAP);
6398c2ecf20Sopenharmony_ci				tmp |= RADEON_SCLK_FORCE_CP;
6408c2ecf20Sopenharmony_ci				WREG32_PLL(RADEON_SCLK_CNTL, tmp);
6418c2ecf20Sopenharmony_ci				mdelay(15);
6428c2ecf20Sopenharmony_ci
6438c2ecf20Sopenharmony_ci				tmp = RREG32_PLL(R300_SCLK_CNTL2);
6448c2ecf20Sopenharmony_ci				tmp &= ~(R300_SCLK_FORCE_TCL |
6458c2ecf20Sopenharmony_ci					 R300_SCLK_FORCE_GA |
6468c2ecf20Sopenharmony_ci					 R300_SCLK_FORCE_CBA);
6478c2ecf20Sopenharmony_ci				WREG32_PLL(R300_SCLK_CNTL2, tmp);
6488c2ecf20Sopenharmony_ci			}
6498c2ecf20Sopenharmony_ci		} else {
6508c2ecf20Sopenharmony_ci			tmp = RREG32_PLL(RADEON_CLK_PWRMGT_CNTL);
6518c2ecf20Sopenharmony_ci
6528c2ecf20Sopenharmony_ci			tmp &= ~(RADEON_ACTIVE_HILO_LAT_MASK |
6538c2ecf20Sopenharmony_ci				 RADEON_DISP_DYN_STOP_LAT_MASK |
6548c2ecf20Sopenharmony_ci				 RADEON_DYN_STOP_MODE_MASK);
6558c2ecf20Sopenharmony_ci
6568c2ecf20Sopenharmony_ci			tmp |= (RADEON_ENGIN_DYNCLK_MODE |
6578c2ecf20Sopenharmony_ci				(0x01 << RADEON_ACTIVE_HILO_LAT_SHIFT));
6588c2ecf20Sopenharmony_ci			WREG32_PLL(RADEON_CLK_PWRMGT_CNTL, tmp);
6598c2ecf20Sopenharmony_ci			mdelay(15);
6608c2ecf20Sopenharmony_ci
6618c2ecf20Sopenharmony_ci			tmp = RREG32_PLL(RADEON_CLK_PIN_CNTL);
6628c2ecf20Sopenharmony_ci			tmp |= RADEON_SCLK_DYN_START_CNTL;
6638c2ecf20Sopenharmony_ci			WREG32_PLL(RADEON_CLK_PIN_CNTL, tmp);
6648c2ecf20Sopenharmony_ci			mdelay(15);
6658c2ecf20Sopenharmony_ci
6668c2ecf20Sopenharmony_ci			/* When DRI is enabled, setting DYN_STOP_LAT to zero can cause some R200
6678c2ecf20Sopenharmony_ci			   to lockup randomly, leave them as set by BIOS.
6688c2ecf20Sopenharmony_ci			 */
6698c2ecf20Sopenharmony_ci			tmp = RREG32_PLL(RADEON_SCLK_CNTL);
6708c2ecf20Sopenharmony_ci			/*tmp &= RADEON_SCLK_SRC_SEL_MASK; */
6718c2ecf20Sopenharmony_ci			tmp &= ~RADEON_SCLK_FORCEON_MASK;
6728c2ecf20Sopenharmony_ci
6738c2ecf20Sopenharmony_ci			/*RAGE_6::A11 A12 A12N1 A13, RV250::A11 A12, R300 */
6748c2ecf20Sopenharmony_ci			if (((rdev->family == CHIP_RV250) &&
6758c2ecf20Sopenharmony_ci			     ((RREG32(RADEON_CONFIG_CNTL) &
6768c2ecf20Sopenharmony_ci			       RADEON_CFG_ATI_REV_ID_MASK) <
6778c2ecf20Sopenharmony_ci			      RADEON_CFG_ATI_REV_A13))
6788c2ecf20Sopenharmony_ci			    || ((rdev->family == CHIP_RV100)
6798c2ecf20Sopenharmony_ci				&&
6808c2ecf20Sopenharmony_ci				((RREG32(RADEON_CONFIG_CNTL) &
6818c2ecf20Sopenharmony_ci				  RADEON_CFG_ATI_REV_ID_MASK) <=
6828c2ecf20Sopenharmony_ci				 RADEON_CFG_ATI_REV_A13))) {
6838c2ecf20Sopenharmony_ci				tmp |= RADEON_SCLK_FORCE_CP;
6848c2ecf20Sopenharmony_ci				tmp |= RADEON_SCLK_FORCE_VIP;
6858c2ecf20Sopenharmony_ci			}
6868c2ecf20Sopenharmony_ci
6878c2ecf20Sopenharmony_ci			WREG32_PLL(RADEON_SCLK_CNTL, tmp);
6888c2ecf20Sopenharmony_ci
6898c2ecf20Sopenharmony_ci			if ((rdev->family == CHIP_RV200) ||
6908c2ecf20Sopenharmony_ci			    (rdev->family == CHIP_RV250) ||
6918c2ecf20Sopenharmony_ci			    (rdev->family == CHIP_RV280)) {
6928c2ecf20Sopenharmony_ci				tmp = RREG32_PLL(RADEON_SCLK_MORE_CNTL);
6938c2ecf20Sopenharmony_ci				tmp &= ~RADEON_SCLK_MORE_FORCEON;
6948c2ecf20Sopenharmony_ci
6958c2ecf20Sopenharmony_ci				/* RV200::A11 A12 RV250::A11 A12 */
6968c2ecf20Sopenharmony_ci				if (((rdev->family == CHIP_RV200) ||
6978c2ecf20Sopenharmony_ci				     (rdev->family == CHIP_RV250)) &&
6988c2ecf20Sopenharmony_ci				    ((RREG32(RADEON_CONFIG_CNTL) &
6998c2ecf20Sopenharmony_ci				      RADEON_CFG_ATI_REV_ID_MASK) <
7008c2ecf20Sopenharmony_ci				     RADEON_CFG_ATI_REV_A13)) {
7018c2ecf20Sopenharmony_ci					tmp |= RADEON_SCLK_MORE_FORCEON;
7028c2ecf20Sopenharmony_ci				}
7038c2ecf20Sopenharmony_ci				WREG32_PLL(RADEON_SCLK_MORE_CNTL, tmp);
7048c2ecf20Sopenharmony_ci				mdelay(15);
7058c2ecf20Sopenharmony_ci			}
7068c2ecf20Sopenharmony_ci
7078c2ecf20Sopenharmony_ci			/* RV200::A11 A12, RV250::A11 A12 */
7088c2ecf20Sopenharmony_ci			if (((rdev->family == CHIP_RV200) ||
7098c2ecf20Sopenharmony_ci			     (rdev->family == CHIP_RV250)) &&
7108c2ecf20Sopenharmony_ci			    ((RREG32(RADEON_CONFIG_CNTL) &
7118c2ecf20Sopenharmony_ci			      RADEON_CFG_ATI_REV_ID_MASK) <
7128c2ecf20Sopenharmony_ci			     RADEON_CFG_ATI_REV_A13)) {
7138c2ecf20Sopenharmony_ci				tmp = RREG32_PLL(RADEON_PLL_PWRMGT_CNTL);
7148c2ecf20Sopenharmony_ci				tmp |= RADEON_TCL_BYPASS_DISABLE;
7158c2ecf20Sopenharmony_ci				WREG32_PLL(RADEON_PLL_PWRMGT_CNTL, tmp);
7168c2ecf20Sopenharmony_ci			}
7178c2ecf20Sopenharmony_ci			mdelay(15);
7188c2ecf20Sopenharmony_ci
7198c2ecf20Sopenharmony_ci			/*enable dynamic mode for display clocks (PIXCLK and PIX2CLK) */
7208c2ecf20Sopenharmony_ci			tmp = RREG32_PLL(RADEON_PIXCLKS_CNTL);
7218c2ecf20Sopenharmony_ci			tmp |= (RADEON_PIX2CLK_ALWAYS_ONb |
7228c2ecf20Sopenharmony_ci				RADEON_PIX2CLK_DAC_ALWAYS_ONb |
7238c2ecf20Sopenharmony_ci				RADEON_PIXCLK_BLEND_ALWAYS_ONb |
7248c2ecf20Sopenharmony_ci				RADEON_PIXCLK_GV_ALWAYS_ONb |
7258c2ecf20Sopenharmony_ci				RADEON_PIXCLK_DIG_TMDS_ALWAYS_ONb |
7268c2ecf20Sopenharmony_ci				RADEON_PIXCLK_LVDS_ALWAYS_ONb |
7278c2ecf20Sopenharmony_ci				RADEON_PIXCLK_TMDS_ALWAYS_ONb);
7288c2ecf20Sopenharmony_ci
7298c2ecf20Sopenharmony_ci			WREG32_PLL(RADEON_PIXCLKS_CNTL, tmp);
7308c2ecf20Sopenharmony_ci			mdelay(15);
7318c2ecf20Sopenharmony_ci
7328c2ecf20Sopenharmony_ci			tmp = RREG32_PLL(RADEON_VCLK_ECP_CNTL);
7338c2ecf20Sopenharmony_ci			tmp |= (RADEON_PIXCLK_ALWAYS_ONb |
7348c2ecf20Sopenharmony_ci				RADEON_PIXCLK_DAC_ALWAYS_ONb);
7358c2ecf20Sopenharmony_ci
7368c2ecf20Sopenharmony_ci			WREG32_PLL(RADEON_VCLK_ECP_CNTL, tmp);
7378c2ecf20Sopenharmony_ci			mdelay(15);
7388c2ecf20Sopenharmony_ci		}
7398c2ecf20Sopenharmony_ci	} else {
7408c2ecf20Sopenharmony_ci		/* Turn everything OFF (ForceON to everything) */
7418c2ecf20Sopenharmony_ci		if (rdev->flags & RADEON_SINGLE_CRTC) {
7428c2ecf20Sopenharmony_ci			tmp = RREG32_PLL(RADEON_SCLK_CNTL);
7438c2ecf20Sopenharmony_ci			tmp |= (RADEON_SCLK_FORCE_CP | RADEON_SCLK_FORCE_HDP |
7448c2ecf20Sopenharmony_ci				RADEON_SCLK_FORCE_DISP1 | RADEON_SCLK_FORCE_TOP
7458c2ecf20Sopenharmony_ci				| RADEON_SCLK_FORCE_E2 | RADEON_SCLK_FORCE_SE |
7468c2ecf20Sopenharmony_ci				RADEON_SCLK_FORCE_IDCT | RADEON_SCLK_FORCE_VIP |
7478c2ecf20Sopenharmony_ci				RADEON_SCLK_FORCE_RE | RADEON_SCLK_FORCE_PB |
7488c2ecf20Sopenharmony_ci				RADEON_SCLK_FORCE_TAM | RADEON_SCLK_FORCE_TDM |
7498c2ecf20Sopenharmony_ci				RADEON_SCLK_FORCE_RB);
7508c2ecf20Sopenharmony_ci			WREG32_PLL(RADEON_SCLK_CNTL, tmp);
7518c2ecf20Sopenharmony_ci		} else if ((rdev->family == CHIP_RS400) ||
7528c2ecf20Sopenharmony_ci			   (rdev->family == CHIP_RS480)) {
7538c2ecf20Sopenharmony_ci			tmp = RREG32_PLL(RADEON_SCLK_CNTL);
7548c2ecf20Sopenharmony_ci			tmp |= (RADEON_SCLK_FORCE_DISP2 | RADEON_SCLK_FORCE_CP |
7558c2ecf20Sopenharmony_ci				RADEON_SCLK_FORCE_HDP | RADEON_SCLK_FORCE_DISP1
7568c2ecf20Sopenharmony_ci				| RADEON_SCLK_FORCE_TOP | RADEON_SCLK_FORCE_E2 |
7578c2ecf20Sopenharmony_ci				R300_SCLK_FORCE_VAP | RADEON_SCLK_FORCE_IDCT |
7588c2ecf20Sopenharmony_ci				RADEON_SCLK_FORCE_VIP | R300_SCLK_FORCE_SR |
7598c2ecf20Sopenharmony_ci				R300_SCLK_FORCE_PX | R300_SCLK_FORCE_TX |
7608c2ecf20Sopenharmony_ci				R300_SCLK_FORCE_US | RADEON_SCLK_FORCE_TV_SCLK |
7618c2ecf20Sopenharmony_ci				R300_SCLK_FORCE_SU | RADEON_SCLK_FORCE_OV0);
7628c2ecf20Sopenharmony_ci			WREG32_PLL(RADEON_SCLK_CNTL, tmp);
7638c2ecf20Sopenharmony_ci
7648c2ecf20Sopenharmony_ci			tmp = RREG32_PLL(RADEON_SCLK_MORE_CNTL);
7658c2ecf20Sopenharmony_ci			tmp |= RADEON_SCLK_MORE_FORCEON;
7668c2ecf20Sopenharmony_ci			WREG32_PLL(RADEON_SCLK_MORE_CNTL, tmp);
7678c2ecf20Sopenharmony_ci
7688c2ecf20Sopenharmony_ci			tmp = RREG32_PLL(RADEON_VCLK_ECP_CNTL);
7698c2ecf20Sopenharmony_ci			tmp &= ~(RADEON_PIXCLK_ALWAYS_ONb |
7708c2ecf20Sopenharmony_ci				 RADEON_PIXCLK_DAC_ALWAYS_ONb |
7718c2ecf20Sopenharmony_ci				 R300_DISP_DAC_PIXCLK_DAC_BLANK_OFF);
7728c2ecf20Sopenharmony_ci			WREG32_PLL(RADEON_VCLK_ECP_CNTL, tmp);
7738c2ecf20Sopenharmony_ci
7748c2ecf20Sopenharmony_ci			tmp = RREG32_PLL(RADEON_PIXCLKS_CNTL);
7758c2ecf20Sopenharmony_ci			tmp &= ~(RADEON_PIX2CLK_ALWAYS_ONb |
7768c2ecf20Sopenharmony_ci				 RADEON_PIX2CLK_DAC_ALWAYS_ONb |
7778c2ecf20Sopenharmony_ci				 RADEON_DISP_TVOUT_PIXCLK_TV_ALWAYS_ONb |
7788c2ecf20Sopenharmony_ci				 R300_DVOCLK_ALWAYS_ONb |
7798c2ecf20Sopenharmony_ci				 RADEON_PIXCLK_BLEND_ALWAYS_ONb |
7808c2ecf20Sopenharmony_ci				 RADEON_PIXCLK_GV_ALWAYS_ONb |
7818c2ecf20Sopenharmony_ci				 R300_PIXCLK_DVO_ALWAYS_ONb |
7828c2ecf20Sopenharmony_ci				 RADEON_PIXCLK_LVDS_ALWAYS_ONb |
7838c2ecf20Sopenharmony_ci				 RADEON_PIXCLK_TMDS_ALWAYS_ONb |
7848c2ecf20Sopenharmony_ci				 R300_PIXCLK_TRANS_ALWAYS_ONb |
7858c2ecf20Sopenharmony_ci				 R300_PIXCLK_TVO_ALWAYS_ONb |
7868c2ecf20Sopenharmony_ci				 R300_P2G2CLK_ALWAYS_ONb |
7878c2ecf20Sopenharmony_ci				 R300_P2G2CLK_DAC_ALWAYS_ONb |
7888c2ecf20Sopenharmony_ci				 R300_DISP_DAC_PIXCLK_DAC2_BLANK_OFF);
7898c2ecf20Sopenharmony_ci			WREG32_PLL(RADEON_PIXCLKS_CNTL, tmp);
7908c2ecf20Sopenharmony_ci		} else if (rdev->family >= CHIP_RV350) {
7918c2ecf20Sopenharmony_ci			/* for RV350/M10, no delays are required. */
7928c2ecf20Sopenharmony_ci			tmp = RREG32_PLL(R300_SCLK_CNTL2);
7938c2ecf20Sopenharmony_ci			tmp |= (R300_SCLK_FORCE_TCL |
7948c2ecf20Sopenharmony_ci				R300_SCLK_FORCE_GA | R300_SCLK_FORCE_CBA);
7958c2ecf20Sopenharmony_ci			WREG32_PLL(R300_SCLK_CNTL2, tmp);
7968c2ecf20Sopenharmony_ci
7978c2ecf20Sopenharmony_ci			tmp = RREG32_PLL(RADEON_SCLK_CNTL);
7988c2ecf20Sopenharmony_ci			tmp |= (RADEON_SCLK_FORCE_DISP2 | RADEON_SCLK_FORCE_CP |
7998c2ecf20Sopenharmony_ci				RADEON_SCLK_FORCE_HDP | RADEON_SCLK_FORCE_DISP1
8008c2ecf20Sopenharmony_ci				| RADEON_SCLK_FORCE_TOP | RADEON_SCLK_FORCE_E2 |
8018c2ecf20Sopenharmony_ci				R300_SCLK_FORCE_VAP | RADEON_SCLK_FORCE_IDCT |
8028c2ecf20Sopenharmony_ci				RADEON_SCLK_FORCE_VIP | R300_SCLK_FORCE_SR |
8038c2ecf20Sopenharmony_ci				R300_SCLK_FORCE_PX | R300_SCLK_FORCE_TX |
8048c2ecf20Sopenharmony_ci				R300_SCLK_FORCE_US | RADEON_SCLK_FORCE_TV_SCLK |
8058c2ecf20Sopenharmony_ci				R300_SCLK_FORCE_SU | RADEON_SCLK_FORCE_OV0);
8068c2ecf20Sopenharmony_ci			WREG32_PLL(RADEON_SCLK_CNTL, tmp);
8078c2ecf20Sopenharmony_ci
8088c2ecf20Sopenharmony_ci			tmp = RREG32_PLL(RADEON_SCLK_MORE_CNTL);
8098c2ecf20Sopenharmony_ci			tmp |= RADEON_SCLK_MORE_FORCEON;
8108c2ecf20Sopenharmony_ci			WREG32_PLL(RADEON_SCLK_MORE_CNTL, tmp);
8118c2ecf20Sopenharmony_ci
8128c2ecf20Sopenharmony_ci			tmp = RREG32_PLL(RADEON_MCLK_CNTL);
8138c2ecf20Sopenharmony_ci			tmp |= (RADEON_FORCEON_MCLKA |
8148c2ecf20Sopenharmony_ci				RADEON_FORCEON_MCLKB |
8158c2ecf20Sopenharmony_ci				RADEON_FORCEON_YCLKA |
8168c2ecf20Sopenharmony_ci				RADEON_FORCEON_YCLKB | RADEON_FORCEON_MC);
8178c2ecf20Sopenharmony_ci			WREG32_PLL(RADEON_MCLK_CNTL, tmp);
8188c2ecf20Sopenharmony_ci
8198c2ecf20Sopenharmony_ci			tmp = RREG32_PLL(RADEON_VCLK_ECP_CNTL);
8208c2ecf20Sopenharmony_ci			tmp &= ~(RADEON_PIXCLK_ALWAYS_ONb |
8218c2ecf20Sopenharmony_ci				 RADEON_PIXCLK_DAC_ALWAYS_ONb |
8228c2ecf20Sopenharmony_ci				 R300_DISP_DAC_PIXCLK_DAC_BLANK_OFF);
8238c2ecf20Sopenharmony_ci			WREG32_PLL(RADEON_VCLK_ECP_CNTL, tmp);
8248c2ecf20Sopenharmony_ci
8258c2ecf20Sopenharmony_ci			tmp = RREG32_PLL(RADEON_PIXCLKS_CNTL);
8268c2ecf20Sopenharmony_ci			tmp &= ~(RADEON_PIX2CLK_ALWAYS_ONb |
8278c2ecf20Sopenharmony_ci				 RADEON_PIX2CLK_DAC_ALWAYS_ONb |
8288c2ecf20Sopenharmony_ci				 RADEON_DISP_TVOUT_PIXCLK_TV_ALWAYS_ONb |
8298c2ecf20Sopenharmony_ci				 R300_DVOCLK_ALWAYS_ONb |
8308c2ecf20Sopenharmony_ci				 RADEON_PIXCLK_BLEND_ALWAYS_ONb |
8318c2ecf20Sopenharmony_ci				 RADEON_PIXCLK_GV_ALWAYS_ONb |
8328c2ecf20Sopenharmony_ci				 R300_PIXCLK_DVO_ALWAYS_ONb |
8338c2ecf20Sopenharmony_ci				 RADEON_PIXCLK_LVDS_ALWAYS_ONb |
8348c2ecf20Sopenharmony_ci				 RADEON_PIXCLK_TMDS_ALWAYS_ONb |
8358c2ecf20Sopenharmony_ci				 R300_PIXCLK_TRANS_ALWAYS_ONb |
8368c2ecf20Sopenharmony_ci				 R300_PIXCLK_TVO_ALWAYS_ONb |
8378c2ecf20Sopenharmony_ci				 R300_P2G2CLK_ALWAYS_ONb |
8388c2ecf20Sopenharmony_ci				 R300_P2G2CLK_DAC_ALWAYS_ONb |
8398c2ecf20Sopenharmony_ci				 R300_DISP_DAC_PIXCLK_DAC2_BLANK_OFF);
8408c2ecf20Sopenharmony_ci			WREG32_PLL(RADEON_PIXCLKS_CNTL, tmp);
8418c2ecf20Sopenharmony_ci		} else {
8428c2ecf20Sopenharmony_ci			tmp = RREG32_PLL(RADEON_SCLK_CNTL);
8438c2ecf20Sopenharmony_ci			tmp |= (RADEON_SCLK_FORCE_CP | RADEON_SCLK_FORCE_E2);
8448c2ecf20Sopenharmony_ci			tmp |= RADEON_SCLK_FORCE_SE;
8458c2ecf20Sopenharmony_ci
8468c2ecf20Sopenharmony_ci			if (rdev->flags & RADEON_SINGLE_CRTC) {
8478c2ecf20Sopenharmony_ci				tmp |= (RADEON_SCLK_FORCE_RB |
8488c2ecf20Sopenharmony_ci					RADEON_SCLK_FORCE_TDM |
8498c2ecf20Sopenharmony_ci					RADEON_SCLK_FORCE_TAM |
8508c2ecf20Sopenharmony_ci					RADEON_SCLK_FORCE_PB |
8518c2ecf20Sopenharmony_ci					RADEON_SCLK_FORCE_RE |
8528c2ecf20Sopenharmony_ci					RADEON_SCLK_FORCE_VIP |
8538c2ecf20Sopenharmony_ci					RADEON_SCLK_FORCE_IDCT |
8548c2ecf20Sopenharmony_ci					RADEON_SCLK_FORCE_TOP |
8558c2ecf20Sopenharmony_ci					RADEON_SCLK_FORCE_DISP1 |
8568c2ecf20Sopenharmony_ci					RADEON_SCLK_FORCE_DISP2 |
8578c2ecf20Sopenharmony_ci					RADEON_SCLK_FORCE_HDP);
8588c2ecf20Sopenharmony_ci			} else if ((rdev->family == CHIP_R300) ||
8598c2ecf20Sopenharmony_ci				   (rdev->family == CHIP_R350)) {
8608c2ecf20Sopenharmony_ci				tmp |= (RADEON_SCLK_FORCE_HDP |
8618c2ecf20Sopenharmony_ci					RADEON_SCLK_FORCE_DISP1 |
8628c2ecf20Sopenharmony_ci					RADEON_SCLK_FORCE_DISP2 |
8638c2ecf20Sopenharmony_ci					RADEON_SCLK_FORCE_TOP |
8648c2ecf20Sopenharmony_ci					RADEON_SCLK_FORCE_IDCT |
8658c2ecf20Sopenharmony_ci					RADEON_SCLK_FORCE_VIP);
8668c2ecf20Sopenharmony_ci			}
8678c2ecf20Sopenharmony_ci			WREG32_PLL(RADEON_SCLK_CNTL, tmp);
8688c2ecf20Sopenharmony_ci
8698c2ecf20Sopenharmony_ci			mdelay(16);
8708c2ecf20Sopenharmony_ci
8718c2ecf20Sopenharmony_ci			if ((rdev->family == CHIP_R300) ||
8728c2ecf20Sopenharmony_ci			    (rdev->family == CHIP_R350)) {
8738c2ecf20Sopenharmony_ci				tmp = RREG32_PLL(R300_SCLK_CNTL2);
8748c2ecf20Sopenharmony_ci				tmp |= (R300_SCLK_FORCE_TCL |
8758c2ecf20Sopenharmony_ci					R300_SCLK_FORCE_GA |
8768c2ecf20Sopenharmony_ci					R300_SCLK_FORCE_CBA);
8778c2ecf20Sopenharmony_ci				WREG32_PLL(R300_SCLK_CNTL2, tmp);
8788c2ecf20Sopenharmony_ci				mdelay(16);
8798c2ecf20Sopenharmony_ci			}
8808c2ecf20Sopenharmony_ci
8818c2ecf20Sopenharmony_ci			if (rdev->flags & RADEON_IS_IGP) {
8828c2ecf20Sopenharmony_ci				tmp = RREG32_PLL(RADEON_MCLK_CNTL);
8838c2ecf20Sopenharmony_ci				tmp &= ~(RADEON_FORCEON_MCLKA |
8848c2ecf20Sopenharmony_ci					 RADEON_FORCEON_YCLKA);
8858c2ecf20Sopenharmony_ci				WREG32_PLL(RADEON_MCLK_CNTL, tmp);
8868c2ecf20Sopenharmony_ci				mdelay(16);
8878c2ecf20Sopenharmony_ci			}
8888c2ecf20Sopenharmony_ci
8898c2ecf20Sopenharmony_ci			if ((rdev->family == CHIP_RV200) ||
8908c2ecf20Sopenharmony_ci			    (rdev->family == CHIP_RV250) ||
8918c2ecf20Sopenharmony_ci			    (rdev->family == CHIP_RV280)) {
8928c2ecf20Sopenharmony_ci				tmp = RREG32_PLL(RADEON_SCLK_MORE_CNTL);
8938c2ecf20Sopenharmony_ci				tmp |= RADEON_SCLK_MORE_FORCEON;
8948c2ecf20Sopenharmony_ci				WREG32_PLL(RADEON_SCLK_MORE_CNTL, tmp);
8958c2ecf20Sopenharmony_ci				mdelay(16);
8968c2ecf20Sopenharmony_ci			}
8978c2ecf20Sopenharmony_ci
8988c2ecf20Sopenharmony_ci			tmp = RREG32_PLL(RADEON_PIXCLKS_CNTL);
8998c2ecf20Sopenharmony_ci			tmp &= ~(RADEON_PIX2CLK_ALWAYS_ONb |
9008c2ecf20Sopenharmony_ci				 RADEON_PIX2CLK_DAC_ALWAYS_ONb |
9018c2ecf20Sopenharmony_ci				 RADEON_PIXCLK_BLEND_ALWAYS_ONb |
9028c2ecf20Sopenharmony_ci				 RADEON_PIXCLK_GV_ALWAYS_ONb |
9038c2ecf20Sopenharmony_ci				 RADEON_PIXCLK_DIG_TMDS_ALWAYS_ONb |
9048c2ecf20Sopenharmony_ci				 RADEON_PIXCLK_LVDS_ALWAYS_ONb |
9058c2ecf20Sopenharmony_ci				 RADEON_PIXCLK_TMDS_ALWAYS_ONb);
9068c2ecf20Sopenharmony_ci
9078c2ecf20Sopenharmony_ci			WREG32_PLL(RADEON_PIXCLKS_CNTL, tmp);
9088c2ecf20Sopenharmony_ci			mdelay(16);
9098c2ecf20Sopenharmony_ci
9108c2ecf20Sopenharmony_ci			tmp = RREG32_PLL(RADEON_VCLK_ECP_CNTL);
9118c2ecf20Sopenharmony_ci			tmp &= ~(RADEON_PIXCLK_ALWAYS_ONb |
9128c2ecf20Sopenharmony_ci				 RADEON_PIXCLK_DAC_ALWAYS_ONb);
9138c2ecf20Sopenharmony_ci			WREG32_PLL(RADEON_VCLK_ECP_CNTL, tmp);
9148c2ecf20Sopenharmony_ci		}
9158c2ecf20Sopenharmony_ci	}
9168c2ecf20Sopenharmony_ci}
9178c2ecf20Sopenharmony_ci
918