2 * Copyright 2004, 2007-2011 Freescale Semiconductor, Inc.
4 * (C) Copyright 2003 Motorola Inc.
5 * Xianghua Xiao, (X.Xiao@motorola.com)
8 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
10 * SPDX-License-Identifier: GPL-2.0+
14 #include <ppc_asm.tmpl>
15 #include <linux/compiler.h>
16 #include <asm/processor.h>
19 DECLARE_GLOBAL_DATA_PTR;
22 #ifndef CONFIG_SYS_FSL_NUM_CC_PLLS
23 #define CONFIG_SYS_FSL_NUM_CC_PLLS 6
25 /* --------------------------------------------------------------- */
27 void get_sys_info(sys_info_t *sys_info)
29 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
31 struct fsl_ifc *ifc_regs = (void *)CONFIG_SYS_IFC_ADDR;
34 #ifdef CONFIG_FSL_CORENET
35 volatile ccsr_clk_t *clk = (void *)(CONFIG_SYS_FSL_CORENET_CLK_ADDR);
37 #ifdef CONFIG_SYS_FSL_QORIQ_CHASSIS2
38 int cc_group[12] = CONFIG_SYS_FSL_CLUSTER_CLOCKS;
41 const u8 core_cplx_PLL[16] = {
42 [ 0] = 0, /* CC1 PPL / 1 */
43 [ 1] = 0, /* CC1 PPL / 2 */
44 [ 2] = 0, /* CC1 PPL / 4 */
45 [ 4] = 1, /* CC2 PPL / 1 */
46 [ 5] = 1, /* CC2 PPL / 2 */
47 [ 6] = 1, /* CC2 PPL / 4 */
48 [ 8] = 2, /* CC3 PPL / 1 */
49 [ 9] = 2, /* CC3 PPL / 2 */
50 [10] = 2, /* CC3 PPL / 4 */
51 [12] = 3, /* CC4 PPL / 1 */
52 [13] = 3, /* CC4 PPL / 2 */
53 [14] = 3, /* CC4 PPL / 4 */
56 const u8 core_cplx_pll_div[16] = {
57 [ 0] = 1, /* CC1 PPL / 1 */
58 [ 1] = 2, /* CC1 PPL / 2 */
59 [ 2] = 4, /* CC1 PPL / 4 */
60 [ 4] = 1, /* CC2 PPL / 1 */
61 [ 5] = 2, /* CC2 PPL / 2 */
62 [ 6] = 4, /* CC2 PPL / 4 */
63 [ 8] = 1, /* CC3 PPL / 1 */
64 [ 9] = 2, /* CC3 PPL / 2 */
65 [10] = 4, /* CC3 PPL / 4 */
66 [12] = 1, /* CC4 PPL / 1 */
67 [13] = 2, /* CC4 PPL / 2 */
68 [14] = 4, /* CC4 PPL / 4 */
70 uint i, freq_c_pll[CONFIG_SYS_FSL_NUM_CC_PLLS];
71 #if !defined(CONFIG_FM_PLAT_CLK_DIV) || !defined(CONFIG_PME_PLAT_CLK_DIV)
74 uint ratio[CONFIG_SYS_FSL_NUM_CC_PLLS];
75 unsigned long sysclk = CONFIG_SYS_CLK_FREQ;
78 sys_info->freq_systembus = sysclk;
79 #ifdef CONFIG_SYS_FSL_SINGLE_SOURCE_CLK
81 unsigned int porsr1_sys_clk;
82 porsr1_sys_clk = in_be32(&gur->porsr1) >> FSL_DCFG_PORSR1_SYSCLK_SHIFT
83 & FSL_DCFG_PORSR1_SYSCLK_MASK;
84 if (porsr1_sys_clk == FSL_DCFG_PORSR1_SYSCLK_DIFF)
85 sys_info->diff_sysclk = 1;
87 sys_info->diff_sysclk = 0;
90 * DDR_REFCLK_SEL rcw bit is used to determine if DDR PLLS
91 * are driven by separate DDR Refclock or single source
94 ddr_refclk_sel = (in_be32(&gur->rcwsr[5]) >>
95 FSL_CORENET2_RCWSR5_DDR_REFCLK_SEL_SHIFT) &
96 FSL_CORENET2_RCWSR5_DDR_REFCLK_SEL_MASK;
98 * For single source clocking, both ddrclock and sysclock
99 * are driven by differential sysclock.
101 if (ddr_refclk_sel == FSL_CORENET2_RCWSR5_DDR_REFCLK_SINGLE_CLK)
102 sys_info->freq_ddrbus = CONFIG_SYS_CLK_FREQ;
105 #ifdef CONFIG_DDR_CLK_FREQ
106 sys_info->freq_ddrbus = CONFIG_DDR_CLK_FREQ;
108 sys_info->freq_ddrbus = sysclk;
111 sys_info->freq_systembus *= (in_be32(&gur->rcwsr[0]) >> 25) & 0x1f;
112 mem_pll_rat = (in_be32(&gur->rcwsr[0]) >>
113 FSL_CORENET_RCWSR0_MEM_PLL_RAT_SHIFT)
114 & FSL_CORENET_RCWSR0_MEM_PLL_RAT_MASK;
115 #ifdef CONFIG_SYS_FSL_ERRATUM_A007212
116 if (mem_pll_rat == 0) {
117 mem_pll_rat = (in_be32(&gur->rcwsr[0]) >>
118 FSL_CORENET_RCWSR0_MEM_PLL_RAT_RESV_SHIFT) &
119 FSL_CORENET_RCWSR0_MEM_PLL_RAT_MASK;
122 /* T4240/T4160 Rev2.0 MEM_PLL_RAT uses a value which is half of
123 * T4240/T4160 Rev1.0. eg. It's 12 in Rev1.0, however, for Rev2.0
126 #if defined(CONFIG_PPC_T4240) || defined(CONFIG_PPC_T4160) || \
127 defined(CONFIG_PPC_T4080)
128 if (SVR_MAJ(get_svr()) >= 2)
132 sys_info->freq_ddrbus *= mem_pll_rat;
134 sys_info->freq_ddrbus = sys_info->freq_systembus * mem_pll_rat;
136 for (i = 0; i < CONFIG_SYS_FSL_NUM_CC_PLLS; i++) {
137 ratio[i] = (in_be32(&clk->pllcgsr[i].pllcngsr) >> 1) & 0x3f;
139 freq_c_pll[i] = sysclk * ratio[i];
141 freq_c_pll[i] = sys_info->freq_systembus * ratio[i];
143 #ifdef CONFIG_SYS_FSL_QORIQ_CHASSIS2
145 * As per CHASSIS2 architeture total 12 clusters are posible and
146 * Each cluster has up to 4 cores, sharing the same PLL selection.
147 * The cluster clock assignment is SoC defined.
149 * Total 4 clock groups are possible with 3 PLLs each.
150 * as per array indices, clock group A has 0, 1, 2 numbered PLLs &
151 * clock group B has 3, 4, 6 and so on.
153 * Clock group A having PLL1, PLL2, PLL3, feeding cores of any cluster
154 * depends upon the SoC architeture. Same applies to other
155 * clock groups and clusters.
158 for_each_cpu(i, cpu, cpu_numcores(), cpu_mask()) {
159 int cluster = fsl_qoriq_core_to_cluster(cpu);
160 u32 c_pll_sel = (in_be32(&clk->clkcsr[cluster].clkcncsr) >> 27)
162 u32 cplx_pll = core_cplx_PLL[c_pll_sel];
163 cplx_pll += cc_group[cluster] - 1;
164 sys_info->freq_processor[cpu] =
165 freq_c_pll[cplx_pll] / core_cplx_pll_div[c_pll_sel];
167 #if defined(CONFIG_PPC_B4860) || defined(CONFIG_PPC_B4420) || \
168 defined(CONFIG_PPC_T2080) || defined(CONFIG_PPC_T2081)
169 #define FM1_CLK_SEL 0xe0000000
170 #define FM1_CLK_SHIFT 29
172 #define PME_CLK_SEL 0xe0000000
173 #define PME_CLK_SHIFT 29
174 #define FM1_CLK_SEL 0x1c000000
175 #define FM1_CLK_SHIFT 26
177 #if !defined(CONFIG_FM_PLAT_CLK_DIV) || !defined(CONFIG_PME_PLAT_CLK_DIV)
178 rcw_tmp = in_be32(&gur->rcwsr[7]);
181 #ifdef CONFIG_SYS_DPAA_PME
182 #ifndef CONFIG_PME_PLAT_CLK_DIV
183 switch ((rcw_tmp & PME_CLK_SEL) >> PME_CLK_SHIFT) {
185 sys_info->freq_pme = freq_c_pll[CONFIG_SYS_PME_CLK];
188 sys_info->freq_pme = freq_c_pll[CONFIG_SYS_PME_CLK] / 2;
191 sys_info->freq_pme = freq_c_pll[CONFIG_SYS_PME_CLK] / 3;
194 sys_info->freq_pme = freq_c_pll[CONFIG_SYS_PME_CLK] / 4;
197 sys_info->freq_pme = freq_c_pll[CONFIG_SYS_PME_CLK + 1] / 2;
200 sys_info->freq_pme = freq_c_pll[CONFIG_SYS_PME_CLK + 1] / 3;
203 printf("Error: Unknown PME clock select!\n");
205 sys_info->freq_pme = sys_info->freq_systembus / 2;
210 sys_info->freq_pme = sys_info->freq_systembus / CONFIG_SYS_PME_CLK;
215 #ifdef CONFIG_SYS_DPAA_QBMAN
216 sys_info->freq_qman = sys_info->freq_systembus / 2;
219 #ifdef CONFIG_SYS_DPAA_FMAN
220 #ifndef CONFIG_FM_PLAT_CLK_DIV
221 switch ((rcw_tmp & FM1_CLK_SEL) >> FM1_CLK_SHIFT) {
223 sys_info->freq_fman[0] = freq_c_pll[CONFIG_SYS_FM1_CLK];
226 sys_info->freq_fman[0] = freq_c_pll[CONFIG_SYS_FM1_CLK] / 2;
229 sys_info->freq_fman[0] = freq_c_pll[CONFIG_SYS_FM1_CLK] / 3;
232 sys_info->freq_fman[0] = freq_c_pll[CONFIG_SYS_FM1_CLK] / 4;
235 sys_info->freq_fman[0] = sys_info->freq_systembus;
238 sys_info->freq_fman[0] = freq_c_pll[CONFIG_SYS_FM1_CLK + 1] / 2;
241 sys_info->freq_fman[0] = freq_c_pll[CONFIG_SYS_FM1_CLK + 1] / 3;
244 printf("Error: Unknown FMan1 clock select!\n");
246 sys_info->freq_fman[0] = sys_info->freq_systembus / 2;
249 #if (CONFIG_SYS_NUM_FMAN) == 2
250 #ifdef CONFIG_SYS_FM2_CLK
251 #define FM2_CLK_SEL 0x00000038
252 #define FM2_CLK_SHIFT 3
253 rcw_tmp = in_be32(&gur->rcwsr[15]);
254 switch ((rcw_tmp & FM2_CLK_SEL) >> FM2_CLK_SHIFT) {
256 sys_info->freq_fman[1] = freq_c_pll[CONFIG_SYS_FM2_CLK + 1];
259 sys_info->freq_fman[1] = freq_c_pll[CONFIG_SYS_FM2_CLK + 1] / 2;
262 sys_info->freq_fman[1] = freq_c_pll[CONFIG_SYS_FM2_CLK + 1] / 3;
265 sys_info->freq_fman[1] = freq_c_pll[CONFIG_SYS_FM2_CLK + 1] / 4;
268 sys_info->freq_fman[1] = sys_info->freq_systembus;
271 sys_info->freq_fman[1] = freq_c_pll[CONFIG_SYS_FM2_CLK] / 2;
274 sys_info->freq_fman[1] = freq_c_pll[CONFIG_SYS_FM2_CLK] / 3;
277 printf("Error: Unknown FMan2 clock select!\n");
279 sys_info->freq_fman[1] = sys_info->freq_systembus / 2;
283 #endif /* CONFIG_SYS_NUM_FMAN == 2 */
285 sys_info->freq_fman[0] = sys_info->freq_systembus / CONFIG_SYS_FM1_CLK;
289 #else /* CONFIG_SYS_FSL_QORIQ_CHASSIS2 */
291 for_each_cpu(i, cpu, cpu_numcores(), cpu_mask()) {
292 u32 c_pll_sel = (in_be32(&clk->clkcsr[cpu].clkcncsr) >> 27)
294 u32 cplx_pll = core_cplx_PLL[c_pll_sel];
296 sys_info->freq_processor[cpu] =
297 freq_c_pll[cplx_pll] / core_cplx_pll_div[c_pll_sel];
299 #define PME_CLK_SEL 0x80000000
300 #define FM1_CLK_SEL 0x40000000
301 #define FM2_CLK_SEL 0x20000000
302 #define HWA_ASYNC_DIV 0x04000000
303 #if (CONFIG_SYS_FSL_NUM_CC_PLLS == 2)
305 #elif (CONFIG_SYS_FSL_NUM_CC_PLLS == 3)
307 #elif (CONFIG_SYS_FSL_NUM_CC_PLLS == 4)
310 #error CONFIG_SYS_FSL_NUM_CC_PLLS not set or unknown case
312 rcw_tmp = in_be32(&gur->rcwsr[7]);
314 #ifdef CONFIG_SYS_DPAA_PME
315 if (rcw_tmp & PME_CLK_SEL) {
316 if (rcw_tmp & HWA_ASYNC_DIV)
317 sys_info->freq_pme = freq_c_pll[HWA_CC_PLL] / 4;
319 sys_info->freq_pme = freq_c_pll[HWA_CC_PLL] / 2;
321 sys_info->freq_pme = sys_info->freq_systembus / 2;
325 #ifdef CONFIG_SYS_DPAA_FMAN
326 if (rcw_tmp & FM1_CLK_SEL) {
327 if (rcw_tmp & HWA_ASYNC_DIV)
328 sys_info->freq_fman[0] = freq_c_pll[HWA_CC_PLL] / 4;
330 sys_info->freq_fman[0] = freq_c_pll[HWA_CC_PLL] / 2;
332 sys_info->freq_fman[0] = sys_info->freq_systembus / 2;
334 #if (CONFIG_SYS_NUM_FMAN) == 2
335 if (rcw_tmp & FM2_CLK_SEL) {
336 if (rcw_tmp & HWA_ASYNC_DIV)
337 sys_info->freq_fman[1] = freq_c_pll[HWA_CC_PLL] / 4;
339 sys_info->freq_fman[1] = freq_c_pll[HWA_CC_PLL] / 2;
341 sys_info->freq_fman[1] = sys_info->freq_systembus / 2;
346 #ifdef CONFIG_SYS_DPAA_QBMAN
347 sys_info->freq_qman = sys_info->freq_systembus / 2;
350 #endif /* CONFIG_SYS_FSL_QORIQ_CHASSIS2 */
353 sys_info->freq_qe = sys_info->freq_systembus / 2;
356 #else /* CONFIG_FSL_CORENET */
357 uint plat_ratio, e500_ratio, half_freq_systembus;
360 __maybe_unused u32 qe_ratio;
363 plat_ratio = (gur->porpllsr) & 0x0000003e;
365 sys_info->freq_systembus = plat_ratio * CONFIG_SYS_CLK_FREQ;
367 /* Divide before multiply to avoid integer
368 * overflow for processor speeds above 2GHz */
369 half_freq_systembus = sys_info->freq_systembus/2;
370 for (i = 0; i < cpu_numcores(); i++) {
371 e500_ratio = ((gur->porpllsr) >> (i * 8 + 16)) & 0x3f;
372 sys_info->freq_processor[i] = e500_ratio * half_freq_systembus;
375 /* Note: freq_ddrbus is the MCLK frequency, not the data rate. */
376 sys_info->freq_ddrbus = sys_info->freq_systembus;
378 #ifdef CONFIG_DDR_CLK_FREQ
380 u32 ddr_ratio = ((gur->porpllsr) & MPC85xx_PORPLLSR_DDR_RATIO)
381 >> MPC85xx_PORPLLSR_DDR_RATIO_SHIFT;
382 if (ddr_ratio != 0x7)
383 sys_info->freq_ddrbus = ddr_ratio * CONFIG_DDR_CLK_FREQ;
388 #if defined(CONFIG_P1012) || defined(CONFIG_P1021) || defined(CONFIG_P1025)
389 sys_info->freq_qe = sys_info->freq_systembus;
391 qe_ratio = ((gur->porpllsr) & MPC85xx_PORPLLSR_QE_RATIO)
392 >> MPC85xx_PORPLLSR_QE_RATIO_SHIFT;
393 sys_info->freq_qe = qe_ratio * CONFIG_SYS_CLK_FREQ;
397 #ifdef CONFIG_SYS_DPAA_FMAN
398 sys_info->freq_fman[0] = sys_info->freq_systembus;
401 #endif /* CONFIG_FSL_CORENET */
403 #if defined(CONFIG_FSL_LBC)
405 #if defined(CONFIG_SYS_LBC_LCRR)
406 /* We will program LCRR to this value later */
407 lcrr_div = CONFIG_SYS_LBC_LCRR & LCRR_CLKDIV;
409 lcrr_div = in_be32(&(LBC_BASE_ADDR)->lcrr) & LCRR_CLKDIV;
411 if (lcrr_div == 2 || lcrr_div == 4 || lcrr_div == 8) {
412 #if defined(CONFIG_FSL_CORENET)
413 /* If this is corenet based SoC, bit-representation
414 * for four times the clock divider values.
417 #elif !defined(CONFIG_MPC8540) && !defined(CONFIG_MPC8541) && \
418 !defined(CONFIG_MPC8555) && !defined(CONFIG_MPC8560)
420 * Yes, the entire PQ38 family use the same
421 * bit-representation for twice the clock divider values.
425 sys_info->freq_localbus = sys_info->freq_systembus / lcrr_div;
427 /* In case anyone cares what the unknown value is */
428 sys_info->freq_localbus = lcrr_div;
432 #if defined(CONFIG_FSL_IFC)
433 ccr = in_be32(&ifc_regs->ifc_ccr);
434 ccr = ((ccr & IFC_CCR_CLK_DIV_MASK) >> IFC_CCR_CLK_DIV_SHIFT) + 1;
436 sys_info->freq_localbus = sys_info->freq_systembus / ccr;
441 int get_clocks (void)
444 #ifdef CONFIG_MPC8544
445 volatile ccsr_gur_t *gur = (void *) CONFIG_SYS_MPC85xx_GUTS_ADDR;
447 #if defined(CONFIG_CPM2)
448 volatile ccsr_cpm_t *cpm = (ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR;
451 /* set VCO = 4 * BRG */
452 cpm->im_cpm_intctl.sccr &= 0xfffffffc;
453 sccr = cpm->im_cpm_intctl.sccr;
454 dfbrg = (sccr & SCCR_DFBRG_MSK) >> SCCR_DFBRG_SHIFT;
456 get_sys_info (&sys_info);
457 gd->cpu_clk = sys_info.freq_processor[0];
458 gd->bus_clk = sys_info.freq_systembus;
459 gd->mem_clk = sys_info.freq_ddrbus;
460 gd->arch.lbc_clk = sys_info.freq_localbus;
463 gd->arch.qe_clk = sys_info.freq_qe;
464 gd->arch.brg_clk = gd->arch.qe_clk / 2;
467 * The base clock for I2C depends on the actual SOC. Unfortunately,
468 * there is no pattern that can be used to determine the frequency, so
469 * the only choice is to look up the actual SOC number and use the value
470 * for that SOC. This information is taken from application note
473 #if defined(CONFIG_MPC8540) || defined(CONFIG_MPC8541) || \
474 defined(CONFIG_MPC8560) || defined(CONFIG_MPC8555) || \
475 defined(CONFIG_P1022)
476 gd->arch.i2c1_clk = sys_info.freq_systembus;
477 #elif defined(CONFIG_MPC8544)
479 * On the 8544, the I2C clock is the same as the SEC clock. This can be
480 * either CCB/2 or CCB/3, depending on the value of cfg_sec_freq. See
481 * 4.4.3.3 of the 8544 RM. Note that this might actually work for all
482 * 85xx, but only the 8544 has cfg_sec_freq, so it's unknown if the
483 * PORDEVSR2_SEC_CFG bit is 0 on all 85xx boards that are not an 8544.
485 if (gur->pordevsr2 & MPC85xx_PORDEVSR2_SEC_CFG)
486 gd->arch.i2c1_clk = sys_info.freq_systembus / 3;
488 gd->arch.i2c1_clk = sys_info.freq_systembus / 2;
490 /* Most 85xx SOCs use CCB/2, so this is the default behavior. */
491 gd->arch.i2c1_clk = sys_info.freq_systembus / 2;
493 gd->arch.i2c2_clk = gd->arch.i2c1_clk;
495 #if defined(CONFIG_FSL_ESDHC)
496 #if defined(CONFIG_MPC8569) || defined(CONFIG_P1010) ||\
497 defined(CONFIG_P1014)
498 gd->arch.sdhc_clk = gd->bus_clk;
500 gd->arch.sdhc_clk = gd->bus_clk / 2;
502 #endif /* defined(CONFIG_FSL_ESDHC) */
504 #if defined(CONFIG_CPM2)
505 gd->arch.vco_out = 2*sys_info.freq_systembus;
506 gd->arch.cpm_clk = gd->arch.vco_out / 2;
507 gd->arch.scc_clk = gd->arch.vco_out / 4;
508 gd->arch.brg_clk = gd->arch.vco_out / (1 << (2 * (dfbrg + 1)));
511 if(gd->cpu_clk != 0) return (0);
516 /********************************************
518 * return system bus freq in Hz
519 *********************************************/
520 ulong get_bus_freq (ulong dummy)
525 /********************************************
527 * return ddr bus freq in Hz
528 *********************************************/
529 ulong get_ddr_freq (ulong dummy)