blob: f093960fe7e7139cfec9e164f8ff9a5b97a25aaa [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
wdenk42d1f032003-10-15 23:53:47 +000021/* --------------------------------------------------------------- */
22
wdenk42d1f032003-10-15 23:53:47 +000023void get_sys_info (sys_info_t * sysInfo)
24{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020025 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Kumar Gala800c73c2012-10-08 07:44:06 +000026#ifdef CONFIG_FSL_IFC
27 struct fsl_ifc *ifc_regs = (void *)CONFIG_SYS_IFC_ADDR;
28 u32 ccr;
29#endif
Kumar Gala39aaca12009-03-19 02:46:19 -050030#ifdef CONFIG_FSL_CORENET
31 volatile ccsr_clk_t *clk = (void *)(CONFIG_SYS_FSL_CORENET_CLK_ADDR);
Timur Tabifbb9ecf2011-08-05 16:15:24 -050032 unsigned int cpu;
Kumar Gala39aaca12009-03-19 02:46:19 -050033
34 const u8 core_cplx_PLL[16] = {
35 [ 0] = 0, /* CC1 PPL / 1 */
36 [ 1] = 0, /* CC1 PPL / 2 */
37 [ 2] = 0, /* CC1 PPL / 4 */
38 [ 4] = 1, /* CC2 PPL / 1 */
39 [ 5] = 1, /* CC2 PPL / 2 */
40 [ 6] = 1, /* CC2 PPL / 4 */
41 [ 8] = 2, /* CC3 PPL / 1 */
42 [ 9] = 2, /* CC3 PPL / 2 */
43 [10] = 2, /* CC3 PPL / 4 */
44 [12] = 3, /* CC4 PPL / 1 */
45 [13] = 3, /* CC4 PPL / 2 */
46 [14] = 3, /* CC4 PPL / 4 */
47 };
48
49 const u8 core_cplx_PLL_div[16] = {
50 [ 0] = 1, /* CC1 PPL / 1 */
51 [ 1] = 2, /* CC1 PPL / 2 */
52 [ 2] = 4, /* CC1 PPL / 4 */
53 [ 4] = 1, /* CC2 PPL / 1 */
54 [ 5] = 2, /* CC2 PPL / 2 */
55 [ 6] = 4, /* CC2 PPL / 4 */
56 [ 8] = 1, /* CC3 PPL / 1 */
57 [ 9] = 2, /* CC3 PPL / 2 */
58 [10] = 4, /* CC3 PPL / 4 */
59 [12] = 1, /* CC4 PPL / 1 */
60 [13] = 2, /* CC4 PPL / 2 */
61 [14] = 4, /* CC4 PPL / 4 */
62 };
York Sun9a653a92012-10-08 07:44:11 +000063 uint i, freqCC_PLL[6], rcw_tmp;
64 uint ratio[6];
Kumar Gala39aaca12009-03-19 02:46:19 -050065 unsigned long sysclk = CONFIG_SYS_CLK_FREQ;
Srikanth Srinivasanab48ca12010-02-10 17:32:43 +080066 uint mem_pll_rat;
Kumar Gala39aaca12009-03-19 02:46:19 -050067
68 sysInfo->freqSystemBus = sysclk;
York Sun98ffa192012-10-08 07:44:31 +000069#ifdef CONFIG_DDR_CLK_FREQ
70 sysInfo->freqDDRBus = CONFIG_DDR_CLK_FREQ;
71#else
Kumar Gala39aaca12009-03-19 02:46:19 -050072 sysInfo->freqDDRBus = sysclk;
York Sun98ffa192012-10-08 07:44:31 +000073#endif
Kumar Gala39aaca12009-03-19 02:46:19 -050074
James Yang93cedc72010-01-12 15:50:18 -060075 sysInfo->freqSystemBus *= (in_be32(&gur->rcwsr[0]) >> 25) & 0x1f;
York Sunf77329c2012-10-08 07:44:09 +000076 mem_pll_rat = (in_be32(&gur->rcwsr[0]) >>
77 FSL_CORENET_RCWSR0_MEM_PLL_RAT_SHIFT)
78 & FSL_CORENET_RCWSR0_MEM_PLL_RAT_MASK;
Srikanth Srinivasanab48ca12010-02-10 17:32:43 +080079 if (mem_pll_rat > 2)
80 sysInfo->freqDDRBus *= mem_pll_rat;
81 else
82 sysInfo->freqDDRBus = sysInfo->freqSystemBus * mem_pll_rat;
Kumar Gala39aaca12009-03-19 02:46:19 -050083
Srikanth Srinivasanab48ca12010-02-10 17:32:43 +080084 ratio[0] = (in_be32(&clk->pllc1gsr) >> 1) & 0x3f;
85 ratio[1] = (in_be32(&clk->pllc2gsr) >> 1) & 0x3f;
86 ratio[2] = (in_be32(&clk->pllc3gsr) >> 1) & 0x3f;
87 ratio[3] = (in_be32(&clk->pllc4gsr) >> 1) & 0x3f;
York Sun9a653a92012-10-08 07:44:11 +000088 ratio[4] = (in_be32(&clk->pllc5gsr) >> 1) & 0x3f;
89 ratio[5] = (in_be32(&clk->pllc6gsr) >> 1) & 0x3f;
90 for (i = 0; i < 6; i++) {
Srikanth Srinivasanab48ca12010-02-10 17:32:43 +080091 if (ratio[i] > 4)
92 freqCC_PLL[i] = sysclk * ratio[i];
93 else
94 freqCC_PLL[i] = sysInfo->freqSystemBus * ratio[i];
95 }
York Sun9a653a92012-10-08 07:44:11 +000096#ifdef CONFIG_SYS_FSL_QORIQ_CHASSIS2
97 /*
98 * Each cluster has up to 4 cores, sharing the same PLL selection.
York Sunf6981432013-03-25 07:40:07 +000099 * The cluster assignment is fixed per SoC. PLL1, PLL2, PLL3 are
100 * cluster group A, feeding cores on cluster 1 and cluster 2.
101 * PLL4, PLL5, PLL6 are cluster group B, feeding cores on cluster 3
102 * and cluster 4 if existing.
York Sun9a653a92012-10-08 07:44:11 +0000103 */
104 for_each_cpu(i, cpu, cpu_numcores(), cpu_mask()) {
York Sunf6981432013-03-25 07:40:07 +0000105 int cluster = fsl_qoriq_core_to_cluster(cpu);
106 u32 c_pll_sel = (in_be32(&clk->clkcsr[cluster].clkcncsr) >> 27)
York Sun9a653a92012-10-08 07:44:11 +0000107 & 0xf;
108 u32 cplx_pll = core_cplx_PLL[c_pll_sel];
109 if (cplx_pll > 3)
110 printf("Unsupported architecture configuration"
111 " in function %s\n", __func__);
York Sunf6981432013-03-25 07:40:07 +0000112 cplx_pll += (cluster / 2) * 3;
York Sun9a653a92012-10-08 07:44:11 +0000113 sysInfo->freqProcessor[cpu] =
114 freqCC_PLL[cplx_pll] / core_cplx_PLL_div[c_pll_sel];
115 }
Sandeep Singh0cb33252013-03-25 07:33:09 +0000116#ifdef CONFIG_PPC_B4860
117#define FM1_CLK_SEL 0xe0000000
118#define FM1_CLK_SHIFT 29
119#else
York Sun9a653a92012-10-08 07:44:11 +0000120#define PME_CLK_SEL 0xe0000000
121#define PME_CLK_SHIFT 29
122#define FM1_CLK_SEL 0x1c000000
123#define FM1_CLK_SHIFT 26
Sandeep Singh0cb33252013-03-25 07:33:09 +0000124#endif
York Sun9a653a92012-10-08 07:44:11 +0000125 rcw_tmp = in_be32(&gur->rcwsr[7]);
126
127#ifdef CONFIG_SYS_DPAA_PME
128 switch ((rcw_tmp & PME_CLK_SEL) >> PME_CLK_SHIFT) {
129 case 1:
130 sysInfo->freqPME = freqCC_PLL[0];
131 break;
132 case 2:
133 sysInfo->freqPME = freqCC_PLL[0] / 2;
134 break;
135 case 3:
136 sysInfo->freqPME = freqCC_PLL[0] / 3;
137 break;
138 case 4:
139 sysInfo->freqPME = freqCC_PLL[0] / 4;
140 break;
141 case 6:
142 sysInfo->freqPME = freqCC_PLL[1] / 2;
143 break;
144 case 7:
145 sysInfo->freqPME = freqCC_PLL[1] / 3;
146 break;
147 default:
148 printf("Error: Unknown PME clock select!\n");
149 case 0:
150 sysInfo->freqPME = sysInfo->freqSystemBus / 2;
151 break;
152
153 }
154#endif
155
Haiying Wang990e1a82012-10-11 07:13:39 +0000156#ifdef CONFIG_SYS_DPAA_QBMAN
157 sysInfo->freqQMAN = sysInfo->freqSystemBus / 2;
158#endif
159
York Sun9a653a92012-10-08 07:44:11 +0000160#ifdef CONFIG_SYS_DPAA_FMAN
161 switch ((rcw_tmp & FM1_CLK_SEL) >> FM1_CLK_SHIFT) {
162 case 1:
163 sysInfo->freqFMan[0] = freqCC_PLL[3];
164 break;
165 case 2:
166 sysInfo->freqFMan[0] = freqCC_PLL[3] / 2;
167 break;
168 case 3:
169 sysInfo->freqFMan[0] = freqCC_PLL[3] / 3;
170 break;
171 case 4:
172 sysInfo->freqFMan[0] = freqCC_PLL[3] / 4;
173 break;
Sandeep Singh0cb33252013-03-25 07:33:09 +0000174 case 5:
175 sysInfo->freqFMan[0] = sysInfo->freqSystemBus;
176 break;
York Sun9a653a92012-10-08 07:44:11 +0000177 case 6:
178 sysInfo->freqFMan[0] = freqCC_PLL[4] / 2;
179 break;
180 case 7:
181 sysInfo->freqFMan[0] = freqCC_PLL[4] / 3;
182 break;
183 default:
184 printf("Error: Unknown FMan1 clock select!\n");
185 case 0:
186 sysInfo->freqFMan[0] = sysInfo->freqSystemBus / 2;
187 break;
188 }
189#if (CONFIG_SYS_NUM_FMAN) == 2
190#define FM2_CLK_SEL 0x00000038
191#define FM2_CLK_SHIFT 3
192 rcw_tmp = in_be32(&gur->rcwsr[15]);
193 switch ((rcw_tmp & FM2_CLK_SEL) >> FM2_CLK_SHIFT) {
194 case 1:
195 sysInfo->freqFMan[1] = freqCC_PLL[4];
196 break;
197 case 2:
198 sysInfo->freqFMan[1] = freqCC_PLL[4] / 2;
199 break;
200 case 3:
201 sysInfo->freqFMan[1] = freqCC_PLL[4] / 3;
202 break;
203 case 4:
204 sysInfo->freqFMan[1] = freqCC_PLL[4] / 4;
205 break;
206 case 6:
207 sysInfo->freqFMan[1] = freqCC_PLL[3] / 2;
208 break;
209 case 7:
210 sysInfo->freqFMan[1] = freqCC_PLL[3] / 3;
211 break;
212 default:
213 printf("Error: Unknown FMan2 clock select!\n");
214 case 0:
215 sysInfo->freqFMan[1] = sysInfo->freqSystemBus / 2;
216 break;
217 }
218#endif /* CONFIG_SYS_NUM_FMAN == 2 */
219#endif /* CONFIG_SYS_DPAA_FMAN */
220
221#else /* CONFIG_SYS_FSL_QORIQ_CHASSIS2 */
222
Timur Tabifbb9ecf2011-08-05 16:15:24 -0500223 for_each_cpu(i, cpu, cpu_numcores(), cpu_mask()) {
York Sunf6981432013-03-25 07:40:07 +0000224 u32 c_pll_sel = (in_be32(&clk->clkcsr[cpu].clkcncsr) >> 27)
225 & 0xf;
Kumar Gala39aaca12009-03-19 02:46:19 -0500226 u32 cplx_pll = core_cplx_PLL[c_pll_sel];
227
Timur Tabifbb9ecf2011-08-05 16:15:24 -0500228 sysInfo->freqProcessor[cpu] =
Kumar Gala39aaca12009-03-19 02:46:19 -0500229 freqCC_PLL[cplx_pll] / core_cplx_PLL_div[c_pll_sel];
230 }
Kumar Gala39aaca12009-03-19 02:46:19 -0500231#define PME_CLK_SEL 0x80000000
232#define FM1_CLK_SEL 0x40000000
233#define FM2_CLK_SEL 0x20000000
Kumar Galab5c87532011-02-16 02:03:29 -0600234#define HWA_ASYNC_DIV 0x04000000
235#if (CONFIG_SYS_FSL_NUM_CC_PLLS == 2)
236#define HWA_CC_PLL 1
Timur Tabi49054432012-10-05 11:09:19 +0000237#elif (CONFIG_SYS_FSL_NUM_CC_PLLS == 3)
238#define HWA_CC_PLL 2
Kumar Galab5c87532011-02-16 02:03:29 -0600239#elif (CONFIG_SYS_FSL_NUM_CC_PLLS == 4)
Wolfgang Denkcd6881b2011-05-19 22:21:41 +0200240#define HWA_CC_PLL 2
Kumar Galab5c87532011-02-16 02:03:29 -0600241#else
242#error CONFIG_SYS_FSL_NUM_CC_PLLS not set or unknown case
243#endif
Kumar Gala39aaca12009-03-19 02:46:19 -0500244 rcw_tmp = in_be32(&gur->rcwsr[7]);
245
246#ifdef CONFIG_SYS_DPAA_PME
Kumar Galab5c87532011-02-16 02:03:29 -0600247 if (rcw_tmp & PME_CLK_SEL) {
248 if (rcw_tmp & HWA_ASYNC_DIV)
249 sysInfo->freqPME = freqCC_PLL[HWA_CC_PLL] / 4;
250 else
251 sysInfo->freqPME = freqCC_PLL[HWA_CC_PLL] / 2;
252 } else {
Kumar Gala693416f2010-01-25 11:01:51 -0600253 sysInfo->freqPME = sysInfo->freqSystemBus / 2;
Kumar Galab5c87532011-02-16 02:03:29 -0600254 }
Kumar Gala39aaca12009-03-19 02:46:19 -0500255#endif
256
257#ifdef CONFIG_SYS_DPAA_FMAN
Kumar Galab5c87532011-02-16 02:03:29 -0600258 if (rcw_tmp & FM1_CLK_SEL) {
259 if (rcw_tmp & HWA_ASYNC_DIV)
260 sysInfo->freqFMan[0] = freqCC_PLL[HWA_CC_PLL] / 4;
261 else
262 sysInfo->freqFMan[0] = freqCC_PLL[HWA_CC_PLL] / 2;
263 } else {
Kumar Gala693416f2010-01-25 11:01:51 -0600264 sysInfo->freqFMan[0] = sysInfo->freqSystemBus / 2;
Kumar Galab5c87532011-02-16 02:03:29 -0600265 }
Kumar Gala39aaca12009-03-19 02:46:19 -0500266#if (CONFIG_SYS_NUM_FMAN) == 2
Kumar Galab5c87532011-02-16 02:03:29 -0600267 if (rcw_tmp & FM2_CLK_SEL) {
268 if (rcw_tmp & HWA_ASYNC_DIV)
269 sysInfo->freqFMan[1] = freqCC_PLL[HWA_CC_PLL] / 4;
270 else
271 sysInfo->freqFMan[1] = freqCC_PLL[HWA_CC_PLL] / 2;
272 } else {
Kumar Gala693416f2010-01-25 11:01:51 -0600273 sysInfo->freqFMan[1] = sysInfo->freqSystemBus / 2;
Kumar Galab5c87532011-02-16 02:03:29 -0600274 }
Kumar Gala39aaca12009-03-19 02:46:19 -0500275#endif
276#endif
277
Shaohui Xie3e83fc92013-03-25 07:33:25 +0000278#ifdef CONFIG_SYS_DPAA_QBMAN
279 sysInfo->freqQMAN = sysInfo->freqSystemBus / 2;
280#endif
281
York Sun9a653a92012-10-08 07:44:11 +0000282#endif /* CONFIG_SYS_FSL_QORIQ_CHASSIS2 */
283
284#else /* CONFIG_FSL_CORENET */
285 uint plat_ratio, e500_ratio, half_freqSystemBus;
Haiying Wang2fc7eb02009-01-15 11:58:35 -0500286 int i;
Haiying Wangb3d7f202009-05-20 12:30:29 -0400287#ifdef CONFIG_QE
Haiying Wanga52d2f82011-02-11 01:25:30 -0600288 __maybe_unused u32 qe_ratio;
Haiying Wangb3d7f202009-05-20 12:30:29 -0400289#endif
wdenk42d1f032003-10-15 23:53:47 +0000290
291 plat_ratio = (gur->porpllsr) & 0x0000003e;
292 plat_ratio >>= 1;
Andy Fleming66ed6cc2007-04-23 02:37:47 -0500293 sysInfo->freqSystemBus = plat_ratio * CONFIG_SYS_CLK_FREQ;
Andy Fleming66ed6cc2007-04-23 02:37:47 -0500294
295 /* Divide before multiply to avoid integer
296 * overflow for processor speeds above 2GHz */
297 half_freqSystemBus = sysInfo->freqSystemBus/2;
Poonam Aggrwal0e870982009-07-31 12:08:14 +0530298 for (i = 0; i < cpu_numcores(); i++) {
Haiying Wang2fc7eb02009-01-15 11:58:35 -0500299 e500_ratio = ((gur->porpllsr) >> (i * 8 + 16)) & 0x3f;
300 sysInfo->freqProcessor[i] = e500_ratio * half_freqSystemBus;
301 }
James Yanga3e77fa2008-02-08 18:05:08 -0600302
303 /* Note: freqDDRBus is the MCLK frequency, not the data rate. */
Kumar Galad4357932007-12-07 04:59:26 -0600304 sysInfo->freqDDRBus = sysInfo->freqSystemBus;
305
306#ifdef CONFIG_DDR_CLK_FREQ
307 {
Jason Jinc0391112008-09-27 14:40:57 +0800308 u32 ddr_ratio = ((gur->porpllsr) & MPC85xx_PORPLLSR_DDR_RATIO)
309 >> MPC85xx_PORPLLSR_DDR_RATIO_SHIFT;
Kumar Galad4357932007-12-07 04:59:26 -0600310 if (ddr_ratio != 0x7)
311 sysInfo->freqDDRBus = ddr_ratio * CONFIG_DDR_CLK_FREQ;
312 }
313#endif
Trent Piephoada591d2008-12-03 15:16:37 -0800314
Haiying Wangb3d7f202009-05-20 12:30:29 -0400315#ifdef CONFIG_QE
York Sunbe7bebe2012-08-10 11:07:26 +0000316#if defined(CONFIG_P1012) || defined(CONFIG_P1021) || defined(CONFIG_P1025)
Haiying Wanga52d2f82011-02-11 01:25:30 -0600317 sysInfo->freqQE = sysInfo->freqSystemBus;
318#else
Haiying Wangb3d7f202009-05-20 12:30:29 -0400319 qe_ratio = ((gur->porpllsr) & MPC85xx_PORPLLSR_QE_RATIO)
320 >> MPC85xx_PORPLLSR_QE_RATIO_SHIFT;
321 sysInfo->freqQE = qe_ratio * CONFIG_SYS_CLK_FREQ;
322#endif
Haiying Wanga52d2f82011-02-11 01:25:30 -0600323#endif
Haiying Wangb3d7f202009-05-20 12:30:29 -0400324
Haiying Wang24995d82011-01-20 22:26:31 +0000325#ifdef CONFIG_SYS_DPAA_FMAN
Kumar Gala939cdcd2011-03-10 06:09:20 -0600326 sysInfo->freqFMan[0] = sysInfo->freqSystemBus;
Haiying Wang24995d82011-01-20 22:26:31 +0000327#endif
328
329#endif /* CONFIG_FSL_CORENET */
330
Dipen Dudhatbeba93e2011-01-19 12:46:27 +0530331#if defined(CONFIG_FSL_LBC)
York Sun9a653a92012-10-08 07:44:11 +0000332 uint lcrr_div;
Trent Piephoada591d2008-12-03 15:16:37 -0800333#if defined(CONFIG_SYS_LBC_LCRR)
334 /* We will program LCRR to this value later */
335 lcrr_div = CONFIG_SYS_LBC_LCRR & LCRR_CLKDIV;
336#else
Becky Brucef51cdaf2010-06-17 11:37:20 -0500337 lcrr_div = in_be32(&(LBC_BASE_ADDR)->lcrr) & LCRR_CLKDIV;
Trent Piephoada591d2008-12-03 15:16:37 -0800338#endif
339 if (lcrr_div == 2 || lcrr_div == 4 || lcrr_div == 8) {
Dave Liu0fd2fa62009-11-17 20:49:05 +0800340#if defined(CONFIG_FSL_CORENET)
341 /* If this is corenet based SoC, bit-representation
342 * for four times the clock divider values.
343 */
344 lcrr_div *= 4;
345#elif !defined(CONFIG_MPC8540) && !defined(CONFIG_MPC8541) && \
Trent Piephoada591d2008-12-03 15:16:37 -0800346 !defined(CONFIG_MPC8555) && !defined(CONFIG_MPC8560)
347 /*
348 * Yes, the entire PQ38 family use the same
349 * bit-representation for twice the clock divider values.
350 */
351 lcrr_div *= 2;
352#endif
353 sysInfo->freqLocalBus = sysInfo->freqSystemBus / lcrr_div;
354 } else {
355 /* In case anyone cares what the unknown value is */
356 sysInfo->freqLocalBus = lcrr_div;
357 }
Dipen Dudhatbeba93e2011-01-19 12:46:27 +0530358#endif
Kumar Gala800c73c2012-10-08 07:44:06 +0000359
360#if defined(CONFIG_FSL_IFC)
361 ccr = in_be32(&ifc_regs->ifc_ccr);
362 ccr = ((ccr & IFC_CCR_CLK_DIV_MASK) >> IFC_CCR_CLK_DIV_SHIFT) + 1;
363
364 sysInfo->freqLocalBus = sysInfo->freqSystemBus / ccr;
365#endif
wdenk42d1f032003-10-15 23:53:47 +0000366}
367
Andy Fleming66ed6cc2007-04-23 02:37:47 -0500368
wdenk42d1f032003-10-15 23:53:47 +0000369int get_clocks (void)
370{
wdenk42d1f032003-10-15 23:53:47 +0000371 sys_info_t sys_info;
Timur Tabi88353a92008-04-04 11:15:58 -0500372#ifdef CONFIG_MPC8544
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200373 volatile ccsr_gur_t *gur = (void *) CONFIG_SYS_MPC85xx_GUTS_ADDR;
Timur Tabi88353a92008-04-04 11:15:58 -0500374#endif
Jon Loeliger9c4c5ae2005-07-23 10:37:35 -0500375#if defined(CONFIG_CPM2)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200376 volatile ccsr_cpm_t *cpm = (ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR;
wdenk42d1f032003-10-15 23:53:47 +0000377 uint sccr, dfbrg;
378
379 /* set VCO = 4 * BRG */
Kumar Galaaafeefb2007-11-28 00:36:33 -0600380 cpm->im_cpm_intctl.sccr &= 0xfffffffc;
381 sccr = cpm->im_cpm_intctl.sccr;
wdenk42d1f032003-10-15 23:53:47 +0000382 dfbrg = (sccr & SCCR_DFBRG_MSK) >> SCCR_DFBRG_SHIFT;
383#endif
384 get_sys_info (&sys_info);
Haiying Wang2fc7eb02009-01-15 11:58:35 -0500385 gd->cpu_clk = sys_info.freqProcessor[0];
wdenk42d1f032003-10-15 23:53:47 +0000386 gd->bus_clk = sys_info.freqSystemBus;
James Yanga3e77fa2008-02-08 18:05:08 -0600387 gd->mem_clk = sys_info.freqDDRBus;
Simon Glass67ac13b2012-12-13 20:48:48 +0000388 gd->arch.lbc_clk = sys_info.freqLocalBus;
Timur Tabi88353a92008-04-04 11:15:58 -0500389
Haiying Wangb3d7f202009-05-20 12:30:29 -0400390#ifdef CONFIG_QE
Simon Glass45bae2e2012-12-13 20:48:50 +0000391 gd->arch.qe_clk = sys_info.freqQE;
392 gd->arch.brg_clk = gd->arch.qe_clk / 2;
Haiying Wangb3d7f202009-05-20 12:30:29 -0400393#endif
Timur Tabi88353a92008-04-04 11:15:58 -0500394 /*
395 * The base clock for I2C depends on the actual SOC. Unfortunately,
396 * there is no pattern that can be used to determine the frequency, so
397 * the only choice is to look up the actual SOC number and use the value
398 * for that SOC. This information is taken from application note
399 * AN2919.
400 */
401#if defined(CONFIG_MPC8540) || defined(CONFIG_MPC8541) || \
402 defined(CONFIG_MPC8560) || defined(CONFIG_MPC8555)
Simon Glass609e6ec2012-12-13 20:48:49 +0000403 gd->arch.i2c1_clk = sys_info.freqSystemBus;
Timur Tabi88353a92008-04-04 11:15:58 -0500404#elif defined(CONFIG_MPC8544)
405 /*
406 * On the 8544, the I2C clock is the same as the SEC clock. This can be
407 * either CCB/2 or CCB/3, depending on the value of cfg_sec_freq. See
408 * 4.4.3.3 of the 8544 RM. Note that this might actually work for all
409 * 85xx, but only the 8544 has cfg_sec_freq, so it's unknown if the
410 * PORDEVSR2_SEC_CFG bit is 0 on all 85xx boards that are not an 8544.
411 */
412 if (gur->pordevsr2 & MPC85xx_PORDEVSR2_SEC_CFG)
Simon Glass609e6ec2012-12-13 20:48:49 +0000413 gd->arch.i2c1_clk = sys_info.freqSystemBus / 3;
Kumar Gala42653b82008-10-16 21:58:49 -0500414 else
Simon Glass609e6ec2012-12-13 20:48:49 +0000415 gd->arch.i2c1_clk = sys_info.freqSystemBus / 2;
Timur Tabi88353a92008-04-04 11:15:58 -0500416#else
417 /* Most 85xx SOCs use CCB/2, so this is the default behavior. */
Simon Glass609e6ec2012-12-13 20:48:49 +0000418 gd->arch.i2c1_clk = sys_info.freqSystemBus / 2;
Timur Tabi88353a92008-04-04 11:15:58 -0500419#endif
Simon Glass609e6ec2012-12-13 20:48:49 +0000420 gd->arch.i2c2_clk = gd->arch.i2c1_clk;
Timur Tabi943afa22008-01-09 14:35:26 -0600421
Dipen Dudhat6b9ea082009-09-01 17:27:00 +0530422#if defined(CONFIG_FSL_ESDHC)
Priyanka Jain7d640e92011-02-08 15:45:25 +0530423#if defined(CONFIG_MPC8569) || defined(CONFIG_P1010) ||\
424 defined(CONFIG_P1014)
Simon Glasse9adeca2012-12-13 20:49:05 +0000425 gd->arch.sdhc_clk = gd->bus_clk;
Anton Vorontsov7f52ed52009-10-15 17:47:06 +0400426#else
Simon Glasse9adeca2012-12-13 20:49:05 +0000427 gd->arch.sdhc_clk = gd->bus_clk / 2;
Kumar Galaef50d6c2008-08-12 11:14:19 -0500428#endif
Anton Vorontsov7f52ed52009-10-15 17:47:06 +0400429#endif /* defined(CONFIG_FSL_ESDHC) */
Kumar Galaef50d6c2008-08-12 11:14:19 -0500430
Jon Loeliger9c4c5ae2005-07-23 10:37:35 -0500431#if defined(CONFIG_CPM2)
Simon Glass748cd052012-12-13 20:48:46 +0000432 gd->arch.vco_out = 2*sys_info.freqSystemBus;
433 gd->arch.cpm_clk = gd->arch.vco_out / 2;
434 gd->arch.scc_clk = gd->arch.vco_out / 4;
435 gd->arch.brg_clk = gd->arch.vco_out / (1 << (2 * (dfbrg + 1)));
wdenk42d1f032003-10-15 23:53:47 +0000436#endif
437
438 if(gd->cpu_clk != 0) return (0);
439 else return (1);
440}
441
442
443/********************************************
444 * get_bus_freq
445 * return system bus freq in Hz
446 *********************************************/
447ulong get_bus_freq (ulong dummy)
448{
James Yanga3e77fa2008-02-08 18:05:08 -0600449 return gd->bus_clk;
wdenk42d1f032003-10-15 23:53:47 +0000450}
Kumar Galad4357932007-12-07 04:59:26 -0600451
452/********************************************
453 * get_ddr_freq
454 * return ddr bus freq in Hz
455 *********************************************/
456ulong get_ddr_freq (ulong dummy)
457{
James Yanga3e77fa2008-02-08 18:05:08 -0600458 return gd->mem_clk;
Kumar Galad4357932007-12-07 04:59:26 -0600459}