xref: /rk3399_rockchip-uboot/arch/powerpc/cpu/mpc85xx/speed.c (revision 3e83fc9b4d898e3e97a6079d103c1e3dc53ca5cc)
1a47a12beSStefan Roese /*
2beba93edSDipen Dudhat  * Copyright 2004, 2007-2011 Freescale Semiconductor, Inc.
3a47a12beSStefan Roese  *
4a47a12beSStefan Roese  * (C) Copyright 2003 Motorola Inc.
5a47a12beSStefan Roese  * Xianghua Xiao, (X.Xiao@motorola.com)
6a47a12beSStefan Roese  *
7a47a12beSStefan Roese  * (C) Copyright 2000
8a47a12beSStefan Roese  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
9a47a12beSStefan Roese  *
10a47a12beSStefan Roese  * See file CREDITS for list of people who contributed to this
11a47a12beSStefan Roese  * project.
12a47a12beSStefan Roese  *
13a47a12beSStefan Roese  * This program is free software; you can redistribute it and/or
14a47a12beSStefan Roese  * modify it under the terms of the GNU General Public License as
15a47a12beSStefan Roese  * published by the Free Software Foundation; either version 2 of
16a47a12beSStefan Roese  * the License, or (at your option) any later version.
17a47a12beSStefan Roese  *
18a47a12beSStefan Roese  * This program is distributed in the hope that it will be useful,
19a47a12beSStefan Roese  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20a47a12beSStefan Roese  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21a47a12beSStefan Roese  * GNU General Public License for more details.
22a47a12beSStefan Roese  *
23a47a12beSStefan Roese  * You should have received a copy of the GNU General Public License
24a47a12beSStefan Roese  * along with this program; if not, write to the Free Software
25a47a12beSStefan Roese  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26a47a12beSStefan Roese  * MA 02111-1307 USA
27a47a12beSStefan Roese  */
28a47a12beSStefan Roese 
29a47a12beSStefan Roese #include <common.h>
30a47a12beSStefan Roese #include <ppc_asm.tmpl>
31a52d2f81SHaiying Wang #include <linux/compiler.h>
32a47a12beSStefan Roese #include <asm/processor.h>
33a47a12beSStefan Roese #include <asm/io.h>
34a47a12beSStefan Roese 
35a47a12beSStefan Roese DECLARE_GLOBAL_DATA_PTR;
36a47a12beSStefan Roese 
37a47a12beSStefan Roese /* --------------------------------------------------------------- */
38a47a12beSStefan Roese 
39a47a12beSStefan Roese void get_sys_info (sys_info_t * sysInfo)
40a47a12beSStefan Roese {
41a47a12beSStefan Roese 	volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
42800c73c4SKumar Gala #ifdef CONFIG_FSL_IFC
43800c73c4SKumar Gala 	struct fsl_ifc *ifc_regs = (void *)CONFIG_SYS_IFC_ADDR;
44800c73c4SKumar Gala 	u32 ccr;
45800c73c4SKumar Gala #endif
46a47a12beSStefan Roese #ifdef CONFIG_FSL_CORENET
47a47a12beSStefan Roese 	volatile ccsr_clk_t *clk = (void *)(CONFIG_SYS_FSL_CORENET_CLK_ADDR);
48fbb9ecf7STimur Tabi 	unsigned int cpu;
49a47a12beSStefan Roese 
50a47a12beSStefan Roese 	const u8 core_cplx_PLL[16] = {
51a47a12beSStefan Roese 		[ 0] = 0,	/* CC1 PPL / 1 */
52a47a12beSStefan Roese 		[ 1] = 0,	/* CC1 PPL / 2 */
53a47a12beSStefan Roese 		[ 2] = 0,	/* CC1 PPL / 4 */
54a47a12beSStefan Roese 		[ 4] = 1,	/* CC2 PPL / 1 */
55a47a12beSStefan Roese 		[ 5] = 1,	/* CC2 PPL / 2 */
56a47a12beSStefan Roese 		[ 6] = 1,	/* CC2 PPL / 4 */
57a47a12beSStefan Roese 		[ 8] = 2,	/* CC3 PPL / 1 */
58a47a12beSStefan Roese 		[ 9] = 2,	/* CC3 PPL / 2 */
59a47a12beSStefan Roese 		[10] = 2,	/* CC3 PPL / 4 */
60a47a12beSStefan Roese 		[12] = 3,	/* CC4 PPL / 1 */
61a47a12beSStefan Roese 		[13] = 3,	/* CC4 PPL / 2 */
62a47a12beSStefan Roese 		[14] = 3,	/* CC4 PPL / 4 */
63a47a12beSStefan Roese 	};
64a47a12beSStefan Roese 
65a47a12beSStefan Roese 	const u8 core_cplx_PLL_div[16] = {
66a47a12beSStefan Roese 		[ 0] = 1,	/* CC1 PPL / 1 */
67a47a12beSStefan Roese 		[ 1] = 2,	/* CC1 PPL / 2 */
68a47a12beSStefan Roese 		[ 2] = 4,	/* CC1 PPL / 4 */
69a47a12beSStefan Roese 		[ 4] = 1,	/* CC2 PPL / 1 */
70a47a12beSStefan Roese 		[ 5] = 2,	/* CC2 PPL / 2 */
71a47a12beSStefan Roese 		[ 6] = 4,	/* CC2 PPL / 4 */
72a47a12beSStefan Roese 		[ 8] = 1,	/* CC3 PPL / 1 */
73a47a12beSStefan Roese 		[ 9] = 2,	/* CC3 PPL / 2 */
74a47a12beSStefan Roese 		[10] = 4,	/* CC3 PPL / 4 */
75a47a12beSStefan Roese 		[12] = 1,	/* CC4 PPL / 1 */
76a47a12beSStefan Roese 		[13] = 2,	/* CC4 PPL / 2 */
77a47a12beSStefan Roese 		[14] = 4,	/* CC4 PPL / 4 */
78a47a12beSStefan Roese 	};
799a653a98SYork Sun 	uint i, freqCC_PLL[6], rcw_tmp;
809a653a98SYork Sun 	uint ratio[6];
81a47a12beSStefan Roese 	unsigned long sysclk = CONFIG_SYS_CLK_FREQ;
82ab48ca1aSSrikanth Srinivasan 	uint mem_pll_rat;
83a47a12beSStefan Roese 
84a47a12beSStefan Roese 	sysInfo->freqSystemBus = sysclk;
8598ffa190SYork Sun #ifdef CONFIG_DDR_CLK_FREQ
8698ffa190SYork Sun 	sysInfo->freqDDRBus = CONFIG_DDR_CLK_FREQ;
8798ffa190SYork Sun #else
88a47a12beSStefan Roese 	sysInfo->freqDDRBus = sysclk;
8998ffa190SYork Sun #endif
90a47a12beSStefan Roese 
91a47a12beSStefan Roese 	sysInfo->freqSystemBus *= (in_be32(&gur->rcwsr[0]) >> 25) & 0x1f;
92f77329cfSYork Sun 	mem_pll_rat = (in_be32(&gur->rcwsr[0]) >>
93f77329cfSYork Sun 			FSL_CORENET_RCWSR0_MEM_PLL_RAT_SHIFT)
94f77329cfSYork Sun 			& FSL_CORENET_RCWSR0_MEM_PLL_RAT_MASK;
95ab48ca1aSSrikanth Srinivasan 	if (mem_pll_rat > 2)
96ab48ca1aSSrikanth Srinivasan 		sysInfo->freqDDRBus *= mem_pll_rat;
97ab48ca1aSSrikanth Srinivasan 	else
98ab48ca1aSSrikanth Srinivasan 		sysInfo->freqDDRBus = sysInfo->freqSystemBus * mem_pll_rat;
99a47a12beSStefan Roese 
100ab48ca1aSSrikanth Srinivasan 	ratio[0] = (in_be32(&clk->pllc1gsr) >> 1) & 0x3f;
101ab48ca1aSSrikanth Srinivasan 	ratio[1] = (in_be32(&clk->pllc2gsr) >> 1) & 0x3f;
102ab48ca1aSSrikanth Srinivasan 	ratio[2] = (in_be32(&clk->pllc3gsr) >> 1) & 0x3f;
103ab48ca1aSSrikanth Srinivasan 	ratio[3] = (in_be32(&clk->pllc4gsr) >> 1) & 0x3f;
1049a653a98SYork Sun 	ratio[4] = (in_be32(&clk->pllc5gsr) >> 1) & 0x3f;
1059a653a98SYork Sun 	ratio[5] = (in_be32(&clk->pllc6gsr) >> 1) & 0x3f;
1069a653a98SYork Sun 	for (i = 0; i < 6; i++) {
107ab48ca1aSSrikanth Srinivasan 		if (ratio[i] > 4)
108ab48ca1aSSrikanth Srinivasan 			freqCC_PLL[i] = sysclk * ratio[i];
109ab48ca1aSSrikanth Srinivasan 		else
110ab48ca1aSSrikanth Srinivasan 			freqCC_PLL[i] = sysInfo->freqSystemBus * ratio[i];
111ab48ca1aSSrikanth Srinivasan 	}
1129a653a98SYork Sun #ifdef CONFIG_SYS_FSL_QORIQ_CHASSIS2
1139a653a98SYork Sun 	/*
1149a653a98SYork Sun 	 * Each cluster has up to 4 cores, sharing the same PLL selection.
1159a653a98SYork Sun 	 * The cluster assignment is fixed per SoC. There is no way identify the
1169a653a98SYork Sun 	 * assignment so far, presuming the "first configuration" which is to
1179a653a98SYork Sun 	 * fill the lower cluster group first before moving up to next group.
1189a653a98SYork Sun 	 * PLL1, PLL2, PLL3 are cluster group A, feeding core 0~3 on cluster 1
1199a653a98SYork Sun 	 * and core 4~7 on cluster 2
1209a653a98SYork Sun 	 * PLL4, PLL5, PLL6 are cluster group B, feeding core 8~11 on cluster 3
1219a653a98SYork Sun 	 * and core 12~15 on cluster 4 if existing
1229a653a98SYork Sun 	 */
1239a653a98SYork Sun 	for_each_cpu(i, cpu, cpu_numcores(), cpu_mask()) {
1249a653a98SYork Sun 		u32 c_pll_sel = (in_be32(&clk->clkc0csr + (cpu / 4) * 8) >> 27)
1259a653a98SYork Sun 				& 0xf;
1269a653a98SYork Sun 		u32 cplx_pll = core_cplx_PLL[c_pll_sel];
1279a653a98SYork Sun 		if (cplx_pll > 3)
1289a653a98SYork Sun 			printf("Unsupported architecture configuration"
1299a653a98SYork Sun 				" in function %s\n", __func__);
1309a653a98SYork Sun 		cplx_pll += (cpu / 8) * 3;
1319a653a98SYork Sun 
1329a653a98SYork Sun 		sysInfo->freqProcessor[cpu] =
1339a653a98SYork Sun 			 freqCC_PLL[cplx_pll] / core_cplx_PLL_div[c_pll_sel];
1349a653a98SYork Sun 	}
1350cb3325cSSandeep Singh #ifdef CONFIG_PPC_B4860
1360cb3325cSSandeep Singh #define FM1_CLK_SEL	0xe0000000
1370cb3325cSSandeep Singh #define FM1_CLK_SHIFT	29
1380cb3325cSSandeep Singh #else
1399a653a98SYork Sun #define PME_CLK_SEL	0xe0000000
1409a653a98SYork Sun #define PME_CLK_SHIFT	29
1419a653a98SYork Sun #define FM1_CLK_SEL	0x1c000000
1429a653a98SYork Sun #define FM1_CLK_SHIFT	26
1430cb3325cSSandeep Singh #endif
1449a653a98SYork Sun 	rcw_tmp = in_be32(&gur->rcwsr[7]);
1459a653a98SYork Sun 
1469a653a98SYork Sun #ifdef CONFIG_SYS_DPAA_PME
1479a653a98SYork Sun 	switch ((rcw_tmp & PME_CLK_SEL) >> PME_CLK_SHIFT) {
1489a653a98SYork Sun 	case 1:
1499a653a98SYork Sun 		sysInfo->freqPME = freqCC_PLL[0];
1509a653a98SYork Sun 		break;
1519a653a98SYork Sun 	case 2:
1529a653a98SYork Sun 		sysInfo->freqPME = freqCC_PLL[0] / 2;
1539a653a98SYork Sun 		break;
1549a653a98SYork Sun 	case 3:
1559a653a98SYork Sun 		sysInfo->freqPME = freqCC_PLL[0] / 3;
1569a653a98SYork Sun 		break;
1579a653a98SYork Sun 	case 4:
1589a653a98SYork Sun 		sysInfo->freqPME = freqCC_PLL[0] / 4;
1599a653a98SYork Sun 		break;
1609a653a98SYork Sun 	case 6:
1619a653a98SYork Sun 		sysInfo->freqPME = freqCC_PLL[1] / 2;
1629a653a98SYork Sun 		break;
1639a653a98SYork Sun 	case 7:
1649a653a98SYork Sun 		sysInfo->freqPME = freqCC_PLL[1] / 3;
1659a653a98SYork Sun 		break;
1669a653a98SYork Sun 	default:
1679a653a98SYork Sun 		printf("Error: Unknown PME clock select!\n");
1689a653a98SYork Sun 	case 0:
1699a653a98SYork Sun 		sysInfo->freqPME = sysInfo->freqSystemBus / 2;
1709a653a98SYork Sun 		break;
1719a653a98SYork Sun 
1729a653a98SYork Sun 	}
1739a653a98SYork Sun #endif
1749a653a98SYork Sun 
175990e1a8cSHaiying Wang #ifdef CONFIG_SYS_DPAA_QBMAN
176990e1a8cSHaiying Wang 	sysInfo->freqQMAN = sysInfo->freqSystemBus / 2;
177990e1a8cSHaiying Wang #endif
178990e1a8cSHaiying Wang 
1799a653a98SYork Sun #ifdef CONFIG_SYS_DPAA_FMAN
1809a653a98SYork Sun 	switch ((rcw_tmp & FM1_CLK_SEL) >> FM1_CLK_SHIFT) {
1819a653a98SYork Sun 	case 1:
1829a653a98SYork Sun 		sysInfo->freqFMan[0] = freqCC_PLL[3];
1839a653a98SYork Sun 		break;
1849a653a98SYork Sun 	case 2:
1859a653a98SYork Sun 		sysInfo->freqFMan[0] = freqCC_PLL[3] / 2;
1869a653a98SYork Sun 		break;
1879a653a98SYork Sun 	case 3:
1889a653a98SYork Sun 		sysInfo->freqFMan[0] = freqCC_PLL[3] / 3;
1899a653a98SYork Sun 		break;
1909a653a98SYork Sun 	case 4:
1919a653a98SYork Sun 		sysInfo->freqFMan[0] = freqCC_PLL[3] / 4;
1929a653a98SYork Sun 		break;
1930cb3325cSSandeep Singh 	case 5:
1940cb3325cSSandeep Singh 		sysInfo->freqFMan[0] = sysInfo->freqSystemBus;
1950cb3325cSSandeep Singh 		break;
1969a653a98SYork Sun 	case 6:
1979a653a98SYork Sun 		sysInfo->freqFMan[0] = freqCC_PLL[4] / 2;
1989a653a98SYork Sun 		break;
1999a653a98SYork Sun 	case 7:
2009a653a98SYork Sun 		sysInfo->freqFMan[0] = freqCC_PLL[4] / 3;
2019a653a98SYork Sun 		break;
2029a653a98SYork Sun 	default:
2039a653a98SYork Sun 		printf("Error: Unknown FMan1 clock select!\n");
2049a653a98SYork Sun 	case 0:
2059a653a98SYork Sun 		sysInfo->freqFMan[0] = sysInfo->freqSystemBus / 2;
2069a653a98SYork Sun 		break;
2079a653a98SYork Sun 	}
2089a653a98SYork Sun #if (CONFIG_SYS_NUM_FMAN) == 2
2099a653a98SYork Sun #define FM2_CLK_SEL	0x00000038
2109a653a98SYork Sun #define FM2_CLK_SHIFT	3
2119a653a98SYork Sun 	rcw_tmp = in_be32(&gur->rcwsr[15]);
2129a653a98SYork Sun 	switch ((rcw_tmp & FM2_CLK_SEL) >> FM2_CLK_SHIFT) {
2139a653a98SYork Sun 	case 1:
2149a653a98SYork Sun 		sysInfo->freqFMan[1] = freqCC_PLL[4];
2159a653a98SYork Sun 		break;
2169a653a98SYork Sun 	case 2:
2179a653a98SYork Sun 		sysInfo->freqFMan[1] = freqCC_PLL[4] / 2;
2189a653a98SYork Sun 		break;
2199a653a98SYork Sun 	case 3:
2209a653a98SYork Sun 		sysInfo->freqFMan[1] = freqCC_PLL[4] / 3;
2219a653a98SYork Sun 		break;
2229a653a98SYork Sun 	case 4:
2239a653a98SYork Sun 		sysInfo->freqFMan[1] = freqCC_PLL[4] / 4;
2249a653a98SYork Sun 		break;
2259a653a98SYork Sun 	case 6:
2269a653a98SYork Sun 		sysInfo->freqFMan[1] = freqCC_PLL[3] / 2;
2279a653a98SYork Sun 		break;
2289a653a98SYork Sun 	case 7:
2299a653a98SYork Sun 		sysInfo->freqFMan[1] = freqCC_PLL[3] / 3;
2309a653a98SYork Sun 		break;
2319a653a98SYork Sun 	default:
2329a653a98SYork Sun 		printf("Error: Unknown FMan2 clock select!\n");
2339a653a98SYork Sun 	case 0:
2349a653a98SYork Sun 		sysInfo->freqFMan[1] = sysInfo->freqSystemBus / 2;
2359a653a98SYork Sun 		break;
2369a653a98SYork Sun 	}
2379a653a98SYork Sun #endif	/* CONFIG_SYS_NUM_FMAN == 2 */
2389a653a98SYork Sun #endif	/* CONFIG_SYS_DPAA_FMAN */
2399a653a98SYork Sun 
2409a653a98SYork Sun #else /* CONFIG_SYS_FSL_QORIQ_CHASSIS2 */
2419a653a98SYork Sun 
242fbb9ecf7STimur Tabi 	for_each_cpu(i, cpu, cpu_numcores(), cpu_mask()) {
243fbb9ecf7STimur Tabi 		u32 c_pll_sel = (in_be32(&clk->clkc0csr + cpu*8) >> 27) & 0xf;
244a47a12beSStefan Roese 		u32 cplx_pll = core_cplx_PLL[c_pll_sel];
245a47a12beSStefan Roese 
246fbb9ecf7STimur Tabi 		sysInfo->freqProcessor[cpu] =
247a47a12beSStefan Roese 			 freqCC_PLL[cplx_pll] / core_cplx_PLL_div[c_pll_sel];
248a47a12beSStefan Roese 	}
249a47a12beSStefan Roese #define PME_CLK_SEL	0x80000000
250a47a12beSStefan Roese #define FM1_CLK_SEL	0x40000000
251a47a12beSStefan Roese #define FM2_CLK_SEL	0x20000000
252b5c8753fSKumar Gala #define HWA_ASYNC_DIV	0x04000000
253b5c8753fSKumar Gala #if (CONFIG_SYS_FSL_NUM_CC_PLLS == 2)
254b5c8753fSKumar Gala #define HWA_CC_PLL	1
2554905443fSTimur Tabi #elif (CONFIG_SYS_FSL_NUM_CC_PLLS == 3)
2564905443fSTimur Tabi #define HWA_CC_PLL	2
257b5c8753fSKumar Gala #elif (CONFIG_SYS_FSL_NUM_CC_PLLS == 4)
258b5c8753fSKumar Gala #define HWA_CC_PLL	2
259b5c8753fSKumar Gala #else
260b5c8753fSKumar Gala #error CONFIG_SYS_FSL_NUM_CC_PLLS not set or unknown case
261b5c8753fSKumar Gala #endif
262a47a12beSStefan Roese 	rcw_tmp = in_be32(&gur->rcwsr[7]);
263a47a12beSStefan Roese 
264a47a12beSStefan Roese #ifdef CONFIG_SYS_DPAA_PME
265b5c8753fSKumar Gala 	if (rcw_tmp & PME_CLK_SEL) {
266b5c8753fSKumar Gala 		if (rcw_tmp & HWA_ASYNC_DIV)
267b5c8753fSKumar Gala 			sysInfo->freqPME = freqCC_PLL[HWA_CC_PLL] / 4;
268a47a12beSStefan Roese 		else
269b5c8753fSKumar Gala 			sysInfo->freqPME = freqCC_PLL[HWA_CC_PLL] / 2;
270b5c8753fSKumar Gala 	} else {
271a47a12beSStefan Roese 		sysInfo->freqPME = sysInfo->freqSystemBus / 2;
272b5c8753fSKumar Gala 	}
273a47a12beSStefan Roese #endif
274a47a12beSStefan Roese 
275a47a12beSStefan Roese #ifdef CONFIG_SYS_DPAA_FMAN
276b5c8753fSKumar Gala 	if (rcw_tmp & FM1_CLK_SEL) {
277b5c8753fSKumar Gala 		if (rcw_tmp & HWA_ASYNC_DIV)
278b5c8753fSKumar Gala 			sysInfo->freqFMan[0] = freqCC_PLL[HWA_CC_PLL] / 4;
279a47a12beSStefan Roese 		else
280b5c8753fSKumar Gala 			sysInfo->freqFMan[0] = freqCC_PLL[HWA_CC_PLL] / 2;
281b5c8753fSKumar Gala 	} else {
282a47a12beSStefan Roese 		sysInfo->freqFMan[0] = sysInfo->freqSystemBus / 2;
283b5c8753fSKumar Gala 	}
284a47a12beSStefan Roese #if (CONFIG_SYS_NUM_FMAN) == 2
285b5c8753fSKumar Gala 	if (rcw_tmp & FM2_CLK_SEL) {
286b5c8753fSKumar Gala 		if (rcw_tmp & HWA_ASYNC_DIV)
287b5c8753fSKumar Gala 			sysInfo->freqFMan[1] = freqCC_PLL[HWA_CC_PLL] / 4;
288a47a12beSStefan Roese 		else
289b5c8753fSKumar Gala 			sysInfo->freqFMan[1] = freqCC_PLL[HWA_CC_PLL] / 2;
290b5c8753fSKumar Gala 	} else {
291a47a12beSStefan Roese 		sysInfo->freqFMan[1] = sysInfo->freqSystemBus / 2;
292b5c8753fSKumar Gala 	}
293a47a12beSStefan Roese #endif
294a47a12beSStefan Roese #endif
295a47a12beSStefan Roese 
296*3e83fc9bSShaohui Xie #ifdef CONFIG_SYS_DPAA_QBMAN
297*3e83fc9bSShaohui Xie 	sysInfo->freqQMAN = sysInfo->freqSystemBus / 2;
298*3e83fc9bSShaohui Xie #endif
299*3e83fc9bSShaohui Xie 
3009a653a98SYork Sun #endif /* CONFIG_SYS_FSL_QORIQ_CHASSIS2 */
3019a653a98SYork Sun 
3029a653a98SYork Sun #else /* CONFIG_FSL_CORENET */
303a47a12beSStefan Roese 	uint plat_ratio, e500_ratio, half_freqSystemBus;
304a47a12beSStefan Roese 	int i;
305a47a12beSStefan Roese #ifdef CONFIG_QE
306a52d2f81SHaiying Wang 	__maybe_unused u32 qe_ratio;
307a47a12beSStefan Roese #endif
308a47a12beSStefan Roese 
309a47a12beSStefan Roese 	plat_ratio = (gur->porpllsr) & 0x0000003e;
310a47a12beSStefan Roese 	plat_ratio >>= 1;
311a47a12beSStefan Roese 	sysInfo->freqSystemBus = plat_ratio * CONFIG_SYS_CLK_FREQ;
312a47a12beSStefan Roese 
313a47a12beSStefan Roese 	/* Divide before multiply to avoid integer
314a47a12beSStefan Roese 	 * overflow for processor speeds above 2GHz */
315a47a12beSStefan Roese 	half_freqSystemBus = sysInfo->freqSystemBus/2;
316a47a12beSStefan Roese 	for (i = 0; i < cpu_numcores(); i++) {
317a47a12beSStefan Roese 		e500_ratio = ((gur->porpllsr) >> (i * 8 + 16)) & 0x3f;
318a47a12beSStefan Roese 		sysInfo->freqProcessor[i] = e500_ratio * half_freqSystemBus;
319a47a12beSStefan Roese 	}
320a47a12beSStefan Roese 
321a47a12beSStefan Roese 	/* Note: freqDDRBus is the MCLK frequency, not the data rate. */
322a47a12beSStefan Roese 	sysInfo->freqDDRBus = sysInfo->freqSystemBus;
323a47a12beSStefan Roese 
324a47a12beSStefan Roese #ifdef CONFIG_DDR_CLK_FREQ
325a47a12beSStefan Roese 	{
326a47a12beSStefan Roese 		u32 ddr_ratio = ((gur->porpllsr) & MPC85xx_PORPLLSR_DDR_RATIO)
327a47a12beSStefan Roese 			>> MPC85xx_PORPLLSR_DDR_RATIO_SHIFT;
328a47a12beSStefan Roese 		if (ddr_ratio != 0x7)
329a47a12beSStefan Roese 			sysInfo->freqDDRBus = ddr_ratio * CONFIG_DDR_CLK_FREQ;
330a47a12beSStefan Roese 	}
331a47a12beSStefan Roese #endif
332a47a12beSStefan Roese 
333a47a12beSStefan Roese #ifdef CONFIG_QE
334be7bebeaSYork Sun #if defined(CONFIG_P1012) || defined(CONFIG_P1021) || defined(CONFIG_P1025)
335a52d2f81SHaiying Wang 	sysInfo->freqQE =  sysInfo->freqSystemBus;
336a52d2f81SHaiying Wang #else
337a47a12beSStefan Roese 	qe_ratio = ((gur->porpllsr) & MPC85xx_PORPLLSR_QE_RATIO)
338a47a12beSStefan Roese 			>> MPC85xx_PORPLLSR_QE_RATIO_SHIFT;
339a47a12beSStefan Roese 	sysInfo->freqQE = qe_ratio * CONFIG_SYS_CLK_FREQ;
340a47a12beSStefan Roese #endif
341a52d2f81SHaiying Wang #endif
342a47a12beSStefan Roese 
34324995d82SHaiying Wang #ifdef CONFIG_SYS_DPAA_FMAN
344939cdcdcSKumar Gala 		sysInfo->freqFMan[0] = sysInfo->freqSystemBus;
34524995d82SHaiying Wang #endif
34624995d82SHaiying Wang 
34724995d82SHaiying Wang #endif /* CONFIG_FSL_CORENET */
34824995d82SHaiying Wang 
349beba93edSDipen Dudhat #if defined(CONFIG_FSL_LBC)
3509a653a98SYork Sun 	uint lcrr_div;
351a47a12beSStefan Roese #if defined(CONFIG_SYS_LBC_LCRR)
352a47a12beSStefan Roese 	/* We will program LCRR to this value later */
353a47a12beSStefan Roese 	lcrr_div = CONFIG_SYS_LBC_LCRR & LCRR_CLKDIV;
354a47a12beSStefan Roese #else
355f51cdaf1SBecky Bruce 	lcrr_div = in_be32(&(LBC_BASE_ADDR)->lcrr) & LCRR_CLKDIV;
356a47a12beSStefan Roese #endif
357a47a12beSStefan Roese 	if (lcrr_div == 2 || lcrr_div == 4 || lcrr_div == 8) {
358a47a12beSStefan Roese #if defined(CONFIG_FSL_CORENET)
359a47a12beSStefan Roese 		/* If this is corenet based SoC, bit-representation
360a47a12beSStefan Roese 		 * for four times the clock divider values.
361a47a12beSStefan Roese 		 */
362a47a12beSStefan Roese 		lcrr_div *= 4;
363a47a12beSStefan Roese #elif !defined(CONFIG_MPC8540) && !defined(CONFIG_MPC8541) && \
364a47a12beSStefan Roese     !defined(CONFIG_MPC8555) && !defined(CONFIG_MPC8560)
365a47a12beSStefan Roese 		/*
366a47a12beSStefan Roese 		 * Yes, the entire PQ38 family use the same
367a47a12beSStefan Roese 		 * bit-representation for twice the clock divider values.
368a47a12beSStefan Roese 		 */
369a47a12beSStefan Roese 		lcrr_div *= 2;
370a47a12beSStefan Roese #endif
371a47a12beSStefan Roese 		sysInfo->freqLocalBus = sysInfo->freqSystemBus / lcrr_div;
372a47a12beSStefan Roese 	} else {
373a47a12beSStefan Roese 		/* In case anyone cares what the unknown value is */
374a47a12beSStefan Roese 		sysInfo->freqLocalBus = lcrr_div;
375a47a12beSStefan Roese 	}
376beba93edSDipen Dudhat #endif
377800c73c4SKumar Gala 
378800c73c4SKumar Gala #if defined(CONFIG_FSL_IFC)
379800c73c4SKumar Gala 	ccr = in_be32(&ifc_regs->ifc_ccr);
380800c73c4SKumar Gala 	ccr = ((ccr & IFC_CCR_CLK_DIV_MASK) >> IFC_CCR_CLK_DIV_SHIFT) + 1;
381800c73c4SKumar Gala 
382800c73c4SKumar Gala 	sysInfo->freqLocalBus = sysInfo->freqSystemBus / ccr;
383800c73c4SKumar Gala #endif
384a47a12beSStefan Roese }
385a47a12beSStefan Roese 
386a47a12beSStefan Roese 
387a47a12beSStefan Roese int get_clocks (void)
388a47a12beSStefan Roese {
389a47a12beSStefan Roese 	sys_info_t sys_info;
390a47a12beSStefan Roese #ifdef CONFIG_MPC8544
391a47a12beSStefan Roese 	volatile ccsr_gur_t *gur = (void *) CONFIG_SYS_MPC85xx_GUTS_ADDR;
392a47a12beSStefan Roese #endif
393a47a12beSStefan Roese #if defined(CONFIG_CPM2)
394a47a12beSStefan Roese 	volatile ccsr_cpm_t *cpm = (ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR;
395a47a12beSStefan Roese 	uint sccr, dfbrg;
396a47a12beSStefan Roese 
397a47a12beSStefan Roese 	/* set VCO = 4 * BRG */
398a47a12beSStefan Roese 	cpm->im_cpm_intctl.sccr &= 0xfffffffc;
399a47a12beSStefan Roese 	sccr = cpm->im_cpm_intctl.sccr;
400a47a12beSStefan Roese 	dfbrg = (sccr & SCCR_DFBRG_MSK) >> SCCR_DFBRG_SHIFT;
401a47a12beSStefan Roese #endif
402a47a12beSStefan Roese 	get_sys_info (&sys_info);
403a47a12beSStefan Roese 	gd->cpu_clk = sys_info.freqProcessor[0];
404a47a12beSStefan Roese 	gd->bus_clk = sys_info.freqSystemBus;
405a47a12beSStefan Roese 	gd->mem_clk = sys_info.freqDDRBus;
40667ac13b1SSimon Glass 	gd->arch.lbc_clk = sys_info.freqLocalBus;
407a47a12beSStefan Roese 
408a47a12beSStefan Roese #ifdef CONFIG_QE
40945bae2e3SSimon Glass 	gd->arch.qe_clk = sys_info.freqQE;
41045bae2e3SSimon Glass 	gd->arch.brg_clk = gd->arch.qe_clk / 2;
411a47a12beSStefan Roese #endif
412a47a12beSStefan Roese 	/*
413a47a12beSStefan Roese 	 * The base clock for I2C depends on the actual SOC.  Unfortunately,
414a47a12beSStefan Roese 	 * there is no pattern that can be used to determine the frequency, so
415a47a12beSStefan Roese 	 * the only choice is to look up the actual SOC number and use the value
416a47a12beSStefan Roese 	 * for that SOC. This information is taken from application note
417a47a12beSStefan Roese 	 * AN2919.
418a47a12beSStefan Roese 	 */
419a47a12beSStefan Roese #if defined(CONFIG_MPC8540) || defined(CONFIG_MPC8541) || \
420a47a12beSStefan Roese 	defined(CONFIG_MPC8560) || defined(CONFIG_MPC8555)
421609e6ec3SSimon Glass 	gd->arch.i2c1_clk = sys_info.freqSystemBus;
422a47a12beSStefan Roese #elif defined(CONFIG_MPC8544)
423a47a12beSStefan Roese 	/*
424a47a12beSStefan Roese 	 * On the 8544, the I2C clock is the same as the SEC clock.  This can be
425a47a12beSStefan Roese 	 * either CCB/2 or CCB/3, depending on the value of cfg_sec_freq. See
426a47a12beSStefan Roese 	 * 4.4.3.3 of the 8544 RM.  Note that this might actually work for all
427a47a12beSStefan Roese 	 * 85xx, but only the 8544 has cfg_sec_freq, so it's unknown if the
428a47a12beSStefan Roese 	 * PORDEVSR2_SEC_CFG bit is 0 on all 85xx boards that are not an 8544.
429a47a12beSStefan Roese 	 */
430a47a12beSStefan Roese 	if (gur->pordevsr2 & MPC85xx_PORDEVSR2_SEC_CFG)
431609e6ec3SSimon Glass 		gd->arch.i2c1_clk = sys_info.freqSystemBus / 3;
432a47a12beSStefan Roese 	else
433609e6ec3SSimon Glass 		gd->arch.i2c1_clk = sys_info.freqSystemBus / 2;
434a47a12beSStefan Roese #else
435a47a12beSStefan Roese 	/* Most 85xx SOCs use CCB/2, so this is the default behavior. */
436609e6ec3SSimon Glass 	gd->arch.i2c1_clk = sys_info.freqSystemBus / 2;
437a47a12beSStefan Roese #endif
438609e6ec3SSimon Glass 	gd->arch.i2c2_clk = gd->arch.i2c1_clk;
439a47a12beSStefan Roese 
440a47a12beSStefan Roese #if defined(CONFIG_FSL_ESDHC)
4417d640e9bSPriyanka Jain #if defined(CONFIG_MPC8569) || defined(CONFIG_P1010) ||\
4427d640e9bSPriyanka Jain        defined(CONFIG_P1014)
443e9adeca3SSimon Glass 	gd->arch.sdhc_clk = gd->bus_clk;
444a47a12beSStefan Roese #else
445e9adeca3SSimon Glass 	gd->arch.sdhc_clk = gd->bus_clk / 2;
446a47a12beSStefan Roese #endif
447a47a12beSStefan Roese #endif /* defined(CONFIG_FSL_ESDHC) */
448a47a12beSStefan Roese 
449a47a12beSStefan Roese #if defined(CONFIG_CPM2)
450748cd059SSimon Glass 	gd->arch.vco_out = 2*sys_info.freqSystemBus;
451748cd059SSimon Glass 	gd->arch.cpm_clk = gd->arch.vco_out / 2;
452748cd059SSimon Glass 	gd->arch.scc_clk = gd->arch.vco_out / 4;
453748cd059SSimon Glass 	gd->arch.brg_clk = gd->arch.vco_out / (1 << (2 * (dfbrg + 1)));
454a47a12beSStefan Roese #endif
455a47a12beSStefan Roese 
456a47a12beSStefan Roese 	if(gd->cpu_clk != 0) return (0);
457a47a12beSStefan Roese 	else return (1);
458a47a12beSStefan Roese }
459a47a12beSStefan Roese 
460a47a12beSStefan Roese 
461a47a12beSStefan Roese /********************************************
462a47a12beSStefan Roese  * get_bus_freq
463a47a12beSStefan Roese  * return system bus freq in Hz
464a47a12beSStefan Roese  *********************************************/
465a47a12beSStefan Roese ulong get_bus_freq (ulong dummy)
466a47a12beSStefan Roese {
467a47a12beSStefan Roese 	return gd->bus_clk;
468a47a12beSStefan Roese }
469a47a12beSStefan Roese 
470a47a12beSStefan Roese /********************************************
471a47a12beSStefan Roese  * get_ddr_freq
472a47a12beSStefan Roese  * return ddr bus freq in Hz
473a47a12beSStefan Roese  *********************************************/
474a47a12beSStefan Roese ulong get_ddr_freq (ulong dummy)
475a47a12beSStefan Roese {
476a47a12beSStefan Roese 	return gd->mem_clk;
477a47a12beSStefan Roese }
478