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 } 1359a653a98SYork Sun #define PME_CLK_SEL 0xe0000000 1369a653a98SYork Sun #define PME_CLK_SHIFT 29 1379a653a98SYork Sun #define FM1_CLK_SEL 0x1c000000 1389a653a98SYork Sun #define FM1_CLK_SHIFT 26 1399a653a98SYork Sun rcw_tmp = in_be32(&gur->rcwsr[7]); 1409a653a98SYork Sun 1419a653a98SYork Sun #ifdef CONFIG_SYS_DPAA_PME 1429a653a98SYork Sun switch ((rcw_tmp & PME_CLK_SEL) >> PME_CLK_SHIFT) { 1439a653a98SYork Sun case 1: 1449a653a98SYork Sun sysInfo->freqPME = freqCC_PLL[0]; 1459a653a98SYork Sun break; 1469a653a98SYork Sun case 2: 1479a653a98SYork Sun sysInfo->freqPME = freqCC_PLL[0] / 2; 1489a653a98SYork Sun break; 1499a653a98SYork Sun case 3: 1509a653a98SYork Sun sysInfo->freqPME = freqCC_PLL[0] / 3; 1519a653a98SYork Sun break; 1529a653a98SYork Sun case 4: 1539a653a98SYork Sun sysInfo->freqPME = freqCC_PLL[0] / 4; 1549a653a98SYork Sun break; 1559a653a98SYork Sun case 6: 1569a653a98SYork Sun sysInfo->freqPME = freqCC_PLL[1] / 2; 1579a653a98SYork Sun break; 1589a653a98SYork Sun case 7: 1599a653a98SYork Sun sysInfo->freqPME = freqCC_PLL[1] / 3; 1609a653a98SYork Sun break; 1619a653a98SYork Sun default: 1629a653a98SYork Sun printf("Error: Unknown PME clock select!\n"); 1639a653a98SYork Sun case 0: 1649a653a98SYork Sun sysInfo->freqPME = sysInfo->freqSystemBus / 2; 1659a653a98SYork Sun break; 1669a653a98SYork Sun 1679a653a98SYork Sun } 1689a653a98SYork Sun #endif 1699a653a98SYork Sun 170990e1a8cSHaiying Wang #ifdef CONFIG_SYS_DPAA_QBMAN 171990e1a8cSHaiying Wang sysInfo->freqQMAN = sysInfo->freqSystemBus / 2; 172990e1a8cSHaiying Wang #endif 173990e1a8cSHaiying Wang 1749a653a98SYork Sun #ifdef CONFIG_SYS_DPAA_FMAN 1759a653a98SYork Sun switch ((rcw_tmp & FM1_CLK_SEL) >> FM1_CLK_SHIFT) { 1769a653a98SYork Sun case 1: 1779a653a98SYork Sun sysInfo->freqFMan[0] = freqCC_PLL[3]; 1789a653a98SYork Sun break; 1799a653a98SYork Sun case 2: 1809a653a98SYork Sun sysInfo->freqFMan[0] = freqCC_PLL[3] / 2; 1819a653a98SYork Sun break; 1829a653a98SYork Sun case 3: 1839a653a98SYork Sun sysInfo->freqFMan[0] = freqCC_PLL[3] / 3; 1849a653a98SYork Sun break; 1859a653a98SYork Sun case 4: 1869a653a98SYork Sun sysInfo->freqFMan[0] = freqCC_PLL[3] / 4; 1879a653a98SYork Sun break; 1889a653a98SYork Sun case 6: 1899a653a98SYork Sun sysInfo->freqFMan[0] = freqCC_PLL[4] / 2; 1909a653a98SYork Sun break; 1919a653a98SYork Sun case 7: 1929a653a98SYork Sun sysInfo->freqFMan[0] = freqCC_PLL[4] / 3; 1939a653a98SYork Sun break; 1949a653a98SYork Sun default: 1959a653a98SYork Sun printf("Error: Unknown FMan1 clock select!\n"); 1969a653a98SYork Sun case 0: 1979a653a98SYork Sun sysInfo->freqFMan[0] = sysInfo->freqSystemBus / 2; 1989a653a98SYork Sun break; 1999a653a98SYork Sun } 2009a653a98SYork Sun #if (CONFIG_SYS_NUM_FMAN) == 2 2019a653a98SYork Sun #define FM2_CLK_SEL 0x00000038 2029a653a98SYork Sun #define FM2_CLK_SHIFT 3 2039a653a98SYork Sun rcw_tmp = in_be32(&gur->rcwsr[15]); 2049a653a98SYork Sun switch ((rcw_tmp & FM2_CLK_SEL) >> FM2_CLK_SHIFT) { 2059a653a98SYork Sun case 1: 2069a653a98SYork Sun sysInfo->freqFMan[1] = freqCC_PLL[4]; 2079a653a98SYork Sun break; 2089a653a98SYork Sun case 2: 2099a653a98SYork Sun sysInfo->freqFMan[1] = freqCC_PLL[4] / 2; 2109a653a98SYork Sun break; 2119a653a98SYork Sun case 3: 2129a653a98SYork Sun sysInfo->freqFMan[1] = freqCC_PLL[4] / 3; 2139a653a98SYork Sun break; 2149a653a98SYork Sun case 4: 2159a653a98SYork Sun sysInfo->freqFMan[1] = freqCC_PLL[4] / 4; 2169a653a98SYork Sun break; 2179a653a98SYork Sun case 6: 2189a653a98SYork Sun sysInfo->freqFMan[1] = freqCC_PLL[3] / 2; 2199a653a98SYork Sun break; 2209a653a98SYork Sun case 7: 2219a653a98SYork Sun sysInfo->freqFMan[1] = freqCC_PLL[3] / 3; 2229a653a98SYork Sun break; 2239a653a98SYork Sun default: 2249a653a98SYork Sun printf("Error: Unknown FMan2 clock select!\n"); 2259a653a98SYork Sun case 0: 2269a653a98SYork Sun sysInfo->freqFMan[1] = sysInfo->freqSystemBus / 2; 2279a653a98SYork Sun break; 2289a653a98SYork Sun } 2299a653a98SYork Sun #endif /* CONFIG_SYS_NUM_FMAN == 2 */ 2309a653a98SYork Sun #endif /* CONFIG_SYS_DPAA_FMAN */ 2319a653a98SYork Sun 2329a653a98SYork Sun #else /* CONFIG_SYS_FSL_QORIQ_CHASSIS2 */ 2339a653a98SYork Sun 234fbb9ecf7STimur Tabi for_each_cpu(i, cpu, cpu_numcores(), cpu_mask()) { 235fbb9ecf7STimur Tabi u32 c_pll_sel = (in_be32(&clk->clkc0csr + cpu*8) >> 27) & 0xf; 236a47a12beSStefan Roese u32 cplx_pll = core_cplx_PLL[c_pll_sel]; 237a47a12beSStefan Roese 238fbb9ecf7STimur Tabi sysInfo->freqProcessor[cpu] = 239a47a12beSStefan Roese freqCC_PLL[cplx_pll] / core_cplx_PLL_div[c_pll_sel]; 240a47a12beSStefan Roese } 241a47a12beSStefan Roese #define PME_CLK_SEL 0x80000000 242a47a12beSStefan Roese #define FM1_CLK_SEL 0x40000000 243a47a12beSStefan Roese #define FM2_CLK_SEL 0x20000000 244b5c8753fSKumar Gala #define HWA_ASYNC_DIV 0x04000000 245b5c8753fSKumar Gala #if (CONFIG_SYS_FSL_NUM_CC_PLLS == 2) 246b5c8753fSKumar Gala #define HWA_CC_PLL 1 2474905443fSTimur Tabi #elif (CONFIG_SYS_FSL_NUM_CC_PLLS == 3) 2484905443fSTimur Tabi #define HWA_CC_PLL 2 249b5c8753fSKumar Gala #elif (CONFIG_SYS_FSL_NUM_CC_PLLS == 4) 250b5c8753fSKumar Gala #define HWA_CC_PLL 2 251b5c8753fSKumar Gala #else 252b5c8753fSKumar Gala #error CONFIG_SYS_FSL_NUM_CC_PLLS not set or unknown case 253b5c8753fSKumar Gala #endif 254a47a12beSStefan Roese rcw_tmp = in_be32(&gur->rcwsr[7]); 255a47a12beSStefan Roese 256a47a12beSStefan Roese #ifdef CONFIG_SYS_DPAA_PME 257b5c8753fSKumar Gala if (rcw_tmp & PME_CLK_SEL) { 258b5c8753fSKumar Gala if (rcw_tmp & HWA_ASYNC_DIV) 259b5c8753fSKumar Gala sysInfo->freqPME = freqCC_PLL[HWA_CC_PLL] / 4; 260a47a12beSStefan Roese else 261b5c8753fSKumar Gala sysInfo->freqPME = freqCC_PLL[HWA_CC_PLL] / 2; 262b5c8753fSKumar Gala } else { 263a47a12beSStefan Roese sysInfo->freqPME = sysInfo->freqSystemBus / 2; 264b5c8753fSKumar Gala } 265a47a12beSStefan Roese #endif 266a47a12beSStefan Roese 267a47a12beSStefan Roese #ifdef CONFIG_SYS_DPAA_FMAN 268b5c8753fSKumar Gala if (rcw_tmp & FM1_CLK_SEL) { 269b5c8753fSKumar Gala if (rcw_tmp & HWA_ASYNC_DIV) 270b5c8753fSKumar Gala sysInfo->freqFMan[0] = freqCC_PLL[HWA_CC_PLL] / 4; 271a47a12beSStefan Roese else 272b5c8753fSKumar Gala sysInfo->freqFMan[0] = freqCC_PLL[HWA_CC_PLL] / 2; 273b5c8753fSKumar Gala } else { 274a47a12beSStefan Roese sysInfo->freqFMan[0] = sysInfo->freqSystemBus / 2; 275b5c8753fSKumar Gala } 276a47a12beSStefan Roese #if (CONFIG_SYS_NUM_FMAN) == 2 277b5c8753fSKumar Gala if (rcw_tmp & FM2_CLK_SEL) { 278b5c8753fSKumar Gala if (rcw_tmp & HWA_ASYNC_DIV) 279b5c8753fSKumar Gala sysInfo->freqFMan[1] = freqCC_PLL[HWA_CC_PLL] / 4; 280a47a12beSStefan Roese else 281b5c8753fSKumar Gala sysInfo->freqFMan[1] = freqCC_PLL[HWA_CC_PLL] / 2; 282b5c8753fSKumar Gala } else { 283a47a12beSStefan Roese sysInfo->freqFMan[1] = sysInfo->freqSystemBus / 2; 284b5c8753fSKumar Gala } 285a47a12beSStefan Roese #endif 286a47a12beSStefan Roese #endif 287a47a12beSStefan Roese 2889a653a98SYork Sun #endif /* CONFIG_SYS_FSL_QORIQ_CHASSIS2 */ 2899a653a98SYork Sun 2909a653a98SYork Sun #else /* CONFIG_FSL_CORENET */ 291a47a12beSStefan Roese uint plat_ratio, e500_ratio, half_freqSystemBus; 292a47a12beSStefan Roese int i; 293a47a12beSStefan Roese #ifdef CONFIG_QE 294a52d2f81SHaiying Wang __maybe_unused u32 qe_ratio; 295a47a12beSStefan Roese #endif 296a47a12beSStefan Roese 297a47a12beSStefan Roese plat_ratio = (gur->porpllsr) & 0x0000003e; 298a47a12beSStefan Roese plat_ratio >>= 1; 299a47a12beSStefan Roese sysInfo->freqSystemBus = plat_ratio * CONFIG_SYS_CLK_FREQ; 300a47a12beSStefan Roese 301a47a12beSStefan Roese /* Divide before multiply to avoid integer 302a47a12beSStefan Roese * overflow for processor speeds above 2GHz */ 303a47a12beSStefan Roese half_freqSystemBus = sysInfo->freqSystemBus/2; 304a47a12beSStefan Roese for (i = 0; i < cpu_numcores(); i++) { 305a47a12beSStefan Roese e500_ratio = ((gur->porpllsr) >> (i * 8 + 16)) & 0x3f; 306a47a12beSStefan Roese sysInfo->freqProcessor[i] = e500_ratio * half_freqSystemBus; 307a47a12beSStefan Roese } 308a47a12beSStefan Roese 309a47a12beSStefan Roese /* Note: freqDDRBus is the MCLK frequency, not the data rate. */ 310a47a12beSStefan Roese sysInfo->freqDDRBus = sysInfo->freqSystemBus; 311a47a12beSStefan Roese 312a47a12beSStefan Roese #ifdef CONFIG_DDR_CLK_FREQ 313a47a12beSStefan Roese { 314a47a12beSStefan Roese u32 ddr_ratio = ((gur->porpllsr) & MPC85xx_PORPLLSR_DDR_RATIO) 315a47a12beSStefan Roese >> MPC85xx_PORPLLSR_DDR_RATIO_SHIFT; 316a47a12beSStefan Roese if (ddr_ratio != 0x7) 317a47a12beSStefan Roese sysInfo->freqDDRBus = ddr_ratio * CONFIG_DDR_CLK_FREQ; 318a47a12beSStefan Roese } 319a47a12beSStefan Roese #endif 320a47a12beSStefan Roese 321a47a12beSStefan Roese #ifdef CONFIG_QE 322be7bebeaSYork Sun #if defined(CONFIG_P1012) || defined(CONFIG_P1021) || defined(CONFIG_P1025) 323a52d2f81SHaiying Wang sysInfo->freqQE = sysInfo->freqSystemBus; 324a52d2f81SHaiying Wang #else 325a47a12beSStefan Roese qe_ratio = ((gur->porpllsr) & MPC85xx_PORPLLSR_QE_RATIO) 326a47a12beSStefan Roese >> MPC85xx_PORPLLSR_QE_RATIO_SHIFT; 327a47a12beSStefan Roese sysInfo->freqQE = qe_ratio * CONFIG_SYS_CLK_FREQ; 328a47a12beSStefan Roese #endif 329a52d2f81SHaiying Wang #endif 330a47a12beSStefan Roese 33124995d82SHaiying Wang #ifdef CONFIG_SYS_DPAA_FMAN 332939cdcdcSKumar Gala sysInfo->freqFMan[0] = sysInfo->freqSystemBus; 33324995d82SHaiying Wang #endif 33424995d82SHaiying Wang 33524995d82SHaiying Wang #endif /* CONFIG_FSL_CORENET */ 33624995d82SHaiying Wang 337beba93edSDipen Dudhat #if defined(CONFIG_FSL_LBC) 3389a653a98SYork Sun uint lcrr_div; 339a47a12beSStefan Roese #if defined(CONFIG_SYS_LBC_LCRR) 340a47a12beSStefan Roese /* We will program LCRR to this value later */ 341a47a12beSStefan Roese lcrr_div = CONFIG_SYS_LBC_LCRR & LCRR_CLKDIV; 342a47a12beSStefan Roese #else 343f51cdaf1SBecky Bruce lcrr_div = in_be32(&(LBC_BASE_ADDR)->lcrr) & LCRR_CLKDIV; 344a47a12beSStefan Roese #endif 345a47a12beSStefan Roese if (lcrr_div == 2 || lcrr_div == 4 || lcrr_div == 8) { 346a47a12beSStefan Roese #if defined(CONFIG_FSL_CORENET) 347a47a12beSStefan Roese /* If this is corenet based SoC, bit-representation 348a47a12beSStefan Roese * for four times the clock divider values. 349a47a12beSStefan Roese */ 350a47a12beSStefan Roese lcrr_div *= 4; 351a47a12beSStefan Roese #elif !defined(CONFIG_MPC8540) && !defined(CONFIG_MPC8541) && \ 352a47a12beSStefan Roese !defined(CONFIG_MPC8555) && !defined(CONFIG_MPC8560) 353a47a12beSStefan Roese /* 354a47a12beSStefan Roese * Yes, the entire PQ38 family use the same 355a47a12beSStefan Roese * bit-representation for twice the clock divider values. 356a47a12beSStefan Roese */ 357a47a12beSStefan Roese lcrr_div *= 2; 358a47a12beSStefan Roese #endif 359a47a12beSStefan Roese sysInfo->freqLocalBus = sysInfo->freqSystemBus / lcrr_div; 360a47a12beSStefan Roese } else { 361a47a12beSStefan Roese /* In case anyone cares what the unknown value is */ 362a47a12beSStefan Roese sysInfo->freqLocalBus = lcrr_div; 363a47a12beSStefan Roese } 364beba93edSDipen Dudhat #endif 365800c73c4SKumar Gala 366800c73c4SKumar Gala #if defined(CONFIG_FSL_IFC) 367800c73c4SKumar Gala ccr = in_be32(&ifc_regs->ifc_ccr); 368800c73c4SKumar Gala ccr = ((ccr & IFC_CCR_CLK_DIV_MASK) >> IFC_CCR_CLK_DIV_SHIFT) + 1; 369800c73c4SKumar Gala 370800c73c4SKumar Gala sysInfo->freqLocalBus = sysInfo->freqSystemBus / ccr; 371800c73c4SKumar Gala #endif 372a47a12beSStefan Roese } 373a47a12beSStefan Roese 374a47a12beSStefan Roese 375a47a12beSStefan Roese int get_clocks (void) 376a47a12beSStefan Roese { 377a47a12beSStefan Roese sys_info_t sys_info; 378a47a12beSStefan Roese #ifdef CONFIG_MPC8544 379a47a12beSStefan Roese volatile ccsr_gur_t *gur = (void *) CONFIG_SYS_MPC85xx_GUTS_ADDR; 380a47a12beSStefan Roese #endif 381a47a12beSStefan Roese #if defined(CONFIG_CPM2) 382a47a12beSStefan Roese volatile ccsr_cpm_t *cpm = (ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR; 383a47a12beSStefan Roese uint sccr, dfbrg; 384a47a12beSStefan Roese 385a47a12beSStefan Roese /* set VCO = 4 * BRG */ 386a47a12beSStefan Roese cpm->im_cpm_intctl.sccr &= 0xfffffffc; 387a47a12beSStefan Roese sccr = cpm->im_cpm_intctl.sccr; 388a47a12beSStefan Roese dfbrg = (sccr & SCCR_DFBRG_MSK) >> SCCR_DFBRG_SHIFT; 389a47a12beSStefan Roese #endif 390a47a12beSStefan Roese get_sys_info (&sys_info); 391a47a12beSStefan Roese gd->cpu_clk = sys_info.freqProcessor[0]; 392a47a12beSStefan Roese gd->bus_clk = sys_info.freqSystemBus; 393a47a12beSStefan Roese gd->mem_clk = sys_info.freqDDRBus; 39467ac13b1SSimon Glass gd->arch.lbc_clk = sys_info.freqLocalBus; 395a47a12beSStefan Roese 396a47a12beSStefan Roese #ifdef CONFIG_QE 39745bae2e3SSimon Glass gd->arch.qe_clk = sys_info.freqQE; 39845bae2e3SSimon Glass gd->arch.brg_clk = gd->arch.qe_clk / 2; 399a47a12beSStefan Roese #endif 400a47a12beSStefan Roese /* 401a47a12beSStefan Roese * The base clock for I2C depends on the actual SOC. Unfortunately, 402a47a12beSStefan Roese * there is no pattern that can be used to determine the frequency, so 403a47a12beSStefan Roese * the only choice is to look up the actual SOC number and use the value 404a47a12beSStefan Roese * for that SOC. This information is taken from application note 405a47a12beSStefan Roese * AN2919. 406a47a12beSStefan Roese */ 407a47a12beSStefan Roese #if defined(CONFIG_MPC8540) || defined(CONFIG_MPC8541) || \ 408a47a12beSStefan Roese defined(CONFIG_MPC8560) || defined(CONFIG_MPC8555) 409609e6ec3SSimon Glass gd->arch.i2c1_clk = sys_info.freqSystemBus; 410a47a12beSStefan Roese #elif defined(CONFIG_MPC8544) 411a47a12beSStefan Roese /* 412a47a12beSStefan Roese * On the 8544, the I2C clock is the same as the SEC clock. This can be 413a47a12beSStefan Roese * either CCB/2 or CCB/3, depending on the value of cfg_sec_freq. See 414a47a12beSStefan Roese * 4.4.3.3 of the 8544 RM. Note that this might actually work for all 415a47a12beSStefan Roese * 85xx, but only the 8544 has cfg_sec_freq, so it's unknown if the 416a47a12beSStefan Roese * PORDEVSR2_SEC_CFG bit is 0 on all 85xx boards that are not an 8544. 417a47a12beSStefan Roese */ 418a47a12beSStefan Roese if (gur->pordevsr2 & MPC85xx_PORDEVSR2_SEC_CFG) 419609e6ec3SSimon Glass gd->arch.i2c1_clk = sys_info.freqSystemBus / 3; 420a47a12beSStefan Roese else 421609e6ec3SSimon Glass gd->arch.i2c1_clk = sys_info.freqSystemBus / 2; 422a47a12beSStefan Roese #else 423a47a12beSStefan Roese /* Most 85xx SOCs use CCB/2, so this is the default behavior. */ 424609e6ec3SSimon Glass gd->arch.i2c1_clk = sys_info.freqSystemBus / 2; 425a47a12beSStefan Roese #endif 426609e6ec3SSimon Glass gd->arch.i2c2_clk = gd->arch.i2c1_clk; 427a47a12beSStefan Roese 428a47a12beSStefan Roese #if defined(CONFIG_FSL_ESDHC) 4297d640e9bSPriyanka Jain #if defined(CONFIG_MPC8569) || defined(CONFIG_P1010) ||\ 4307d640e9bSPriyanka Jain defined(CONFIG_P1014) 431*e9adeca3SSimon Glass gd->arch.sdhc_clk = gd->bus_clk; 432a47a12beSStefan Roese #else 433*e9adeca3SSimon Glass gd->arch.sdhc_clk = gd->bus_clk / 2; 434a47a12beSStefan Roese #endif 435a47a12beSStefan Roese #endif /* defined(CONFIG_FSL_ESDHC) */ 436a47a12beSStefan Roese 437a47a12beSStefan Roese #if defined(CONFIG_CPM2) 438748cd059SSimon Glass gd->arch.vco_out = 2*sys_info.freqSystemBus; 439748cd059SSimon Glass gd->arch.cpm_clk = gd->arch.vco_out / 2; 440748cd059SSimon Glass gd->arch.scc_clk = gd->arch.vco_out / 4; 441748cd059SSimon Glass gd->arch.brg_clk = gd->arch.vco_out / (1 << (2 * (dfbrg + 1))); 442a47a12beSStefan Roese #endif 443a47a12beSStefan Roese 444a47a12beSStefan Roese if(gd->cpu_clk != 0) return (0); 445a47a12beSStefan Roese else return (1); 446a47a12beSStefan Roese } 447a47a12beSStefan Roese 448a47a12beSStefan Roese 449a47a12beSStefan Roese /******************************************** 450a47a12beSStefan Roese * get_bus_freq 451a47a12beSStefan Roese * return system bus freq in Hz 452a47a12beSStefan Roese *********************************************/ 453a47a12beSStefan Roese ulong get_bus_freq (ulong dummy) 454a47a12beSStefan Roese { 455a47a12beSStefan Roese return gd->bus_clk; 456a47a12beSStefan Roese } 457a47a12beSStefan Roese 458a47a12beSStefan Roese /******************************************** 459a47a12beSStefan Roese * get_ddr_freq 460a47a12beSStefan Roese * return ddr bus freq in Hz 461a47a12beSStefan Roese *********************************************/ 462a47a12beSStefan Roese ulong get_ddr_freq (ulong dummy) 463a47a12beSStefan Roese { 464a47a12beSStefan Roese return gd->mem_clk; 465a47a12beSStefan Roese } 466