blob: cb8281e19e13e15204cfe6fb129149308207a342 [file] [log] [blame]
wdenk9c53f402003-10-15 23:53:47 +00001/*
Dipen Dudhat5d51bf92011-01-19 12:46:27 +05302 * Copyright 2004, 2007-2011 Freescale Semiconductor, Inc.
Kumar Galadccd9e32009-03-19 02:46:19 -05003 *
wdenk9c53f402003-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 Denkd79de1d2013-07-08 09:37:19 +020010 * SPDX-License-Identifier: GPL-2.0+
wdenk9c53f402003-10-15 23:53:47 +000011 */
12
13#include <common.h>
14#include <ppc_asm.tmpl>
Haiying Wang8cb2af72011-02-11 01:25:30 -060015#include <linux/compiler.h>
wdenk9c53f402003-10-15 23:53:47 +000016#include <asm/processor.h>
Trent Piepho0b691fc2008-12-03 15:16:37 -080017#include <asm/io.h>
wdenk9c53f402003-10-15 23:53:47 +000018
Wolfgang Denk6405a152006-03-31 18:32:53 +020019DECLARE_GLOBAL_DATA_PTR;
20
Prabhakar Kushwaha7e8382f2013-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
wdenk9c53f402003-10-15 23:53:47 +000025/* --------------------------------------------------------------- */
26
Prabhakar Kushwahad1698082013-08-16 14:52:26 +053027void get_sys_info(sys_info_t *sys_info)
wdenk9c53f402003-10-15 23:53:47 +000028{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020029 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Kumar Galadccd9e32009-03-19 02:46:19 -050030#ifdef CONFIG_FSL_CORENET
31 volatile ccsr_clk_t *clk = (void *)(CONFIG_SYS_FSL_CORENET_CLK_ADDR);
Timur Tabi47289422011-08-05 16:15:24 -050032 unsigned int cpu;
Shaveta Leekhadbf0bc82015-01-19 12:46:54 +053033#ifdef CONFIG_HETROGENOUS_CLUSTERS
34 unsigned int dsp_cpu;
35 uint rcw_tmp1, rcw_tmp2;
36#endif
Prabhakar Kushwaha7e8382f2013-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 Sun7c355f52014-10-27 11:31:33 -070040 __maybe_unused u32 svr;
Kumar Galadccd9e32009-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 Kushwahad1698082013-08-16 14:52:26 +053057 const u8 core_cplx_pll_div[16] = {
Kumar Galadccd9e32009-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 Kushwaha7e8382f2013-09-03 11:20:15 +053071 uint i, freq_c_pll[CONFIG_SYS_FSL_NUM_CC_PLLS];
Yangbo Lu163beec2015-04-22 13:57:40 +080072#if !defined(CONFIG_FM_PLAT_CLK_DIV) || !defined(CONFIG_PME_PLAT_CLK_DIV) || \
73 defined(CONFIG_FSL_ESDHC_USE_PERIPHERAL_CLK)
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +053074 uint rcw_tmp;
75#endif
76 uint ratio[CONFIG_SYS_FSL_NUM_CC_PLLS];
Kumar Galadccd9e32009-03-19 02:46:19 -050077 unsigned long sysclk = CONFIG_SYS_CLK_FREQ;
Srikanth Srinivasanf58c2a42010-02-10 17:32:43 +080078 uint mem_pll_rat;
Kumar Galadccd9e32009-03-19 02:46:19 -050079
Prabhakar Kushwahad1698082013-08-16 14:52:26 +053080 sys_info->freq_systembus = sysclk;
Priyanka Jaine9dcaa82013-12-17 14:25:52 +053081#ifdef CONFIG_SYS_FSL_SINGLE_SOURCE_CLK
vijay raid84fd502014-04-15 11:34:12 +053082 uint ddr_refclk_sel;
83 unsigned int porsr1_sys_clk;
84 porsr1_sys_clk = in_be32(&gur->porsr1) >> FSL_DCFG_PORSR1_SYSCLK_SHIFT
85 & FSL_DCFG_PORSR1_SYSCLK_MASK;
86 if (porsr1_sys_clk == FSL_DCFG_PORSR1_SYSCLK_DIFF)
87 sys_info->diff_sysclk = 1;
88 else
89 sys_info->diff_sysclk = 0;
90
Priyanka Jaine9dcaa82013-12-17 14:25:52 +053091 /*
92 * DDR_REFCLK_SEL rcw bit is used to determine if DDR PLLS
93 * are driven by separate DDR Refclock or single source
94 * differential clock.
95 */
vijay raid84fd502014-04-15 11:34:12 +053096 ddr_refclk_sel = (in_be32(&gur->rcwsr[5]) >>
Priyanka Jaine9dcaa82013-12-17 14:25:52 +053097 FSL_CORENET2_RCWSR5_DDR_REFCLK_SEL_SHIFT) &
98 FSL_CORENET2_RCWSR5_DDR_REFCLK_SEL_MASK;
99 /*
vijay raid84fd502014-04-15 11:34:12 +0530100 * For single source clocking, both ddrclock and sysclock
Priyanka Jaine9dcaa82013-12-17 14:25:52 +0530101 * are driven by differential sysclock.
102 */
vijay raid84fd502014-04-15 11:34:12 +0530103 if (ddr_refclk_sel == FSL_CORENET2_RCWSR5_DDR_REFCLK_SINGLE_CLK)
Priyanka Jaine9dcaa82013-12-17 14:25:52 +0530104 sys_info->freq_ddrbus = CONFIG_SYS_CLK_FREQ;
vijay raid84fd502014-04-15 11:34:12 +0530105 else
Priyanka Jaine9dcaa82013-12-17 14:25:52 +0530106#endif
York Sun3b5179f2012-10-08 07:44:31 +0000107#ifdef CONFIG_DDR_CLK_FREQ
Priyanka Jaine9dcaa82013-12-17 14:25:52 +0530108 sys_info->freq_ddrbus = CONFIG_DDR_CLK_FREQ;
York Sun3b5179f2012-10-08 07:44:31 +0000109#else
Priyanka Jaine9dcaa82013-12-17 14:25:52 +0530110 sys_info->freq_ddrbus = sysclk;
York Sun3b5179f2012-10-08 07:44:31 +0000111#endif
Kumar Galadccd9e32009-03-19 02:46:19 -0500112
Prabhakar Kushwahad1698082013-08-16 14:52:26 +0530113 sys_info->freq_systembus *= (in_be32(&gur->rcwsr[0]) >> 25) & 0x1f;
York Sunb8a076b2012-10-08 07:44:09 +0000114 mem_pll_rat = (in_be32(&gur->rcwsr[0]) >>
115 FSL_CORENET_RCWSR0_MEM_PLL_RAT_SHIFT)
116 & FSL_CORENET_RCWSR0_MEM_PLL_RAT_MASK;
York Sun7b083df2014-03-28 15:07:27 -0700117#ifdef CONFIG_SYS_FSL_ERRATUM_A007212
118 if (mem_pll_rat == 0) {
119 mem_pll_rat = (in_be32(&gur->rcwsr[0]) >>
120 FSL_CORENET_RCWSR0_MEM_PLL_RAT_RESV_SHIFT) &
121 FSL_CORENET_RCWSR0_MEM_PLL_RAT_MASK;
122 }
123#endif
Zang Roy-R619111b1e5cf2013-11-28 13:23:37 +0800124 /* T4240/T4160 Rev2.0 MEM_PLL_RAT uses a value which is half of
125 * T4240/T4160 Rev1.0. eg. It's 12 in Rev1.0, however, for Rev2.0
126 * it uses 6.
York Sun7c355f52014-10-27 11:31:33 -0700127 * T2080 rev 1.1 and later also use half mem_pll comparing with rev 1.0
Zang Roy-R619111b1e5cf2013-11-28 13:23:37 +0800128 */
York Sun0fad3262016-11-21 13:35:41 -0800129#if defined(CONFIG_ARCH_T4240) || defined(CONFIG_ARCH_T4160) || \
York Sunc1845032016-11-21 13:41:30 -0800130 defined(CONFIG_ARCH_T2080) || defined(CONFIG_ARCH_T2081)
York Sun7c355f52014-10-27 11:31:33 -0700131 svr = get_svr();
132 switch (SVR_SOC_VER(svr)) {
133 case SVR_T4240:
134 case SVR_T4160:
135 case SVR_T4120:
136 case SVR_T4080:
137 if (SVR_MAJ(svr) >= 2)
138 mem_pll_rat *= 2;
139 break;
140 case SVR_T2080:
141 case SVR_T2081:
142 if ((SVR_MAJ(svr) > 1) || (SVR_MIN(svr) >= 1))
143 mem_pll_rat *= 2;
144 break;
145 default:
146 break;
147 }
Zang Roy-R619111b1e5cf2013-11-28 13:23:37 +0800148#endif
Srikanth Srinivasanf58c2a42010-02-10 17:32:43 +0800149 if (mem_pll_rat > 2)
Prabhakar Kushwahad1698082013-08-16 14:52:26 +0530150 sys_info->freq_ddrbus *= mem_pll_rat;
Srikanth Srinivasanf58c2a42010-02-10 17:32:43 +0800151 else
Prabhakar Kushwahad1698082013-08-16 14:52:26 +0530152 sys_info->freq_ddrbus = sys_info->freq_systembus * mem_pll_rat;
Kumar Galadccd9e32009-03-19 02:46:19 -0500153
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530154 for (i = 0; i < CONFIG_SYS_FSL_NUM_CC_PLLS; i++) {
155 ratio[i] = (in_be32(&clk->pllcgsr[i].pllcngsr) >> 1) & 0x3f;
Srikanth Srinivasanf58c2a42010-02-10 17:32:43 +0800156 if (ratio[i] > 4)
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530157 freq_c_pll[i] = sysclk * ratio[i];
Srikanth Srinivasanf58c2a42010-02-10 17:32:43 +0800158 else
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530159 freq_c_pll[i] = sys_info->freq_systembus * ratio[i];
Srikanth Srinivasanf58c2a42010-02-10 17:32:43 +0800160 }
Shaveta Leekhadbf0bc82015-01-19 12:46:54 +0530161
York Sund7778f72012-10-08 07:44:11 +0000162#ifdef CONFIG_SYS_FSL_QORIQ_CHASSIS2
163 /*
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530164 * As per CHASSIS2 architeture total 12 clusters are posible and
York Sund7778f72012-10-08 07:44:11 +0000165 * Each cluster has up to 4 cores, sharing the same PLL selection.
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530166 * The cluster clock assignment is SoC defined.
167 *
168 * Total 4 clock groups are possible with 3 PLLs each.
169 * as per array indices, clock group A has 0, 1, 2 numbered PLLs &
170 * clock group B has 3, 4, 6 and so on.
171 *
172 * Clock group A having PLL1, PLL2, PLL3, feeding cores of any cluster
173 * depends upon the SoC architeture. Same applies to other
174 * clock groups and clusters.
175 *
York Sund7778f72012-10-08 07:44:11 +0000176 */
Timur Tabi47289422011-08-05 16:15:24 -0500177 for_each_cpu(i, cpu, cpu_numcores(), cpu_mask()) {
York Sunaa150bb2013-03-25 07:40:07 +0000178 int cluster = fsl_qoriq_core_to_cluster(cpu);
179 u32 c_pll_sel = (in_be32(&clk->clkcsr[cluster].clkcncsr) >> 27)
York Sund7778f72012-10-08 07:44:11 +0000180 & 0xf;
Kumar Galadccd9e32009-03-19 02:46:19 -0500181 u32 cplx_pll = core_cplx_PLL[c_pll_sel];
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530182 cplx_pll += cc_group[cluster] - 1;
Prabhakar Kushwahad1698082013-08-16 14:52:26 +0530183 sys_info->freq_processor[cpu] =
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530184 freq_c_pll[cplx_pll] / core_cplx_pll_div[c_pll_sel];
Kumar Galadccd9e32009-03-19 02:46:19 -0500185 }
Shaveta Leekhadbf0bc82015-01-19 12:46:54 +0530186
187#ifdef CONFIG_HETROGENOUS_CLUSTERS
188 for_each_cpu(i, dsp_cpu, cpu_num_dspcores(), cpu_dsp_mask()) {
189 int dsp_cluster = fsl_qoriq_dsp_core_to_cluster(dsp_cpu);
190 u32 c_pll_sel = (in_be32
191 (&clk->clkcsr[dsp_cluster].clkcncsr) >> 27)
192 & 0xf;
193 u32 cplx_pll = core_cplx_PLL[c_pll_sel];
194 cplx_pll += cc_group[dsp_cluster] - 1;
195 sys_info->freq_processor_dsp[dsp_cpu] =
196 freq_c_pll[cplx_pll] / core_cplx_pll_div[c_pll_sel];
197 }
198#endif
199
York Sunfda566d2016-11-18 11:56:57 -0800200#if defined(CONFIG_ARCH_B4860) || defined(CONFIG_ARCH_B4420) || \
York Sune20c6852016-11-21 12:54:19 -0800201 defined(CONFIG_ARCH_T2080) || defined(CONFIG_ARCH_T2081)
Sandeep Singhf7dfe252013-03-25 07:33:09 +0000202#define FM1_CLK_SEL 0xe0000000
203#define FM1_CLK_SHIFT 29
York Sun7d29dd62016-11-18 13:01:34 -0800204#elif defined(CONFIG_ARCH_T1024) || defined(CONFIG_ARCH_T1023)
Shengzhou Liue6fb7702014-11-24 17:11:54 +0800205#define FM1_CLK_SEL 0x00000007
206#define FM1_CLK_SHIFT 0
Sandeep Singhf7dfe252013-03-25 07:33:09 +0000207#else
York Sund7778f72012-10-08 07:44:11 +0000208#define PME_CLK_SEL 0xe0000000
209#define PME_CLK_SHIFT 29
210#define FM1_CLK_SEL 0x1c000000
211#define FM1_CLK_SHIFT 26
Sandeep Singhf7dfe252013-03-25 07:33:09 +0000212#endif
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530213#if !defined(CONFIG_FM_PLAT_CLK_DIV) || !defined(CONFIG_PME_PLAT_CLK_DIV)
York Sun7d29dd62016-11-18 13:01:34 -0800214#if defined(CONFIG_ARCH_T1024) || defined(CONFIG_ARCH_T1023)
Shengzhou Liue6fb7702014-11-24 17:11:54 +0800215 rcw_tmp = in_be32(&gur->rcwsr[15]) - 4;
216#else
York Sund7778f72012-10-08 07:44:11 +0000217 rcw_tmp = in_be32(&gur->rcwsr[7]);
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530218#endif
Shengzhou Liue6fb7702014-11-24 17:11:54 +0800219#endif
York Sund7778f72012-10-08 07:44:11 +0000220
221#ifdef CONFIG_SYS_DPAA_PME
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530222#ifndef CONFIG_PME_PLAT_CLK_DIV
York Sund7778f72012-10-08 07:44:11 +0000223 switch ((rcw_tmp & PME_CLK_SEL) >> PME_CLK_SHIFT) {
224 case 1:
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530225 sys_info->freq_pme = freq_c_pll[CONFIG_SYS_PME_CLK];
York Sund7778f72012-10-08 07:44:11 +0000226 break;
227 case 2:
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530228 sys_info->freq_pme = freq_c_pll[CONFIG_SYS_PME_CLK] / 2;
York Sund7778f72012-10-08 07:44:11 +0000229 break;
230 case 3:
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530231 sys_info->freq_pme = freq_c_pll[CONFIG_SYS_PME_CLK] / 3;
York Sund7778f72012-10-08 07:44:11 +0000232 break;
233 case 4:
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530234 sys_info->freq_pme = freq_c_pll[CONFIG_SYS_PME_CLK] / 4;
York Sund7778f72012-10-08 07:44:11 +0000235 break;
236 case 6:
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530237 sys_info->freq_pme = freq_c_pll[CONFIG_SYS_PME_CLK + 1] / 2;
York Sund7778f72012-10-08 07:44:11 +0000238 break;
239 case 7:
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530240 sys_info->freq_pme = freq_c_pll[CONFIG_SYS_PME_CLK + 1] / 3;
York Sund7778f72012-10-08 07:44:11 +0000241 break;
242 default:
243 printf("Error: Unknown PME clock select!\n");
244 case 0:
Prabhakar Kushwahad1698082013-08-16 14:52:26 +0530245 sys_info->freq_pme = sys_info->freq_systembus / 2;
York Sund7778f72012-10-08 07:44:11 +0000246 break;
247
248 }
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530249#else
250 sys_info->freq_pme = sys_info->freq_systembus / CONFIG_SYS_PME_CLK;
251
252#endif
York Sund7778f72012-10-08 07:44:11 +0000253#endif
254
Haiying Wang09d0aa92012-10-11 07:13:39 +0000255#ifdef CONFIG_SYS_DPAA_QBMAN
Shengzhou Liue6fb7702014-11-24 17:11:54 +0800256#ifndef CONFIG_QBMAN_CLK_DIV
257#define CONFIG_QBMAN_CLK_DIV 2
258#endif
259 sys_info->freq_qman = sys_info->freq_systembus / CONFIG_QBMAN_CLK_DIV;
Haiying Wang09d0aa92012-10-11 07:13:39 +0000260#endif
261
Shaveta Leekhadbf0bc82015-01-19 12:46:54 +0530262#if defined(CONFIG_SYS_MAPLE)
263#define CPRI_CLK_SEL 0x1C000000
264#define CPRI_CLK_SHIFT 26
265#define CPRI_ALT_CLK_SEL 0x00007000
266#define CPRI_ALT_CLK_SHIFT 12
267
268 rcw_tmp1 = in_be32(&gur->rcwsr[7]); /* Reading RCW bits: 224-255*/
269 rcw_tmp2 = in_be32(&gur->rcwsr[15]); /* Reading RCW bits: 480-511*/
270 /* For MAPLE and CPRI frequency */
271 switch ((rcw_tmp1 & CPRI_CLK_SEL) >> CPRI_CLK_SHIFT) {
272 case 1:
273 sys_info->freq_maple = freq_c_pll[CONFIG_SYS_CPRI_CLK];
274 sys_info->freq_cpri = freq_c_pll[CONFIG_SYS_CPRI_CLK];
275 break;
276 case 2:
277 sys_info->freq_maple = freq_c_pll[CONFIG_SYS_CPRI_CLK] / 2;
278 sys_info->freq_cpri = freq_c_pll[CONFIG_SYS_CPRI_CLK] / 2;
279 break;
280 case 3:
281 sys_info->freq_maple = freq_c_pll[CONFIG_SYS_CPRI_CLK] / 3;
282 sys_info->freq_cpri = freq_c_pll[CONFIG_SYS_CPRI_CLK] / 3;
283 break;
284 case 4:
285 sys_info->freq_maple = freq_c_pll[CONFIG_SYS_CPRI_CLK] / 4;
286 sys_info->freq_cpri = freq_c_pll[CONFIG_SYS_CPRI_CLK] / 4;
287 break;
288 case 5:
289 if (((rcw_tmp2 & CPRI_ALT_CLK_SEL)
290 >> CPRI_ALT_CLK_SHIFT) == 6) {
291 sys_info->freq_maple =
292 freq_c_pll[CONFIG_SYS_CPRI_CLK - 2] / 2;
293 sys_info->freq_cpri =
294 freq_c_pll[CONFIG_SYS_CPRI_CLK - 2] / 2;
295 }
296 if (((rcw_tmp2 & CPRI_ALT_CLK_SEL)
297 >> CPRI_ALT_CLK_SHIFT) == 7) {
298 sys_info->freq_maple =
299 freq_c_pll[CONFIG_SYS_CPRI_CLK - 2] / 3;
300 sys_info->freq_cpri =
301 freq_c_pll[CONFIG_SYS_CPRI_CLK - 2] / 3;
302 }
303 break;
304 case 6:
305 sys_info->freq_maple = freq_c_pll[CONFIG_SYS_CPRI_CLK + 1] / 2;
306 sys_info->freq_cpri = freq_c_pll[CONFIG_SYS_CPRI_CLK + 1] / 2;
307 break;
308 case 7:
309 sys_info->freq_maple = freq_c_pll[CONFIG_SYS_CPRI_CLK + 1] / 3;
310 sys_info->freq_cpri = freq_c_pll[CONFIG_SYS_CPRI_CLK + 1] / 3;
311 break;
312 default:
313 printf("Error: Unknown MAPLE/CPRI clock select!\n");
314 }
315
316 /* For MAPLE ULB and eTVPE frequencies */
317#define ULB_CLK_SEL 0x00000038
318#define ULB_CLK_SHIFT 3
319#define ETVPE_CLK_SEL 0x00000007
320#define ETVPE_CLK_SHIFT 0
321
322 switch ((rcw_tmp2 & ULB_CLK_SEL) >> ULB_CLK_SHIFT) {
323 case 1:
324 sys_info->freq_maple_ulb = freq_c_pll[CONFIG_SYS_ULB_CLK];
325 break;
326 case 2:
327 sys_info->freq_maple_ulb = freq_c_pll[CONFIG_SYS_ULB_CLK] / 2;
328 break;
329 case 3:
330 sys_info->freq_maple_ulb = freq_c_pll[CONFIG_SYS_ULB_CLK] / 3;
331 break;
332 case 4:
333 sys_info->freq_maple_ulb = freq_c_pll[CONFIG_SYS_ULB_CLK] / 4;
334 break;
335 case 5:
336 sys_info->freq_maple_ulb = sys_info->freq_systembus;
337 break;
338 case 6:
339 sys_info->freq_maple_ulb =
340 freq_c_pll[CONFIG_SYS_ULB_CLK - 1] / 2;
341 break;
342 case 7:
343 sys_info->freq_maple_ulb =
344 freq_c_pll[CONFIG_SYS_ULB_CLK - 1] / 3;
345 break;
346 default:
347 printf("Error: Unknown MAPLE ULB clock select!\n");
348 }
349
350 switch ((rcw_tmp2 & ETVPE_CLK_SEL) >> ETVPE_CLK_SHIFT) {
351 case 1:
352 sys_info->freq_maple_etvpe = freq_c_pll[CONFIG_SYS_ETVPE_CLK];
353 break;
354 case 2:
355 sys_info->freq_maple_etvpe =
356 freq_c_pll[CONFIG_SYS_ETVPE_CLK] / 2;
357 break;
358 case 3:
359 sys_info->freq_maple_etvpe =
360 freq_c_pll[CONFIG_SYS_ETVPE_CLK] / 3;
361 break;
362 case 4:
363 sys_info->freq_maple_etvpe =
364 freq_c_pll[CONFIG_SYS_ETVPE_CLK] / 4;
365 break;
366 case 5:
367 sys_info->freq_maple_etvpe = sys_info->freq_systembus;
368 break;
369 case 6:
370 sys_info->freq_maple_etvpe =
371 freq_c_pll[CONFIG_SYS_ETVPE_CLK - 1] / 2;
372 break;
373 case 7:
374 sys_info->freq_maple_etvpe =
375 freq_c_pll[CONFIG_SYS_ETVPE_CLK - 1] / 3;
376 break;
377 default:
378 printf("Error: Unknown MAPLE eTVPE clock select!\n");
379 }
380
381#endif
382
York Sund7778f72012-10-08 07:44:11 +0000383#ifdef CONFIG_SYS_DPAA_FMAN
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530384#ifndef CONFIG_FM_PLAT_CLK_DIV
York Sund7778f72012-10-08 07:44:11 +0000385 switch ((rcw_tmp & FM1_CLK_SEL) >> FM1_CLK_SHIFT) {
386 case 1:
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530387 sys_info->freq_fman[0] = freq_c_pll[CONFIG_SYS_FM1_CLK];
York Sund7778f72012-10-08 07:44:11 +0000388 break;
389 case 2:
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530390 sys_info->freq_fman[0] = freq_c_pll[CONFIG_SYS_FM1_CLK] / 2;
York Sund7778f72012-10-08 07:44:11 +0000391 break;
392 case 3:
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530393 sys_info->freq_fman[0] = freq_c_pll[CONFIG_SYS_FM1_CLK] / 3;
York Sund7778f72012-10-08 07:44:11 +0000394 break;
395 case 4:
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530396 sys_info->freq_fman[0] = freq_c_pll[CONFIG_SYS_FM1_CLK] / 4;
York Sund7778f72012-10-08 07:44:11 +0000397 break;
Sandeep Singhf7dfe252013-03-25 07:33:09 +0000398 case 5:
Prabhakar Kushwahad1698082013-08-16 14:52:26 +0530399 sys_info->freq_fman[0] = sys_info->freq_systembus;
Sandeep Singhf7dfe252013-03-25 07:33:09 +0000400 break;
York Sund7778f72012-10-08 07:44:11 +0000401 case 6:
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530402 sys_info->freq_fman[0] = freq_c_pll[CONFIG_SYS_FM1_CLK + 1] / 2;
York Sund7778f72012-10-08 07:44:11 +0000403 break;
404 case 7:
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530405 sys_info->freq_fman[0] = freq_c_pll[CONFIG_SYS_FM1_CLK + 1] / 3;
York Sund7778f72012-10-08 07:44:11 +0000406 break;
407 default:
408 printf("Error: Unknown FMan1 clock select!\n");
409 case 0:
Prabhakar Kushwahad1698082013-08-16 14:52:26 +0530410 sys_info->freq_fman[0] = sys_info->freq_systembus / 2;
York Sund7778f72012-10-08 07:44:11 +0000411 break;
412 }
413#if (CONFIG_SYS_NUM_FMAN) == 2
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530414#ifdef CONFIG_SYS_FM2_CLK
York Sund7778f72012-10-08 07:44:11 +0000415#define FM2_CLK_SEL 0x00000038
416#define FM2_CLK_SHIFT 3
417 rcw_tmp = in_be32(&gur->rcwsr[15]);
418 switch ((rcw_tmp & FM2_CLK_SEL) >> FM2_CLK_SHIFT) {
419 case 1:
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530420 sys_info->freq_fman[1] = freq_c_pll[CONFIG_SYS_FM2_CLK + 1];
York Sund7778f72012-10-08 07:44:11 +0000421 break;
422 case 2:
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530423 sys_info->freq_fman[1] = freq_c_pll[CONFIG_SYS_FM2_CLK + 1] / 2;
York Sund7778f72012-10-08 07:44:11 +0000424 break;
425 case 3:
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530426 sys_info->freq_fman[1] = freq_c_pll[CONFIG_SYS_FM2_CLK + 1] / 3;
York Sund7778f72012-10-08 07:44:11 +0000427 break;
428 case 4:
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530429 sys_info->freq_fman[1] = freq_c_pll[CONFIG_SYS_FM2_CLK + 1] / 4;
York Sund7778f72012-10-08 07:44:11 +0000430 break;
Shaohui Xie45359a32013-11-28 13:52:51 +0800431 case 5:
432 sys_info->freq_fman[1] = sys_info->freq_systembus;
433 break;
York Sund7778f72012-10-08 07:44:11 +0000434 case 6:
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530435 sys_info->freq_fman[1] = freq_c_pll[CONFIG_SYS_FM2_CLK] / 2;
York Sund7778f72012-10-08 07:44:11 +0000436 break;
437 case 7:
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530438 sys_info->freq_fman[1] = freq_c_pll[CONFIG_SYS_FM2_CLK] / 3;
York Sund7778f72012-10-08 07:44:11 +0000439 break;
440 default:
441 printf("Error: Unknown FMan2 clock select!\n");
442 case 0:
Prabhakar Kushwahad1698082013-08-16 14:52:26 +0530443 sys_info->freq_fman[1] = sys_info->freq_systembus / 2;
York Sund7778f72012-10-08 07:44:11 +0000444 break;
445 }
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530446#endif
York Sund7778f72012-10-08 07:44:11 +0000447#endif /* CONFIG_SYS_NUM_FMAN == 2 */
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530448#else
449 sys_info->freq_fman[0] = sys_info->freq_systembus / CONFIG_SYS_FM1_CLK;
450#endif
451#endif
Kumar Galadccd9e32009-03-19 02:46:19 -0500452
Yangbo Lu163beec2015-04-22 13:57:40 +0800453#ifdef CONFIG_FSL_ESDHC_USE_PERIPHERAL_CLK
York Sune20c6852016-11-21 12:54:19 -0800454#if defined(CONFIG_ARCH_T2080)
Yangbo Lu163beec2015-04-22 13:57:40 +0800455#define ESDHC_CLK_SEL 0x00000007
456#define ESDHC_CLK_SHIFT 0
457#define ESDHC_CLK_RCWSR 15
458#else /* Support T1040 T1024 by now */
459#define ESDHC_CLK_SEL 0xe0000000
460#define ESDHC_CLK_SHIFT 29
461#define ESDHC_CLK_RCWSR 7
462#endif
463 rcw_tmp = in_be32(&gur->rcwsr[ESDHC_CLK_RCWSR]);
464 switch ((rcw_tmp & ESDHC_CLK_SEL) >> ESDHC_CLK_SHIFT) {
465 case 1:
466 sys_info->freq_sdhc = freq_c_pll[CONFIG_SYS_SDHC_CLK];
467 break;
468 case 2:
469 sys_info->freq_sdhc = freq_c_pll[CONFIG_SYS_SDHC_CLK] / 2;
470 break;
471 case 3:
472 sys_info->freq_sdhc = freq_c_pll[CONFIG_SYS_SDHC_CLK] / 3;
473 break;
474#if defined(CONFIG_SYS_SDHC_CLK_2_PLL)
475 case 4:
476 sys_info->freq_sdhc = freq_c_pll[CONFIG_SYS_SDHC_CLK] / 4;
477 break;
York Sune20c6852016-11-21 12:54:19 -0800478#if defined(CONFIG_ARCH_T2080)
Yangbo Lu163beec2015-04-22 13:57:40 +0800479 case 5:
480 sys_info->freq_sdhc = freq_c_pll[1 - CONFIG_SYS_SDHC_CLK];
481 break;
482#endif
483 case 6:
484 sys_info->freq_sdhc = freq_c_pll[1 - CONFIG_SYS_SDHC_CLK] / 2;
485 break;
486 case 7:
487 sys_info->freq_sdhc = freq_c_pll[1 - CONFIG_SYS_SDHC_CLK] / 3;
488 break;
489#endif
490 default:
491 sys_info->freq_sdhc = 0;
492 printf("Error: Unknown SDHC peripheral clock select!\n");
493 }
494#endif
York Sund7778f72012-10-08 07:44:11 +0000495#else /* CONFIG_SYS_FSL_QORIQ_CHASSIS2 */
496
497 for_each_cpu(i, cpu, cpu_numcores(), cpu_mask()) {
York Sunaa150bb2013-03-25 07:40:07 +0000498 u32 c_pll_sel = (in_be32(&clk->clkcsr[cpu].clkcncsr) >> 27)
499 & 0xf;
York Sund7778f72012-10-08 07:44:11 +0000500 u32 cplx_pll = core_cplx_PLL[c_pll_sel];
501
Prabhakar Kushwahad1698082013-08-16 14:52:26 +0530502 sys_info->freq_processor[cpu] =
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530503 freq_c_pll[cplx_pll] / core_cplx_pll_div[c_pll_sel];
York Sund7778f72012-10-08 07:44:11 +0000504 }
Kumar Galadccd9e32009-03-19 02:46:19 -0500505#define PME_CLK_SEL 0x80000000
506#define FM1_CLK_SEL 0x40000000
507#define FM2_CLK_SEL 0x20000000
Kumar Gala3842bb52011-02-16 02:03:29 -0600508#define HWA_ASYNC_DIV 0x04000000
509#if (CONFIG_SYS_FSL_NUM_CC_PLLS == 2)
510#define HWA_CC_PLL 1
Timur Tabid5e13882012-10-05 11:09:19 +0000511#elif (CONFIG_SYS_FSL_NUM_CC_PLLS == 3)
512#define HWA_CC_PLL 2
Kumar Gala3842bb52011-02-16 02:03:29 -0600513#elif (CONFIG_SYS_FSL_NUM_CC_PLLS == 4)
Wolfgang Denk80f70212011-05-19 22:21:41 +0200514#define HWA_CC_PLL 2
Kumar Gala3842bb52011-02-16 02:03:29 -0600515#else
516#error CONFIG_SYS_FSL_NUM_CC_PLLS not set or unknown case
517#endif
Kumar Galadccd9e32009-03-19 02:46:19 -0500518 rcw_tmp = in_be32(&gur->rcwsr[7]);
519
520#ifdef CONFIG_SYS_DPAA_PME
Kumar Gala3842bb52011-02-16 02:03:29 -0600521 if (rcw_tmp & PME_CLK_SEL) {
522 if (rcw_tmp & HWA_ASYNC_DIV)
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530523 sys_info->freq_pme = freq_c_pll[HWA_CC_PLL] / 4;
Kumar Gala3842bb52011-02-16 02:03:29 -0600524 else
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530525 sys_info->freq_pme = freq_c_pll[HWA_CC_PLL] / 2;
Kumar Gala3842bb52011-02-16 02:03:29 -0600526 } else {
Prabhakar Kushwahad1698082013-08-16 14:52:26 +0530527 sys_info->freq_pme = sys_info->freq_systembus / 2;
Kumar Gala3842bb52011-02-16 02:03:29 -0600528 }
Kumar Galadccd9e32009-03-19 02:46:19 -0500529#endif
530
531#ifdef CONFIG_SYS_DPAA_FMAN
Kumar Gala3842bb52011-02-16 02:03:29 -0600532 if (rcw_tmp & FM1_CLK_SEL) {
533 if (rcw_tmp & HWA_ASYNC_DIV)
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530534 sys_info->freq_fman[0] = freq_c_pll[HWA_CC_PLL] / 4;
Kumar Gala3842bb52011-02-16 02:03:29 -0600535 else
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530536 sys_info->freq_fman[0] = freq_c_pll[HWA_CC_PLL] / 2;
Kumar Gala3842bb52011-02-16 02:03:29 -0600537 } else {
Prabhakar Kushwahad1698082013-08-16 14:52:26 +0530538 sys_info->freq_fman[0] = sys_info->freq_systembus / 2;
Kumar Gala3842bb52011-02-16 02:03:29 -0600539 }
Kumar Galadccd9e32009-03-19 02:46:19 -0500540#if (CONFIG_SYS_NUM_FMAN) == 2
Kumar Gala3842bb52011-02-16 02:03:29 -0600541 if (rcw_tmp & FM2_CLK_SEL) {
542 if (rcw_tmp & HWA_ASYNC_DIV)
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530543 sys_info->freq_fman[1] = freq_c_pll[HWA_CC_PLL] / 4;
Kumar Gala3842bb52011-02-16 02:03:29 -0600544 else
Prabhakar Kushwaha7e8382f2013-09-03 11:20:15 +0530545 sys_info->freq_fman[1] = freq_c_pll[HWA_CC_PLL] / 2;
Kumar Gala3842bb52011-02-16 02:03:29 -0600546 } else {
Prabhakar Kushwahad1698082013-08-16 14:52:26 +0530547 sys_info->freq_fman[1] = sys_info->freq_systembus / 2;
Kumar Gala3842bb52011-02-16 02:03:29 -0600548 }
Kumar Galadccd9e32009-03-19 02:46:19 -0500549#endif
550#endif
551
Shaohui Xie835c9ad2013-03-25 07:33:25 +0000552#ifdef CONFIG_SYS_DPAA_QBMAN
Prabhakar Kushwahad1698082013-08-16 14:52:26 +0530553 sys_info->freq_qman = sys_info->freq_systembus / 2;
Shaohui Xie835c9ad2013-03-25 07:33:25 +0000554#endif
555
York Sund7778f72012-10-08 07:44:11 +0000556#endif /* CONFIG_SYS_FSL_QORIQ_CHASSIS2 */
557
Zhao Qiangb818ba22014-03-21 16:21:45 +0800558#ifdef CONFIG_U_QE
559 sys_info->freq_qe = sys_info->freq_systembus / 2;
560#endif
561
York Sund7778f72012-10-08 07:44:11 +0000562#else /* CONFIG_FSL_CORENET */
Prabhakar Kushwahad1698082013-08-16 14:52:26 +0530563 uint plat_ratio, e500_ratio, half_freq_systembus;
Haiying Wangbb8aea72009-01-15 11:58:35 -0500564 int i;
Haiying Wang61414682009-05-20 12:30:29 -0400565#ifdef CONFIG_QE
Haiying Wang8cb2af72011-02-11 01:25:30 -0600566 __maybe_unused u32 qe_ratio;
Haiying Wang61414682009-05-20 12:30:29 -0400567#endif
wdenk9c53f402003-10-15 23:53:47 +0000568
569 plat_ratio = (gur->porpllsr) & 0x0000003e;
570 plat_ratio >>= 1;
Prabhakar Kushwahad1698082013-08-16 14:52:26 +0530571 sys_info->freq_systembus = plat_ratio * CONFIG_SYS_CLK_FREQ;
Andy Fleming6d972762007-04-23 02:37:47 -0500572
573 /* Divide before multiply to avoid integer
574 * overflow for processor speeds above 2GHz */
Prabhakar Kushwahad1698082013-08-16 14:52:26 +0530575 half_freq_systembus = sys_info->freq_systembus/2;
Poonam Aggrwal4baef822009-07-31 12:08:14 +0530576 for (i = 0; i < cpu_numcores(); i++) {
Haiying Wangbb8aea72009-01-15 11:58:35 -0500577 e500_ratio = ((gur->porpllsr) >> (i * 8 + 16)) & 0x3f;
Prabhakar Kushwahad1698082013-08-16 14:52:26 +0530578 sys_info->freq_processor[i] = e500_ratio * half_freq_systembus;
Haiying Wangbb8aea72009-01-15 11:58:35 -0500579 }
James Yangd1d51ad2008-02-08 18:05:08 -0600580
Prabhakar Kushwahad1698082013-08-16 14:52:26 +0530581 /* Note: freq_ddrbus is the MCLK frequency, not the data rate. */
582 sys_info->freq_ddrbus = sys_info->freq_systembus;
Kumar Gala07db1702007-12-07 04:59:26 -0600583
584#ifdef CONFIG_DDR_CLK_FREQ
585 {
Jason Jinbfcd6c32008-09-27 14:40:57 +0800586 u32 ddr_ratio = ((gur->porpllsr) & MPC85xx_PORPLLSR_DDR_RATIO)
587 >> MPC85xx_PORPLLSR_DDR_RATIO_SHIFT;
Kumar Gala07db1702007-12-07 04:59:26 -0600588 if (ddr_ratio != 0x7)
Prabhakar Kushwahad1698082013-08-16 14:52:26 +0530589 sys_info->freq_ddrbus = ddr_ratio * CONFIG_DDR_CLK_FREQ;
Kumar Gala07db1702007-12-07 04:59:26 -0600590 }
591#endif
Trent Piepho0b691fc2008-12-03 15:16:37 -0800592
Haiying Wang61414682009-05-20 12:30:29 -0400593#ifdef CONFIG_QE
York Sun0f577972016-11-18 11:05:38 -0800594#if defined(CONFIG_ARCH_P1021) || defined(CONFIG_ARCH_P1025)
Prabhakar Kushwahad1698082013-08-16 14:52:26 +0530595 sys_info->freq_qe = sys_info->freq_systembus;
Haiying Wang8cb2af72011-02-11 01:25:30 -0600596#else
Haiying Wang61414682009-05-20 12:30:29 -0400597 qe_ratio = ((gur->porpllsr) & MPC85xx_PORPLLSR_QE_RATIO)
598 >> MPC85xx_PORPLLSR_QE_RATIO_SHIFT;
Prabhakar Kushwahad1698082013-08-16 14:52:26 +0530599 sys_info->freq_qe = qe_ratio * CONFIG_SYS_CLK_FREQ;
Haiying Wang61414682009-05-20 12:30:29 -0400600#endif
Haiying Wang8cb2af72011-02-11 01:25:30 -0600601#endif
Haiying Wang325a12f2011-01-20 22:26:31 +0000602
603#ifdef CONFIG_SYS_DPAA_FMAN
Prabhakar Kushwahad1698082013-08-16 14:52:26 +0530604 sys_info->freq_fman[0] = sys_info->freq_systembus;
Haiying Wang325a12f2011-01-20 22:26:31 +0000605#endif
606
607#endif /* CONFIG_FSL_CORENET */
Haiying Wang61414682009-05-20 12:30:29 -0400608
Dipen Dudhat5d51bf92011-01-19 12:46:27 +0530609#if defined(CONFIG_FSL_LBC)
Prabhakar Kushwahabedc5622017-02-02 15:02:00 +0530610 sys_info->freq_localbus = sys_info->freq_systembus /
611 CONFIG_SYS_FSL_LBC_CLK_DIV;
Dipen Dudhat5d51bf92011-01-19 12:46:27 +0530612#endif
Kumar Gala17ec6fa2012-10-08 07:44:06 +0000613
614#if defined(CONFIG_FSL_IFC)
Prabhakar Kushwaha3c48f582017-02-02 15:01:26 +0530615 sys_info->freq_localbus = sys_info->freq_systembus /
616 CONFIG_SYS_FSL_IFC_CLK_DIV;
Kumar Gala17ec6fa2012-10-08 07:44:06 +0000617#endif
wdenk9c53f402003-10-15 23:53:47 +0000618}
619
Andy Fleming6d972762007-04-23 02:37:47 -0500620
wdenk9c53f402003-10-15 23:53:47 +0000621int get_clocks (void)
622{
wdenk9c53f402003-10-15 23:53:47 +0000623 sys_info_t sys_info;
York Sun5ac012a2016-11-15 13:57:15 -0800624#ifdef CONFIG_ARCH_MPC8544
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200625 volatile ccsr_gur_t *gur = (void *) CONFIG_SYS_MPC85xx_GUTS_ADDR;
Timur Tabi44befe02008-04-04 11:15:58 -0500626#endif
Jon Loeligerf5ad3782005-07-23 10:37:35 -0500627#if defined(CONFIG_CPM2)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200628 volatile ccsr_cpm_t *cpm = (ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR;
wdenk9c53f402003-10-15 23:53:47 +0000629 uint sccr, dfbrg;
630
631 /* set VCO = 4 * BRG */
Kumar Galacd113a02007-11-28 00:36:33 -0600632 cpm->im_cpm_intctl.sccr &= 0xfffffffc;
633 sccr = cpm->im_cpm_intctl.sccr;
wdenk9c53f402003-10-15 23:53:47 +0000634 dfbrg = (sccr & SCCR_DFBRG_MSK) >> SCCR_DFBRG_SHIFT;
635#endif
636 get_sys_info (&sys_info);
Prabhakar Kushwahad1698082013-08-16 14:52:26 +0530637 gd->cpu_clk = sys_info.freq_processor[0];
638 gd->bus_clk = sys_info.freq_systembus;
639 gd->mem_clk = sys_info.freq_ddrbus;
640 gd->arch.lbc_clk = sys_info.freq_localbus;
Timur Tabi44befe02008-04-04 11:15:58 -0500641
Haiying Wang61414682009-05-20 12:30:29 -0400642#ifdef CONFIG_QE
Prabhakar Kushwahad1698082013-08-16 14:52:26 +0530643 gd->arch.qe_clk = sys_info.freq_qe;
Simon Glass8518b172012-12-13 20:48:50 +0000644 gd->arch.brg_clk = gd->arch.qe_clk / 2;
Haiying Wang61414682009-05-20 12:30:29 -0400645#endif
Timur Tabi44befe02008-04-04 11:15:58 -0500646 /*
647 * The base clock for I2C depends on the actual SOC. Unfortunately,
648 * there is no pattern that can be used to determine the frequency, so
649 * the only choice is to look up the actual SOC number and use the value
650 * for that SOC. This information is taken from application note
651 * AN2919.
652 */
York Sunbf820c02016-11-16 11:18:31 -0800653#if defined(CONFIG_ARCH_MPC8540) || defined(CONFIG_ARCH_MPC8541) || \
York Sunb4046f42016-11-16 11:26:45 -0800654 defined(CONFIG_ARCH_MPC8560) || defined(CONFIG_ARCH_MPC8555) || \
York Sun08672a52016-11-16 15:23:52 -0800655 defined(CONFIG_ARCH_P1022)
Prabhakar Kushwahad1698082013-08-16 14:52:26 +0530656 gd->arch.i2c1_clk = sys_info.freq_systembus;
York Sun5ac012a2016-11-15 13:57:15 -0800657#elif defined(CONFIG_ARCH_MPC8544)
Timur Tabi44befe02008-04-04 11:15:58 -0500658 /*
659 * On the 8544, the I2C clock is the same as the SEC clock. This can be
660 * either CCB/2 or CCB/3, depending on the value of cfg_sec_freq. See
661 * 4.4.3.3 of the 8544 RM. Note that this might actually work for all
662 * 85xx, but only the 8544 has cfg_sec_freq, so it's unknown if the
663 * PORDEVSR2_SEC_CFG bit is 0 on all 85xx boards that are not an 8544.
664 */
665 if (gur->pordevsr2 & MPC85xx_PORDEVSR2_SEC_CFG)
Prabhakar Kushwahad1698082013-08-16 14:52:26 +0530666 gd->arch.i2c1_clk = sys_info.freq_systembus / 3;
Kumar Gala9632f662008-10-16 21:58:49 -0500667 else
Prabhakar Kushwahad1698082013-08-16 14:52:26 +0530668 gd->arch.i2c1_clk = sys_info.freq_systembus / 2;
Timur Tabi44befe02008-04-04 11:15:58 -0500669#else
670 /* Most 85xx SOCs use CCB/2, so this is the default behavior. */
Prabhakar Kushwahad1698082013-08-16 14:52:26 +0530671 gd->arch.i2c1_clk = sys_info.freq_systembus / 2;
Timur Tabi44befe02008-04-04 11:15:58 -0500672#endif
Simon Glassc2baaec2012-12-13 20:48:49 +0000673 gd->arch.i2c2_clk = gd->arch.i2c1_clk;
Timur Tabic1499f482008-01-09 14:35:26 -0600674
Dipen Dudhat9af188d2009-09-01 17:27:00 +0530675#if defined(CONFIG_FSL_ESDHC)
Yangbo Lu163beec2015-04-22 13:57:40 +0800676#ifdef CONFIG_FSL_ESDHC_USE_PERIPHERAL_CLK
677 gd->arch.sdhc_clk = sys_info.freq_sdhc / 2;
678#else
York Sun5f163882016-11-16 16:02:09 -0800679#if defined(CONFIG_ARCH_MPC8569) || defined(CONFIG_ARCH_P1010)
Simon Glass9e247d12012-12-13 20:49:05 +0000680 gd->arch.sdhc_clk = gd->bus_clk;
Anton Vorontsovda225942009-10-15 17:47:06 +0400681#else
Simon Glass9e247d12012-12-13 20:49:05 +0000682 gd->arch.sdhc_clk = gd->bus_clk / 2;
Kumar Galacd777282008-08-12 11:14:19 -0500683#endif
Yangbo Lu163beec2015-04-22 13:57:40 +0800684#endif
Anton Vorontsovda225942009-10-15 17:47:06 +0400685#endif /* defined(CONFIG_FSL_ESDHC) */
Kumar Galacd777282008-08-12 11:14:19 -0500686
Jon Loeligerf5ad3782005-07-23 10:37:35 -0500687#if defined(CONFIG_CPM2)
Prabhakar Kushwahad1698082013-08-16 14:52:26 +0530688 gd->arch.vco_out = 2*sys_info.freq_systembus;
Simon Glass44ea8512012-12-13 20:48:46 +0000689 gd->arch.cpm_clk = gd->arch.vco_out / 2;
690 gd->arch.scc_clk = gd->arch.vco_out / 4;
691 gd->arch.brg_clk = gd->arch.vco_out / (1 << (2 * (dfbrg + 1)));
wdenk9c53f402003-10-15 23:53:47 +0000692#endif
693
694 if(gd->cpu_clk != 0) return (0);
695 else return (1);
696}
697
698
699/********************************************
700 * get_bus_freq
701 * return system bus freq in Hz
702 *********************************************/
703ulong get_bus_freq (ulong dummy)
704{
James Yangd1d51ad2008-02-08 18:05:08 -0600705 return gd->bus_clk;
wdenk9c53f402003-10-15 23:53:47 +0000706}
Kumar Gala07db1702007-12-07 04:59:26 -0600707
708/********************************************
709 * get_ddr_freq
710 * return ddr bus freq in Hz
711 *********************************************/
712ulong get_ddr_freq (ulong dummy)
713{
James Yangd1d51ad2008-02-08 18:05:08 -0600714 return gd->mem_clk;
Kumar Gala07db1702007-12-07 04:59:26 -0600715}