blob: 7e698730f3d1bfd0b48631b01fa35421e020a575 [file] [log] [blame]
wdenk42d1f032003-10-15 23:53:47 +00001/*
Dipen Dudhatbeba93e2011-01-19 12:46:27 +05302 * Copyright 2004, 2007-2011 Freescale Semiconductor, Inc.
Kumar Gala39aaca12009-03-19 02:46:19 -05003 *
wdenk42d1f032003-10-15 23:53:47 +00004 * (C) Copyright 2003 Motorola Inc.
5 * Xianghua Xiao, (X.Xiao@motorola.com)
6 *
7 * (C) Copyright 2000
8 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
9 *
Wolfgang Denk1a459662013-07-08 09:37:19 +020010 * SPDX-License-Identifier: GPL-2.0+
wdenk42d1f032003-10-15 23:53:47 +000011 */
12
13#include <common.h>
14#include <ppc_asm.tmpl>
Haiying Wanga52d2f82011-02-11 01:25:30 -060015#include <linux/compiler.h>
wdenk42d1f032003-10-15 23:53:47 +000016#include <asm/processor.h>
Trent Piephoada591d2008-12-03 15:16:37 -080017#include <asm/io.h>
wdenk42d1f032003-10-15 23:53:47 +000018
Wolfgang Denkd87080b2006-03-31 18:32:53 +020019DECLARE_GLOBAL_DATA_PTR;
20
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +053021
22#ifndef CONFIG_SYS_FSL_NUM_CC_PLLS
23#define CONFIG_SYS_FSL_NUM_CC_PLLS 6
24#endif
wdenk42d1f032003-10-15 23:53:47 +000025/* --------------------------------------------------------------- */
26
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +053027void get_sys_info(sys_info_t *sys_info)
wdenk42d1f032003-10-15 23:53:47 +000028{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020029 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Kumar Gala800c73c2012-10-08 07:44:06 +000030#ifdef CONFIG_FSL_IFC
31 struct fsl_ifc *ifc_regs = (void *)CONFIG_SYS_IFC_ADDR;
32 u32 ccr;
33#endif
Kumar Gala39aaca12009-03-19 02:46:19 -050034#ifdef CONFIG_FSL_CORENET
35 volatile ccsr_clk_t *clk = (void *)(CONFIG_SYS_FSL_CORENET_CLK_ADDR);
Timur Tabifbb9ecf2011-08-05 16:15:24 -050036 unsigned int cpu;
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +053037#ifdef CONFIG_SYS_FSL_QORIQ_CHASSIS2
38 int cc_group[12] = CONFIG_SYS_FSL_CLUSTER_CLOCKS;
39#endif
York Sun14109c72014-10-27 11:31:33 -070040 __maybe_unused u32 svr;
Kumar Gala39aaca12009-03-19 02:46:19 -050041
42 const u8 core_cplx_PLL[16] = {
43 [ 0] = 0, /* CC1 PPL / 1 */
44 [ 1] = 0, /* CC1 PPL / 2 */
45 [ 2] = 0, /* CC1 PPL / 4 */
46 [ 4] = 1, /* CC2 PPL / 1 */
47 [ 5] = 1, /* CC2 PPL / 2 */
48 [ 6] = 1, /* CC2 PPL / 4 */
49 [ 8] = 2, /* CC3 PPL / 1 */
50 [ 9] = 2, /* CC3 PPL / 2 */
51 [10] = 2, /* CC3 PPL / 4 */
52 [12] = 3, /* CC4 PPL / 1 */
53 [13] = 3, /* CC4 PPL / 2 */
54 [14] = 3, /* CC4 PPL / 4 */
55 };
56
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +053057 const u8 core_cplx_pll_div[16] = {
Kumar Gala39aaca12009-03-19 02:46:19 -050058 [ 0] = 1, /* CC1 PPL / 1 */
59 [ 1] = 2, /* CC1 PPL / 2 */
60 [ 2] = 4, /* CC1 PPL / 4 */
61 [ 4] = 1, /* CC2 PPL / 1 */
62 [ 5] = 2, /* CC2 PPL / 2 */
63 [ 6] = 4, /* CC2 PPL / 4 */
64 [ 8] = 1, /* CC3 PPL / 1 */
65 [ 9] = 2, /* CC3 PPL / 2 */
66 [10] = 4, /* CC3 PPL / 4 */
67 [12] = 1, /* CC4 PPL / 1 */
68 [13] = 2, /* CC4 PPL / 2 */
69 [14] = 4, /* CC4 PPL / 4 */
70 };
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +053071 uint i, freq_c_pll[CONFIG_SYS_FSL_NUM_CC_PLLS];
72#if !defined(CONFIG_FM_PLAT_CLK_DIV) || !defined(CONFIG_PME_PLAT_CLK_DIV)
73 uint rcw_tmp;
74#endif
75 uint ratio[CONFIG_SYS_FSL_NUM_CC_PLLS];
Kumar Gala39aaca12009-03-19 02:46:19 -050076 unsigned long sysclk = CONFIG_SYS_CLK_FREQ;
Srikanth Srinivasanab48ca12010-02-10 17:32:43 +080077 uint mem_pll_rat;
Kumar Gala39aaca12009-03-19 02:46:19 -050078
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +053079 sys_info->freq_systembus = sysclk;
Priyanka Jainb1359912013-12-17 14:25:52 +053080#ifdef CONFIG_SYS_FSL_SINGLE_SOURCE_CLK
vijay rai0c12a152014-04-15 11:34:12 +053081 uint ddr_refclk_sel;
82 unsigned int porsr1_sys_clk;
83 porsr1_sys_clk = in_be32(&gur->porsr1) >> FSL_DCFG_PORSR1_SYSCLK_SHIFT
84 & FSL_DCFG_PORSR1_SYSCLK_MASK;
85 if (porsr1_sys_clk == FSL_DCFG_PORSR1_SYSCLK_DIFF)
86 sys_info->diff_sysclk = 1;
87 else
88 sys_info->diff_sysclk = 0;
89
Priyanka Jainb1359912013-12-17 14:25:52 +053090 /*
91 * DDR_REFCLK_SEL rcw bit is used to determine if DDR PLLS
92 * are driven by separate DDR Refclock or single source
93 * differential clock.
94 */
vijay rai0c12a152014-04-15 11:34:12 +053095 ddr_refclk_sel = (in_be32(&gur->rcwsr[5]) >>
Priyanka Jainb1359912013-12-17 14:25:52 +053096 FSL_CORENET2_RCWSR5_DDR_REFCLK_SEL_SHIFT) &
97 FSL_CORENET2_RCWSR5_DDR_REFCLK_SEL_MASK;
98 /*
vijay rai0c12a152014-04-15 11:34:12 +053099 * For single source clocking, both ddrclock and sysclock
Priyanka Jainb1359912013-12-17 14:25:52 +0530100 * are driven by differential sysclock.
101 */
vijay rai0c12a152014-04-15 11:34:12 +0530102 if (ddr_refclk_sel == FSL_CORENET2_RCWSR5_DDR_REFCLK_SINGLE_CLK)
Priyanka Jainb1359912013-12-17 14:25:52 +0530103 sys_info->freq_ddrbus = CONFIG_SYS_CLK_FREQ;
vijay rai0c12a152014-04-15 11:34:12 +0530104 else
Priyanka Jainb1359912013-12-17 14:25:52 +0530105#endif
York Sun98ffa192012-10-08 07:44:31 +0000106#ifdef CONFIG_DDR_CLK_FREQ
Priyanka Jainb1359912013-12-17 14:25:52 +0530107 sys_info->freq_ddrbus = CONFIG_DDR_CLK_FREQ;
York Sun98ffa192012-10-08 07:44:31 +0000108#else
Priyanka Jainb1359912013-12-17 14:25:52 +0530109 sys_info->freq_ddrbus = sysclk;
York Sun98ffa192012-10-08 07:44:31 +0000110#endif
Kumar Gala39aaca12009-03-19 02:46:19 -0500111
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530112 sys_info->freq_systembus *= (in_be32(&gur->rcwsr[0]) >> 25) & 0x1f;
York Sunf77329c2012-10-08 07:44:09 +0000113 mem_pll_rat = (in_be32(&gur->rcwsr[0]) >>
114 FSL_CORENET_RCWSR0_MEM_PLL_RAT_SHIFT)
115 & FSL_CORENET_RCWSR0_MEM_PLL_RAT_MASK;
York Sunc3678b02014-03-28 15:07:27 -0700116#ifdef CONFIG_SYS_FSL_ERRATUM_A007212
117 if (mem_pll_rat == 0) {
118 mem_pll_rat = (in_be32(&gur->rcwsr[0]) >>
119 FSL_CORENET_RCWSR0_MEM_PLL_RAT_RESV_SHIFT) &
120 FSL_CORENET_RCWSR0_MEM_PLL_RAT_MASK;
121 }
122#endif
Zang Roy-R61911e88f4212013-11-28 13:23:37 +0800123 /* T4240/T4160 Rev2.0 MEM_PLL_RAT uses a value which is half of
124 * T4240/T4160 Rev1.0. eg. It's 12 in Rev1.0, however, for Rev2.0
125 * it uses 6.
York Sun14109c72014-10-27 11:31:33 -0700126 * T2080 rev 1.1 and later also use half mem_pll comparing with rev 1.0
Zang Roy-R61911e88f4212013-11-28 13:23:37 +0800127 */
Shengzhou Liu5122dfa2014-04-25 16:31:22 +0800128#if defined(CONFIG_PPC_T4240) || defined(CONFIG_PPC_T4160) || \
York Sun14109c72014-10-27 11:31:33 -0700129 defined(CONFIG_PPC_T4080) || defined(CONFIG_PPC_T2080)
130 svr = get_svr();
131 switch (SVR_SOC_VER(svr)) {
132 case SVR_T4240:
133 case SVR_T4160:
134 case SVR_T4120:
135 case SVR_T4080:
136 if (SVR_MAJ(svr) >= 2)
137 mem_pll_rat *= 2;
138 break;
139 case SVR_T2080:
140 case SVR_T2081:
141 if ((SVR_MAJ(svr) > 1) || (SVR_MIN(svr) >= 1))
142 mem_pll_rat *= 2;
143 break;
144 default:
145 break;
146 }
Zang Roy-R61911e88f4212013-11-28 13:23:37 +0800147#endif
Srikanth Srinivasanab48ca12010-02-10 17:32:43 +0800148 if (mem_pll_rat > 2)
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530149 sys_info->freq_ddrbus *= mem_pll_rat;
Srikanth Srinivasanab48ca12010-02-10 17:32:43 +0800150 else
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530151 sys_info->freq_ddrbus = sys_info->freq_systembus * mem_pll_rat;
Kumar Gala39aaca12009-03-19 02:46:19 -0500152
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530153 for (i = 0; i < CONFIG_SYS_FSL_NUM_CC_PLLS; i++) {
154 ratio[i] = (in_be32(&clk->pllcgsr[i].pllcngsr) >> 1) & 0x3f;
Srikanth Srinivasanab48ca12010-02-10 17:32:43 +0800155 if (ratio[i] > 4)
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530156 freq_c_pll[i] = sysclk * ratio[i];
Srikanth Srinivasanab48ca12010-02-10 17:32:43 +0800157 else
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530158 freq_c_pll[i] = sys_info->freq_systembus * ratio[i];
Srikanth Srinivasanab48ca12010-02-10 17:32:43 +0800159 }
York Sun9a653a92012-10-08 07:44:11 +0000160#ifdef CONFIG_SYS_FSL_QORIQ_CHASSIS2
161 /*
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530162 * As per CHASSIS2 architeture total 12 clusters are posible and
York Sun9a653a92012-10-08 07:44:11 +0000163 * Each cluster has up to 4 cores, sharing the same PLL selection.
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530164 * The cluster clock assignment is SoC defined.
165 *
166 * Total 4 clock groups are possible with 3 PLLs each.
167 * as per array indices, clock group A has 0, 1, 2 numbered PLLs &
168 * clock group B has 3, 4, 6 and so on.
169 *
170 * Clock group A having PLL1, PLL2, PLL3, feeding cores of any cluster
171 * depends upon the SoC architeture. Same applies to other
172 * clock groups and clusters.
173 *
York Sun9a653a92012-10-08 07:44:11 +0000174 */
175 for_each_cpu(i, cpu, cpu_numcores(), cpu_mask()) {
York Sunf6981432013-03-25 07:40:07 +0000176 int cluster = fsl_qoriq_core_to_cluster(cpu);
177 u32 c_pll_sel = (in_be32(&clk->clkcsr[cluster].clkcncsr) >> 27)
York Sun9a653a92012-10-08 07:44:11 +0000178 & 0xf;
179 u32 cplx_pll = core_cplx_PLL[c_pll_sel];
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530180 cplx_pll += cc_group[cluster] - 1;
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530181 sys_info->freq_processor[cpu] =
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530182 freq_c_pll[cplx_pll] / core_cplx_pll_div[c_pll_sel];
York Sun9a653a92012-10-08 07:44:11 +0000183 }
Prabhakar Kushwahab33bd8c2014-04-21 10:47:41 +0530184#if defined(CONFIG_PPC_B4860) || defined(CONFIG_PPC_B4420) || \
185 defined(CONFIG_PPC_T2080) || defined(CONFIG_PPC_T2081)
Sandeep Singh0cb33252013-03-25 07:33:09 +0000186#define FM1_CLK_SEL 0xe0000000
187#define FM1_CLK_SHIFT 29
Shengzhou Liuf6050792014-11-24 17:11:54 +0800188#elif defined(CONFIG_PPC_T1024) || defined(CONFIG_PPC_T1023)
189#define FM1_CLK_SEL 0x00000007
190#define FM1_CLK_SHIFT 0
Sandeep Singh0cb33252013-03-25 07:33:09 +0000191#else
York Sun9a653a92012-10-08 07:44:11 +0000192#define PME_CLK_SEL 0xe0000000
193#define PME_CLK_SHIFT 29
194#define FM1_CLK_SEL 0x1c000000
195#define FM1_CLK_SHIFT 26
Sandeep Singh0cb33252013-03-25 07:33:09 +0000196#endif
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530197#if !defined(CONFIG_FM_PLAT_CLK_DIV) || !defined(CONFIG_PME_PLAT_CLK_DIV)
Shengzhou Liuf6050792014-11-24 17:11:54 +0800198#if defined(CONFIG_PPC_T1024) || defined(CONFIG_PPC_T1023)
199 rcw_tmp = in_be32(&gur->rcwsr[15]) - 4;
200#else
York Sun9a653a92012-10-08 07:44:11 +0000201 rcw_tmp = in_be32(&gur->rcwsr[7]);
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530202#endif
Shengzhou Liuf6050792014-11-24 17:11:54 +0800203#endif
York Sun9a653a92012-10-08 07:44:11 +0000204
205#ifdef CONFIG_SYS_DPAA_PME
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530206#ifndef CONFIG_PME_PLAT_CLK_DIV
York Sun9a653a92012-10-08 07:44:11 +0000207 switch ((rcw_tmp & PME_CLK_SEL) >> PME_CLK_SHIFT) {
208 case 1:
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530209 sys_info->freq_pme = freq_c_pll[CONFIG_SYS_PME_CLK];
York Sun9a653a92012-10-08 07:44:11 +0000210 break;
211 case 2:
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530212 sys_info->freq_pme = freq_c_pll[CONFIG_SYS_PME_CLK] / 2;
York Sun9a653a92012-10-08 07:44:11 +0000213 break;
214 case 3:
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530215 sys_info->freq_pme = freq_c_pll[CONFIG_SYS_PME_CLK] / 3;
York Sun9a653a92012-10-08 07:44:11 +0000216 break;
217 case 4:
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530218 sys_info->freq_pme = freq_c_pll[CONFIG_SYS_PME_CLK] / 4;
York Sun9a653a92012-10-08 07:44:11 +0000219 break;
220 case 6:
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530221 sys_info->freq_pme = freq_c_pll[CONFIG_SYS_PME_CLK + 1] / 2;
York Sun9a653a92012-10-08 07:44:11 +0000222 break;
223 case 7:
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530224 sys_info->freq_pme = freq_c_pll[CONFIG_SYS_PME_CLK + 1] / 3;
York Sun9a653a92012-10-08 07:44:11 +0000225 break;
226 default:
227 printf("Error: Unknown PME clock select!\n");
228 case 0:
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530229 sys_info->freq_pme = sys_info->freq_systembus / 2;
York Sun9a653a92012-10-08 07:44:11 +0000230 break;
231
232 }
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530233#else
234 sys_info->freq_pme = sys_info->freq_systembus / CONFIG_SYS_PME_CLK;
235
236#endif
York Sun9a653a92012-10-08 07:44:11 +0000237#endif
238
Haiying Wang990e1a82012-10-11 07:13:39 +0000239#ifdef CONFIG_SYS_DPAA_QBMAN
Shengzhou Liuf6050792014-11-24 17:11:54 +0800240#ifndef CONFIG_QBMAN_CLK_DIV
241#define CONFIG_QBMAN_CLK_DIV 2
242#endif
243 sys_info->freq_qman = sys_info->freq_systembus / CONFIG_QBMAN_CLK_DIV;
Haiying Wang990e1a82012-10-11 07:13:39 +0000244#endif
245
York Sun9a653a92012-10-08 07:44:11 +0000246#ifdef CONFIG_SYS_DPAA_FMAN
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530247#ifndef CONFIG_FM_PLAT_CLK_DIV
York Sun9a653a92012-10-08 07:44:11 +0000248 switch ((rcw_tmp & FM1_CLK_SEL) >> FM1_CLK_SHIFT) {
249 case 1:
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530250 sys_info->freq_fman[0] = freq_c_pll[CONFIG_SYS_FM1_CLK];
York Sun9a653a92012-10-08 07:44:11 +0000251 break;
252 case 2:
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530253 sys_info->freq_fman[0] = freq_c_pll[CONFIG_SYS_FM1_CLK] / 2;
York Sun9a653a92012-10-08 07:44:11 +0000254 break;
255 case 3:
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530256 sys_info->freq_fman[0] = freq_c_pll[CONFIG_SYS_FM1_CLK] / 3;
York Sun9a653a92012-10-08 07:44:11 +0000257 break;
258 case 4:
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530259 sys_info->freq_fman[0] = freq_c_pll[CONFIG_SYS_FM1_CLK] / 4;
York Sun9a653a92012-10-08 07:44:11 +0000260 break;
Sandeep Singh0cb33252013-03-25 07:33:09 +0000261 case 5:
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530262 sys_info->freq_fman[0] = sys_info->freq_systembus;
Sandeep Singh0cb33252013-03-25 07:33:09 +0000263 break;
York Sun9a653a92012-10-08 07:44:11 +0000264 case 6:
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530265 sys_info->freq_fman[0] = freq_c_pll[CONFIG_SYS_FM1_CLK + 1] / 2;
York Sun9a653a92012-10-08 07:44:11 +0000266 break;
267 case 7:
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530268 sys_info->freq_fman[0] = freq_c_pll[CONFIG_SYS_FM1_CLK + 1] / 3;
York Sun9a653a92012-10-08 07:44:11 +0000269 break;
270 default:
271 printf("Error: Unknown FMan1 clock select!\n");
272 case 0:
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530273 sys_info->freq_fman[0] = sys_info->freq_systembus / 2;
York Sun9a653a92012-10-08 07:44:11 +0000274 break;
275 }
276#if (CONFIG_SYS_NUM_FMAN) == 2
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530277#ifdef CONFIG_SYS_FM2_CLK
York Sun9a653a92012-10-08 07:44:11 +0000278#define FM2_CLK_SEL 0x00000038
279#define FM2_CLK_SHIFT 3
280 rcw_tmp = in_be32(&gur->rcwsr[15]);
281 switch ((rcw_tmp & FM2_CLK_SEL) >> FM2_CLK_SHIFT) {
282 case 1:
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530283 sys_info->freq_fman[1] = freq_c_pll[CONFIG_SYS_FM2_CLK + 1];
York Sun9a653a92012-10-08 07:44:11 +0000284 break;
285 case 2:
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530286 sys_info->freq_fman[1] = freq_c_pll[CONFIG_SYS_FM2_CLK + 1] / 2;
York Sun9a653a92012-10-08 07:44:11 +0000287 break;
288 case 3:
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530289 sys_info->freq_fman[1] = freq_c_pll[CONFIG_SYS_FM2_CLK + 1] / 3;
York Sun9a653a92012-10-08 07:44:11 +0000290 break;
291 case 4:
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530292 sys_info->freq_fman[1] = freq_c_pll[CONFIG_SYS_FM2_CLK + 1] / 4;
York Sun9a653a92012-10-08 07:44:11 +0000293 break;
Shaohui Xiec1015c62013-11-28 13:52:51 +0800294 case 5:
295 sys_info->freq_fman[1] = sys_info->freq_systembus;
296 break;
York Sun9a653a92012-10-08 07:44:11 +0000297 case 6:
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530298 sys_info->freq_fman[1] = freq_c_pll[CONFIG_SYS_FM2_CLK] / 2;
York Sun9a653a92012-10-08 07:44:11 +0000299 break;
300 case 7:
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530301 sys_info->freq_fman[1] = freq_c_pll[CONFIG_SYS_FM2_CLK] / 3;
York Sun9a653a92012-10-08 07:44:11 +0000302 break;
303 default:
304 printf("Error: Unknown FMan2 clock select!\n");
305 case 0:
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530306 sys_info->freq_fman[1] = sys_info->freq_systembus / 2;
York Sun9a653a92012-10-08 07:44:11 +0000307 break;
308 }
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530309#endif
York Sun9a653a92012-10-08 07:44:11 +0000310#endif /* CONFIG_SYS_NUM_FMAN == 2 */
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530311#else
312 sys_info->freq_fman[0] = sys_info->freq_systembus / CONFIG_SYS_FM1_CLK;
313#endif
314#endif
York Sun9a653a92012-10-08 07:44:11 +0000315
316#else /* CONFIG_SYS_FSL_QORIQ_CHASSIS2 */
317
Timur Tabifbb9ecf2011-08-05 16:15:24 -0500318 for_each_cpu(i, cpu, cpu_numcores(), cpu_mask()) {
York Sunf6981432013-03-25 07:40:07 +0000319 u32 c_pll_sel = (in_be32(&clk->clkcsr[cpu].clkcncsr) >> 27)
320 & 0xf;
Kumar Gala39aaca12009-03-19 02:46:19 -0500321 u32 cplx_pll = core_cplx_PLL[c_pll_sel];
322
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530323 sys_info->freq_processor[cpu] =
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530324 freq_c_pll[cplx_pll] / core_cplx_pll_div[c_pll_sel];
Kumar Gala39aaca12009-03-19 02:46:19 -0500325 }
Kumar Gala39aaca12009-03-19 02:46:19 -0500326#define PME_CLK_SEL 0x80000000
327#define FM1_CLK_SEL 0x40000000
328#define FM2_CLK_SEL 0x20000000
Kumar Galab5c87532011-02-16 02:03:29 -0600329#define HWA_ASYNC_DIV 0x04000000
330#if (CONFIG_SYS_FSL_NUM_CC_PLLS == 2)
331#define HWA_CC_PLL 1
Timur Tabi49054432012-10-05 11:09:19 +0000332#elif (CONFIG_SYS_FSL_NUM_CC_PLLS == 3)
333#define HWA_CC_PLL 2
Kumar Galab5c87532011-02-16 02:03:29 -0600334#elif (CONFIG_SYS_FSL_NUM_CC_PLLS == 4)
Wolfgang Denkcd6881b2011-05-19 22:21:41 +0200335#define HWA_CC_PLL 2
Kumar Galab5c87532011-02-16 02:03:29 -0600336#else
337#error CONFIG_SYS_FSL_NUM_CC_PLLS not set or unknown case
338#endif
Kumar Gala39aaca12009-03-19 02:46:19 -0500339 rcw_tmp = in_be32(&gur->rcwsr[7]);
340
341#ifdef CONFIG_SYS_DPAA_PME
Kumar Galab5c87532011-02-16 02:03:29 -0600342 if (rcw_tmp & PME_CLK_SEL) {
343 if (rcw_tmp & HWA_ASYNC_DIV)
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530344 sys_info->freq_pme = freq_c_pll[HWA_CC_PLL] / 4;
Kumar Galab5c87532011-02-16 02:03:29 -0600345 else
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530346 sys_info->freq_pme = freq_c_pll[HWA_CC_PLL] / 2;
Kumar Galab5c87532011-02-16 02:03:29 -0600347 } else {
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530348 sys_info->freq_pme = sys_info->freq_systembus / 2;
Kumar Galab5c87532011-02-16 02:03:29 -0600349 }
Kumar Gala39aaca12009-03-19 02:46:19 -0500350#endif
351
352#ifdef CONFIG_SYS_DPAA_FMAN
Kumar Galab5c87532011-02-16 02:03:29 -0600353 if (rcw_tmp & FM1_CLK_SEL) {
354 if (rcw_tmp & HWA_ASYNC_DIV)
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530355 sys_info->freq_fman[0] = freq_c_pll[HWA_CC_PLL] / 4;
Kumar Galab5c87532011-02-16 02:03:29 -0600356 else
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530357 sys_info->freq_fman[0] = freq_c_pll[HWA_CC_PLL] / 2;
Kumar Galab5c87532011-02-16 02:03:29 -0600358 } else {
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530359 sys_info->freq_fman[0] = sys_info->freq_systembus / 2;
Kumar Galab5c87532011-02-16 02:03:29 -0600360 }
Kumar Gala39aaca12009-03-19 02:46:19 -0500361#if (CONFIG_SYS_NUM_FMAN) == 2
Kumar Galab5c87532011-02-16 02:03:29 -0600362 if (rcw_tmp & FM2_CLK_SEL) {
363 if (rcw_tmp & HWA_ASYNC_DIV)
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530364 sys_info->freq_fman[1] = freq_c_pll[HWA_CC_PLL] / 4;
Kumar Galab5c87532011-02-16 02:03:29 -0600365 else
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530366 sys_info->freq_fman[1] = freq_c_pll[HWA_CC_PLL] / 2;
Kumar Galab5c87532011-02-16 02:03:29 -0600367 } else {
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530368 sys_info->freq_fman[1] = sys_info->freq_systembus / 2;
Kumar Galab5c87532011-02-16 02:03:29 -0600369 }
Kumar Gala39aaca12009-03-19 02:46:19 -0500370#endif
371#endif
372
Shaohui Xie3e83fc92013-03-25 07:33:25 +0000373#ifdef CONFIG_SYS_DPAA_QBMAN
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530374 sys_info->freq_qman = sys_info->freq_systembus / 2;
Shaohui Xie3e83fc92013-03-25 07:33:25 +0000375#endif
376
York Sun9a653a92012-10-08 07:44:11 +0000377#endif /* CONFIG_SYS_FSL_QORIQ_CHASSIS2 */
378
Zhao Qiang2a44efe2014-03-21 16:21:45 +0800379#ifdef CONFIG_U_QE
380 sys_info->freq_qe = sys_info->freq_systembus / 2;
381#endif
382
York Sun9a653a92012-10-08 07:44:11 +0000383#else /* CONFIG_FSL_CORENET */
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530384 uint plat_ratio, e500_ratio, half_freq_systembus;
Haiying Wang2fc7eb02009-01-15 11:58:35 -0500385 int i;
Haiying Wangb3d7f202009-05-20 12:30:29 -0400386#ifdef CONFIG_QE
Haiying Wanga52d2f82011-02-11 01:25:30 -0600387 __maybe_unused u32 qe_ratio;
Haiying Wangb3d7f202009-05-20 12:30:29 -0400388#endif
wdenk42d1f032003-10-15 23:53:47 +0000389
390 plat_ratio = (gur->porpllsr) & 0x0000003e;
391 plat_ratio >>= 1;
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530392 sys_info->freq_systembus = plat_ratio * CONFIG_SYS_CLK_FREQ;
Andy Fleming66ed6cc2007-04-23 02:37:47 -0500393
394 /* Divide before multiply to avoid integer
395 * overflow for processor speeds above 2GHz */
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530396 half_freq_systembus = sys_info->freq_systembus/2;
Poonam Aggrwal0e870982009-07-31 12:08:14 +0530397 for (i = 0; i < cpu_numcores(); i++) {
Haiying Wang2fc7eb02009-01-15 11:58:35 -0500398 e500_ratio = ((gur->porpllsr) >> (i * 8 + 16)) & 0x3f;
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530399 sys_info->freq_processor[i] = e500_ratio * half_freq_systembus;
Haiying Wang2fc7eb02009-01-15 11:58:35 -0500400 }
James Yanga3e77fa2008-02-08 18:05:08 -0600401
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530402 /* Note: freq_ddrbus is the MCLK frequency, not the data rate. */
403 sys_info->freq_ddrbus = sys_info->freq_systembus;
Kumar Galad4357932007-12-07 04:59:26 -0600404
405#ifdef CONFIG_DDR_CLK_FREQ
406 {
Jason Jinc0391112008-09-27 14:40:57 +0800407 u32 ddr_ratio = ((gur->porpllsr) & MPC85xx_PORPLLSR_DDR_RATIO)
408 >> MPC85xx_PORPLLSR_DDR_RATIO_SHIFT;
Kumar Galad4357932007-12-07 04:59:26 -0600409 if (ddr_ratio != 0x7)
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530410 sys_info->freq_ddrbus = ddr_ratio * CONFIG_DDR_CLK_FREQ;
Kumar Galad4357932007-12-07 04:59:26 -0600411 }
412#endif
Trent Piephoada591d2008-12-03 15:16:37 -0800413
Haiying Wangb3d7f202009-05-20 12:30:29 -0400414#ifdef CONFIG_QE
York Sunbe7bebe2012-08-10 11:07:26 +0000415#if defined(CONFIG_P1012) || defined(CONFIG_P1021) || defined(CONFIG_P1025)
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530416 sys_info->freq_qe = sys_info->freq_systembus;
Haiying Wanga52d2f82011-02-11 01:25:30 -0600417#else
Haiying Wangb3d7f202009-05-20 12:30:29 -0400418 qe_ratio = ((gur->porpllsr) & MPC85xx_PORPLLSR_QE_RATIO)
419 >> MPC85xx_PORPLLSR_QE_RATIO_SHIFT;
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530420 sys_info->freq_qe = qe_ratio * CONFIG_SYS_CLK_FREQ;
Haiying Wangb3d7f202009-05-20 12:30:29 -0400421#endif
Haiying Wanga52d2f82011-02-11 01:25:30 -0600422#endif
Haiying Wangb3d7f202009-05-20 12:30:29 -0400423
Haiying Wang24995d82011-01-20 22:26:31 +0000424#ifdef CONFIG_SYS_DPAA_FMAN
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530425 sys_info->freq_fman[0] = sys_info->freq_systembus;
Haiying Wang24995d82011-01-20 22:26:31 +0000426#endif
427
428#endif /* CONFIG_FSL_CORENET */
429
Dipen Dudhatbeba93e2011-01-19 12:46:27 +0530430#if defined(CONFIG_FSL_LBC)
York Sun9a653a92012-10-08 07:44:11 +0000431 uint lcrr_div;
Trent Piephoada591d2008-12-03 15:16:37 -0800432#if defined(CONFIG_SYS_LBC_LCRR)
433 /* We will program LCRR to this value later */
434 lcrr_div = CONFIG_SYS_LBC_LCRR & LCRR_CLKDIV;
435#else
Becky Brucef51cdaf2010-06-17 11:37:20 -0500436 lcrr_div = in_be32(&(LBC_BASE_ADDR)->lcrr) & LCRR_CLKDIV;
Trent Piephoada591d2008-12-03 15:16:37 -0800437#endif
438 if (lcrr_div == 2 || lcrr_div == 4 || lcrr_div == 8) {
Dave Liu0fd2fa62009-11-17 20:49:05 +0800439#if defined(CONFIG_FSL_CORENET)
440 /* If this is corenet based SoC, bit-representation
441 * for four times the clock divider values.
442 */
443 lcrr_div *= 4;
444#elif !defined(CONFIG_MPC8540) && !defined(CONFIG_MPC8541) && \
Trent Piephoada591d2008-12-03 15:16:37 -0800445 !defined(CONFIG_MPC8555) && !defined(CONFIG_MPC8560)
446 /*
447 * Yes, the entire PQ38 family use the same
448 * bit-representation for twice the clock divider values.
449 */
450 lcrr_div *= 2;
451#endif
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530452 sys_info->freq_localbus = sys_info->freq_systembus / lcrr_div;
Trent Piephoada591d2008-12-03 15:16:37 -0800453 } else {
454 /* In case anyone cares what the unknown value is */
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530455 sys_info->freq_localbus = lcrr_div;
Trent Piephoada591d2008-12-03 15:16:37 -0800456 }
Dipen Dudhatbeba93e2011-01-19 12:46:27 +0530457#endif
Kumar Gala800c73c2012-10-08 07:44:06 +0000458
459#if defined(CONFIG_FSL_IFC)
Prabhakar Kushwahaaa5a3d82014-09-23 10:57:12 +0530460 ccr = ifc_in32(&ifc_regs->ifc_ccr);
Kumar Gala800c73c2012-10-08 07:44:06 +0000461 ccr = ((ccr & IFC_CCR_CLK_DIV_MASK) >> IFC_CCR_CLK_DIV_SHIFT) + 1;
462
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530463 sys_info->freq_localbus = sys_info->freq_systembus / ccr;
Kumar Gala800c73c2012-10-08 07:44:06 +0000464#endif
wdenk42d1f032003-10-15 23:53:47 +0000465}
466
Andy Fleming66ed6cc2007-04-23 02:37:47 -0500467
wdenk42d1f032003-10-15 23:53:47 +0000468int get_clocks (void)
469{
wdenk42d1f032003-10-15 23:53:47 +0000470 sys_info_t sys_info;
Timur Tabi88353a92008-04-04 11:15:58 -0500471#ifdef CONFIG_MPC8544
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200472 volatile ccsr_gur_t *gur = (void *) CONFIG_SYS_MPC85xx_GUTS_ADDR;
Timur Tabi88353a92008-04-04 11:15:58 -0500473#endif
Jon Loeliger9c4c5ae2005-07-23 10:37:35 -0500474#if defined(CONFIG_CPM2)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200475 volatile ccsr_cpm_t *cpm = (ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR;
wdenk42d1f032003-10-15 23:53:47 +0000476 uint sccr, dfbrg;
477
478 /* set VCO = 4 * BRG */
Kumar Galaaafeefb2007-11-28 00:36:33 -0600479 cpm->im_cpm_intctl.sccr &= 0xfffffffc;
480 sccr = cpm->im_cpm_intctl.sccr;
wdenk42d1f032003-10-15 23:53:47 +0000481 dfbrg = (sccr & SCCR_DFBRG_MSK) >> SCCR_DFBRG_SHIFT;
482#endif
483 get_sys_info (&sys_info);
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530484 gd->cpu_clk = sys_info.freq_processor[0];
485 gd->bus_clk = sys_info.freq_systembus;
486 gd->mem_clk = sys_info.freq_ddrbus;
487 gd->arch.lbc_clk = sys_info.freq_localbus;
Timur Tabi88353a92008-04-04 11:15:58 -0500488
Haiying Wangb3d7f202009-05-20 12:30:29 -0400489#ifdef CONFIG_QE
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530490 gd->arch.qe_clk = sys_info.freq_qe;
Simon Glass45bae2e2012-12-13 20:48:50 +0000491 gd->arch.brg_clk = gd->arch.qe_clk / 2;
Haiying Wangb3d7f202009-05-20 12:30:29 -0400492#endif
Timur Tabi88353a92008-04-04 11:15:58 -0500493 /*
494 * The base clock for I2C depends on the actual SOC. Unfortunately,
495 * there is no pattern that can be used to determine the frequency, so
496 * the only choice is to look up the actual SOC number and use the value
497 * for that SOC. This information is taken from application note
498 * AN2919.
499 */
500#if defined(CONFIG_MPC8540) || defined(CONFIG_MPC8541) || \
Tang Yuantianf62b1232013-09-06 10:45:40 +0800501 defined(CONFIG_MPC8560) || defined(CONFIG_MPC8555) || \
502 defined(CONFIG_P1022)
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530503 gd->arch.i2c1_clk = sys_info.freq_systembus;
Timur Tabi88353a92008-04-04 11:15:58 -0500504#elif defined(CONFIG_MPC8544)
505 /*
506 * On the 8544, the I2C clock is the same as the SEC clock. This can be
507 * either CCB/2 or CCB/3, depending on the value of cfg_sec_freq. See
508 * 4.4.3.3 of the 8544 RM. Note that this might actually work for all
509 * 85xx, but only the 8544 has cfg_sec_freq, so it's unknown if the
510 * PORDEVSR2_SEC_CFG bit is 0 on all 85xx boards that are not an 8544.
511 */
512 if (gur->pordevsr2 & MPC85xx_PORDEVSR2_SEC_CFG)
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530513 gd->arch.i2c1_clk = sys_info.freq_systembus / 3;
Kumar Gala42653b82008-10-16 21:58:49 -0500514 else
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530515 gd->arch.i2c1_clk = sys_info.freq_systembus / 2;
Timur Tabi88353a92008-04-04 11:15:58 -0500516#else
517 /* Most 85xx SOCs use CCB/2, so this is the default behavior. */
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530518 gd->arch.i2c1_clk = sys_info.freq_systembus / 2;
Timur Tabi88353a92008-04-04 11:15:58 -0500519#endif
Simon Glass609e6ec2012-12-13 20:48:49 +0000520 gd->arch.i2c2_clk = gd->arch.i2c1_clk;
Timur Tabi943afa22008-01-09 14:35:26 -0600521
Dipen Dudhat6b9ea082009-09-01 17:27:00 +0530522#if defined(CONFIG_FSL_ESDHC)
Priyanka Jain7d640e92011-02-08 15:45:25 +0530523#if defined(CONFIG_MPC8569) || defined(CONFIG_P1010) ||\
524 defined(CONFIG_P1014)
Simon Glasse9adeca2012-12-13 20:49:05 +0000525 gd->arch.sdhc_clk = gd->bus_clk;
Anton Vorontsov7f52ed52009-10-15 17:47:06 +0400526#else
Simon Glasse9adeca2012-12-13 20:49:05 +0000527 gd->arch.sdhc_clk = gd->bus_clk / 2;
Kumar Galaef50d6c2008-08-12 11:14:19 -0500528#endif
Anton Vorontsov7f52ed52009-10-15 17:47:06 +0400529#endif /* defined(CONFIG_FSL_ESDHC) */
Kumar Galaef50d6c2008-08-12 11:14:19 -0500530
Jon Loeliger9c4c5ae2005-07-23 10:37:35 -0500531#if defined(CONFIG_CPM2)
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530532 gd->arch.vco_out = 2*sys_info.freq_systembus;
Simon Glass748cd052012-12-13 20:48:46 +0000533 gd->arch.cpm_clk = gd->arch.vco_out / 2;
534 gd->arch.scc_clk = gd->arch.vco_out / 4;
535 gd->arch.brg_clk = gd->arch.vco_out / (1 << (2 * (dfbrg + 1)));
wdenk42d1f032003-10-15 23:53:47 +0000536#endif
537
538 if(gd->cpu_clk != 0) return (0);
539 else return (1);
540}
541
542
543/********************************************
544 * get_bus_freq
545 * return system bus freq in Hz
546 *********************************************/
547ulong get_bus_freq (ulong dummy)
548{
James Yanga3e77fa2008-02-08 18:05:08 -0600549 return gd->bus_clk;
wdenk42d1f032003-10-15 23:53:47 +0000550}
Kumar Galad4357932007-12-07 04:59:26 -0600551
552/********************************************
553 * get_ddr_freq
554 * return ddr bus freq in Hz
555 *********************************************/
556ulong get_ddr_freq (ulong dummy)
557{
James Yanga3e77fa2008-02-08 18:05:08 -0600558 return gd->mem_clk;
Kumar Galad4357932007-12-07 04:59:26 -0600559}