blob: 3236f6a5da6b577af94441996a89127e1ddeac81 [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
Kumar Gala39aaca12009-03-19 02:46:19 -050040
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 */
54 };
55
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +053056 const u8 core_cplx_pll_div[16] = {
Kumar Gala39aaca12009-03-19 02:46:19 -050057 [ 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 */
69 };
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +053070 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)
72 uint rcw_tmp;
73#endif
74 uint ratio[CONFIG_SYS_FSL_NUM_CC_PLLS];
Kumar Gala39aaca12009-03-19 02:46:19 -050075 unsigned long sysclk = CONFIG_SYS_CLK_FREQ;
Srikanth Srinivasanab48ca12010-02-10 17:32:43 +080076 uint mem_pll_rat;
Kumar Gala39aaca12009-03-19 02:46:19 -050077
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +053078 sys_info->freq_systembus = sysclk;
Priyanka Jainb1359912013-12-17 14:25:52 +053079#ifdef CONFIG_SYS_FSL_SINGLE_SOURCE_CLK
vijay rai0c12a152014-04-15 11:34:12 +053080 uint ddr_refclk_sel;
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;
86 else
87 sys_info->diff_sysclk = 0;
88
Priyanka Jainb1359912013-12-17 14:25:52 +053089 /*
90 * DDR_REFCLK_SEL rcw bit is used to determine if DDR PLLS
91 * are driven by separate DDR Refclock or single source
92 * differential clock.
93 */
vijay rai0c12a152014-04-15 11:34:12 +053094 ddr_refclk_sel = (in_be32(&gur->rcwsr[5]) >>
Priyanka Jainb1359912013-12-17 14:25:52 +053095 FSL_CORENET2_RCWSR5_DDR_REFCLK_SEL_SHIFT) &
96 FSL_CORENET2_RCWSR5_DDR_REFCLK_SEL_MASK;
97 /*
vijay rai0c12a152014-04-15 11:34:12 +053098 * For single source clocking, both ddrclock and sysclock
Priyanka Jainb1359912013-12-17 14:25:52 +053099 * are driven by differential sysclock.
100 */
vijay rai0c12a152014-04-15 11:34:12 +0530101 if (ddr_refclk_sel == FSL_CORENET2_RCWSR5_DDR_REFCLK_SINGLE_CLK)
Priyanka Jainb1359912013-12-17 14:25:52 +0530102 sys_info->freq_ddrbus = CONFIG_SYS_CLK_FREQ;
vijay rai0c12a152014-04-15 11:34:12 +0530103 else
Priyanka Jainb1359912013-12-17 14:25:52 +0530104#endif
York Sun98ffa192012-10-08 07:44:31 +0000105#ifdef CONFIG_DDR_CLK_FREQ
Priyanka Jainb1359912013-12-17 14:25:52 +0530106 sys_info->freq_ddrbus = CONFIG_DDR_CLK_FREQ;
York Sun98ffa192012-10-08 07:44:31 +0000107#else
Priyanka Jainb1359912013-12-17 14:25:52 +0530108 sys_info->freq_ddrbus = sysclk;
York Sun98ffa192012-10-08 07:44:31 +0000109#endif
Kumar Gala39aaca12009-03-19 02:46:19 -0500110
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530111 sys_info->freq_systembus *= (in_be32(&gur->rcwsr[0]) >> 25) & 0x1f;
York Sunf77329c2012-10-08 07:44:09 +0000112 mem_pll_rat = (in_be32(&gur->rcwsr[0]) >>
113 FSL_CORENET_RCWSR0_MEM_PLL_RAT_SHIFT)
114 & FSL_CORENET_RCWSR0_MEM_PLL_RAT_MASK;
York Sunc3678b02014-03-28 15:07:27 -0700115#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;
120 }
121#endif
Zang Roy-R61911e88f4212013-11-28 13:23:37 +0800122 /* 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
124 * it uses 6.
125 */
Shengzhou Liu5122dfa2014-04-25 16:31:22 +0800126#if defined(CONFIG_PPC_T4240) || defined(CONFIG_PPC_T4160) || \
127 defined(CONFIG_PPC_T4080)
Zang Roy-R61911e88f4212013-11-28 13:23:37 +0800128 if (SVR_MAJ(get_svr()) >= 2)
129 mem_pll_rat *= 2;
130#endif
Srikanth Srinivasanab48ca12010-02-10 17:32:43 +0800131 if (mem_pll_rat > 2)
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530132 sys_info->freq_ddrbus *= mem_pll_rat;
Srikanth Srinivasanab48ca12010-02-10 17:32:43 +0800133 else
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530134 sys_info->freq_ddrbus = sys_info->freq_systembus * mem_pll_rat;
Kumar Gala39aaca12009-03-19 02:46:19 -0500135
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530136 for (i = 0; i < CONFIG_SYS_FSL_NUM_CC_PLLS; i++) {
137 ratio[i] = (in_be32(&clk->pllcgsr[i].pllcngsr) >> 1) & 0x3f;
Srikanth Srinivasanab48ca12010-02-10 17:32:43 +0800138 if (ratio[i] > 4)
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530139 freq_c_pll[i] = sysclk * ratio[i];
Srikanth Srinivasanab48ca12010-02-10 17:32:43 +0800140 else
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530141 freq_c_pll[i] = sys_info->freq_systembus * ratio[i];
Srikanth Srinivasanab48ca12010-02-10 17:32:43 +0800142 }
York Sun9a653a92012-10-08 07:44:11 +0000143#ifdef CONFIG_SYS_FSL_QORIQ_CHASSIS2
144 /*
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530145 * As per CHASSIS2 architeture total 12 clusters are posible and
York Sun9a653a92012-10-08 07:44:11 +0000146 * Each cluster has up to 4 cores, sharing the same PLL selection.
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530147 * The cluster clock assignment is SoC defined.
148 *
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.
152 *
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.
156 *
York Sun9a653a92012-10-08 07:44:11 +0000157 */
158 for_each_cpu(i, cpu, cpu_numcores(), cpu_mask()) {
York Sunf6981432013-03-25 07:40:07 +0000159 int cluster = fsl_qoriq_core_to_cluster(cpu);
160 u32 c_pll_sel = (in_be32(&clk->clkcsr[cluster].clkcncsr) >> 27)
York Sun9a653a92012-10-08 07:44:11 +0000161 & 0xf;
162 u32 cplx_pll = core_cplx_PLL[c_pll_sel];
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530163 cplx_pll += cc_group[cluster] - 1;
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530164 sys_info->freq_processor[cpu] =
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530165 freq_c_pll[cplx_pll] / core_cplx_pll_div[c_pll_sel];
York Sun9a653a92012-10-08 07:44:11 +0000166 }
Prabhakar Kushwahab33bd8c2014-04-21 10:47:41 +0530167#if defined(CONFIG_PPC_B4860) || defined(CONFIG_PPC_B4420) || \
168 defined(CONFIG_PPC_T2080) || defined(CONFIG_PPC_T2081)
Sandeep Singh0cb33252013-03-25 07:33:09 +0000169#define FM1_CLK_SEL 0xe0000000
170#define FM1_CLK_SHIFT 29
171#else
York Sun9a653a92012-10-08 07:44:11 +0000172#define PME_CLK_SEL 0xe0000000
173#define PME_CLK_SHIFT 29
174#define FM1_CLK_SEL 0x1c000000
175#define FM1_CLK_SHIFT 26
Sandeep Singh0cb33252013-03-25 07:33:09 +0000176#endif
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530177#if !defined(CONFIG_FM_PLAT_CLK_DIV) || !defined(CONFIG_PME_PLAT_CLK_DIV)
York Sun9a653a92012-10-08 07:44:11 +0000178 rcw_tmp = in_be32(&gur->rcwsr[7]);
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530179#endif
York Sun9a653a92012-10-08 07:44:11 +0000180
181#ifdef CONFIG_SYS_DPAA_PME
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530182#ifndef CONFIG_PME_PLAT_CLK_DIV
York Sun9a653a92012-10-08 07:44:11 +0000183 switch ((rcw_tmp & PME_CLK_SEL) >> PME_CLK_SHIFT) {
184 case 1:
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530185 sys_info->freq_pme = freq_c_pll[CONFIG_SYS_PME_CLK];
York Sun9a653a92012-10-08 07:44:11 +0000186 break;
187 case 2:
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530188 sys_info->freq_pme = freq_c_pll[CONFIG_SYS_PME_CLK] / 2;
York Sun9a653a92012-10-08 07:44:11 +0000189 break;
190 case 3:
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530191 sys_info->freq_pme = freq_c_pll[CONFIG_SYS_PME_CLK] / 3;
York Sun9a653a92012-10-08 07:44:11 +0000192 break;
193 case 4:
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530194 sys_info->freq_pme = freq_c_pll[CONFIG_SYS_PME_CLK] / 4;
York Sun9a653a92012-10-08 07:44:11 +0000195 break;
196 case 6:
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530197 sys_info->freq_pme = freq_c_pll[CONFIG_SYS_PME_CLK + 1] / 2;
York Sun9a653a92012-10-08 07:44:11 +0000198 break;
199 case 7:
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530200 sys_info->freq_pme = freq_c_pll[CONFIG_SYS_PME_CLK + 1] / 3;
York Sun9a653a92012-10-08 07:44:11 +0000201 break;
202 default:
203 printf("Error: Unknown PME clock select!\n");
204 case 0:
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530205 sys_info->freq_pme = sys_info->freq_systembus / 2;
York Sun9a653a92012-10-08 07:44:11 +0000206 break;
207
208 }
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530209#else
210 sys_info->freq_pme = sys_info->freq_systembus / CONFIG_SYS_PME_CLK;
211
212#endif
York Sun9a653a92012-10-08 07:44:11 +0000213#endif
214
Haiying Wang990e1a82012-10-11 07:13:39 +0000215#ifdef CONFIG_SYS_DPAA_QBMAN
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530216 sys_info->freq_qman = sys_info->freq_systembus / 2;
Haiying Wang990e1a82012-10-11 07:13:39 +0000217#endif
218
York Sun9a653a92012-10-08 07:44:11 +0000219#ifdef CONFIG_SYS_DPAA_FMAN
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530220#ifndef CONFIG_FM_PLAT_CLK_DIV
York Sun9a653a92012-10-08 07:44:11 +0000221 switch ((rcw_tmp & FM1_CLK_SEL) >> FM1_CLK_SHIFT) {
222 case 1:
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530223 sys_info->freq_fman[0] = freq_c_pll[CONFIG_SYS_FM1_CLK];
York Sun9a653a92012-10-08 07:44:11 +0000224 break;
225 case 2:
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530226 sys_info->freq_fman[0] = freq_c_pll[CONFIG_SYS_FM1_CLK] / 2;
York Sun9a653a92012-10-08 07:44:11 +0000227 break;
228 case 3:
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530229 sys_info->freq_fman[0] = freq_c_pll[CONFIG_SYS_FM1_CLK] / 3;
York Sun9a653a92012-10-08 07:44:11 +0000230 break;
231 case 4:
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530232 sys_info->freq_fman[0] = freq_c_pll[CONFIG_SYS_FM1_CLK] / 4;
York Sun9a653a92012-10-08 07:44:11 +0000233 break;
Sandeep Singh0cb33252013-03-25 07:33:09 +0000234 case 5:
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530235 sys_info->freq_fman[0] = sys_info->freq_systembus;
Sandeep Singh0cb33252013-03-25 07:33:09 +0000236 break;
York Sun9a653a92012-10-08 07:44:11 +0000237 case 6:
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530238 sys_info->freq_fman[0] = freq_c_pll[CONFIG_SYS_FM1_CLK + 1] / 2;
York Sun9a653a92012-10-08 07:44:11 +0000239 break;
240 case 7:
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530241 sys_info->freq_fman[0] = freq_c_pll[CONFIG_SYS_FM1_CLK + 1] / 3;
York Sun9a653a92012-10-08 07:44:11 +0000242 break;
243 default:
244 printf("Error: Unknown FMan1 clock select!\n");
245 case 0:
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530246 sys_info->freq_fman[0] = sys_info->freq_systembus / 2;
York Sun9a653a92012-10-08 07:44:11 +0000247 break;
248 }
249#if (CONFIG_SYS_NUM_FMAN) == 2
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530250#ifdef CONFIG_SYS_FM2_CLK
York Sun9a653a92012-10-08 07:44:11 +0000251#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) {
255 case 1:
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530256 sys_info->freq_fman[1] = freq_c_pll[CONFIG_SYS_FM2_CLK + 1];
York Sun9a653a92012-10-08 07:44:11 +0000257 break;
258 case 2:
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530259 sys_info->freq_fman[1] = freq_c_pll[CONFIG_SYS_FM2_CLK + 1] / 2;
York Sun9a653a92012-10-08 07:44:11 +0000260 break;
261 case 3:
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530262 sys_info->freq_fman[1] = freq_c_pll[CONFIG_SYS_FM2_CLK + 1] / 3;
York Sun9a653a92012-10-08 07:44:11 +0000263 break;
264 case 4:
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530265 sys_info->freq_fman[1] = freq_c_pll[CONFIG_SYS_FM2_CLK + 1] / 4;
York Sun9a653a92012-10-08 07:44:11 +0000266 break;
Shaohui Xiec1015c62013-11-28 13:52:51 +0800267 case 5:
268 sys_info->freq_fman[1] = sys_info->freq_systembus;
269 break;
York Sun9a653a92012-10-08 07:44:11 +0000270 case 6:
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530271 sys_info->freq_fman[1] = freq_c_pll[CONFIG_SYS_FM2_CLK] / 2;
York Sun9a653a92012-10-08 07:44:11 +0000272 break;
273 case 7:
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530274 sys_info->freq_fman[1] = freq_c_pll[CONFIG_SYS_FM2_CLK] / 3;
York Sun9a653a92012-10-08 07:44:11 +0000275 break;
276 default:
277 printf("Error: Unknown FMan2 clock select!\n");
278 case 0:
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530279 sys_info->freq_fman[1] = sys_info->freq_systembus / 2;
York Sun9a653a92012-10-08 07:44:11 +0000280 break;
281 }
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530282#endif
York Sun9a653a92012-10-08 07:44:11 +0000283#endif /* CONFIG_SYS_NUM_FMAN == 2 */
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530284#else
285 sys_info->freq_fman[0] = sys_info->freq_systembus / CONFIG_SYS_FM1_CLK;
286#endif
287#endif
York Sun9a653a92012-10-08 07:44:11 +0000288
289#else /* CONFIG_SYS_FSL_QORIQ_CHASSIS2 */
290
Timur Tabifbb9ecf2011-08-05 16:15:24 -0500291 for_each_cpu(i, cpu, cpu_numcores(), cpu_mask()) {
York Sunf6981432013-03-25 07:40:07 +0000292 u32 c_pll_sel = (in_be32(&clk->clkcsr[cpu].clkcncsr) >> 27)
293 & 0xf;
Kumar Gala39aaca12009-03-19 02:46:19 -0500294 u32 cplx_pll = core_cplx_PLL[c_pll_sel];
295
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530296 sys_info->freq_processor[cpu] =
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530297 freq_c_pll[cplx_pll] / core_cplx_pll_div[c_pll_sel];
Kumar Gala39aaca12009-03-19 02:46:19 -0500298 }
Kumar Gala39aaca12009-03-19 02:46:19 -0500299#define PME_CLK_SEL 0x80000000
300#define FM1_CLK_SEL 0x40000000
301#define FM2_CLK_SEL 0x20000000
Kumar Galab5c87532011-02-16 02:03:29 -0600302#define HWA_ASYNC_DIV 0x04000000
303#if (CONFIG_SYS_FSL_NUM_CC_PLLS == 2)
304#define HWA_CC_PLL 1
Timur Tabi49054432012-10-05 11:09:19 +0000305#elif (CONFIG_SYS_FSL_NUM_CC_PLLS == 3)
306#define HWA_CC_PLL 2
Kumar Galab5c87532011-02-16 02:03:29 -0600307#elif (CONFIG_SYS_FSL_NUM_CC_PLLS == 4)
Wolfgang Denkcd6881b2011-05-19 22:21:41 +0200308#define HWA_CC_PLL 2
Kumar Galab5c87532011-02-16 02:03:29 -0600309#else
310#error CONFIG_SYS_FSL_NUM_CC_PLLS not set or unknown case
311#endif
Kumar Gala39aaca12009-03-19 02:46:19 -0500312 rcw_tmp = in_be32(&gur->rcwsr[7]);
313
314#ifdef CONFIG_SYS_DPAA_PME
Kumar Galab5c87532011-02-16 02:03:29 -0600315 if (rcw_tmp & PME_CLK_SEL) {
316 if (rcw_tmp & HWA_ASYNC_DIV)
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530317 sys_info->freq_pme = freq_c_pll[HWA_CC_PLL] / 4;
Kumar Galab5c87532011-02-16 02:03:29 -0600318 else
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530319 sys_info->freq_pme = freq_c_pll[HWA_CC_PLL] / 2;
Kumar Galab5c87532011-02-16 02:03:29 -0600320 } else {
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530321 sys_info->freq_pme = sys_info->freq_systembus / 2;
Kumar Galab5c87532011-02-16 02:03:29 -0600322 }
Kumar Gala39aaca12009-03-19 02:46:19 -0500323#endif
324
325#ifdef CONFIG_SYS_DPAA_FMAN
Kumar Galab5c87532011-02-16 02:03:29 -0600326 if (rcw_tmp & FM1_CLK_SEL) {
327 if (rcw_tmp & HWA_ASYNC_DIV)
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530328 sys_info->freq_fman[0] = freq_c_pll[HWA_CC_PLL] / 4;
Kumar Galab5c87532011-02-16 02:03:29 -0600329 else
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530330 sys_info->freq_fman[0] = freq_c_pll[HWA_CC_PLL] / 2;
Kumar Galab5c87532011-02-16 02:03:29 -0600331 } else {
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530332 sys_info->freq_fman[0] = sys_info->freq_systembus / 2;
Kumar Galab5c87532011-02-16 02:03:29 -0600333 }
Kumar Gala39aaca12009-03-19 02:46:19 -0500334#if (CONFIG_SYS_NUM_FMAN) == 2
Kumar Galab5c87532011-02-16 02:03:29 -0600335 if (rcw_tmp & FM2_CLK_SEL) {
336 if (rcw_tmp & HWA_ASYNC_DIV)
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530337 sys_info->freq_fman[1] = freq_c_pll[HWA_CC_PLL] / 4;
Kumar Galab5c87532011-02-16 02:03:29 -0600338 else
Prabhakar Kushwahace746fe2013-09-03 11:20:15 +0530339 sys_info->freq_fman[1] = freq_c_pll[HWA_CC_PLL] / 2;
Kumar Galab5c87532011-02-16 02:03:29 -0600340 } else {
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530341 sys_info->freq_fman[1] = sys_info->freq_systembus / 2;
Kumar Galab5c87532011-02-16 02:03:29 -0600342 }
Kumar Gala39aaca12009-03-19 02:46:19 -0500343#endif
344#endif
345
Shaohui Xie3e83fc92013-03-25 07:33:25 +0000346#ifdef CONFIG_SYS_DPAA_QBMAN
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530347 sys_info->freq_qman = sys_info->freq_systembus / 2;
Shaohui Xie3e83fc92013-03-25 07:33:25 +0000348#endif
349
York Sun9a653a92012-10-08 07:44:11 +0000350#endif /* CONFIG_SYS_FSL_QORIQ_CHASSIS2 */
351
Zhao Qiang2a44efe2014-03-21 16:21:45 +0800352#ifdef CONFIG_U_QE
353 sys_info->freq_qe = sys_info->freq_systembus / 2;
354#endif
355
York Sun9a653a92012-10-08 07:44:11 +0000356#else /* CONFIG_FSL_CORENET */
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530357 uint plat_ratio, e500_ratio, half_freq_systembus;
Haiying Wang2fc7eb02009-01-15 11:58:35 -0500358 int i;
Haiying Wangb3d7f202009-05-20 12:30:29 -0400359#ifdef CONFIG_QE
Haiying Wanga52d2f82011-02-11 01:25:30 -0600360 __maybe_unused u32 qe_ratio;
Haiying Wangb3d7f202009-05-20 12:30:29 -0400361#endif
wdenk42d1f032003-10-15 23:53:47 +0000362
363 plat_ratio = (gur->porpllsr) & 0x0000003e;
364 plat_ratio >>= 1;
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530365 sys_info->freq_systembus = plat_ratio * CONFIG_SYS_CLK_FREQ;
Andy Fleming66ed6cc2007-04-23 02:37:47 -0500366
367 /* Divide before multiply to avoid integer
368 * overflow for processor speeds above 2GHz */
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530369 half_freq_systembus = sys_info->freq_systembus/2;
Poonam Aggrwal0e870982009-07-31 12:08:14 +0530370 for (i = 0; i < cpu_numcores(); i++) {
Haiying Wang2fc7eb02009-01-15 11:58:35 -0500371 e500_ratio = ((gur->porpllsr) >> (i * 8 + 16)) & 0x3f;
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530372 sys_info->freq_processor[i] = e500_ratio * half_freq_systembus;
Haiying Wang2fc7eb02009-01-15 11:58:35 -0500373 }
James Yanga3e77fa2008-02-08 18:05:08 -0600374
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530375 /* Note: freq_ddrbus is the MCLK frequency, not the data rate. */
376 sys_info->freq_ddrbus = sys_info->freq_systembus;
Kumar Galad4357932007-12-07 04:59:26 -0600377
378#ifdef CONFIG_DDR_CLK_FREQ
379 {
Jason Jinc0391112008-09-27 14:40:57 +0800380 u32 ddr_ratio = ((gur->porpllsr) & MPC85xx_PORPLLSR_DDR_RATIO)
381 >> MPC85xx_PORPLLSR_DDR_RATIO_SHIFT;
Kumar Galad4357932007-12-07 04:59:26 -0600382 if (ddr_ratio != 0x7)
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530383 sys_info->freq_ddrbus = ddr_ratio * CONFIG_DDR_CLK_FREQ;
Kumar Galad4357932007-12-07 04:59:26 -0600384 }
385#endif
Trent Piephoada591d2008-12-03 15:16:37 -0800386
Haiying Wangb3d7f202009-05-20 12:30:29 -0400387#ifdef CONFIG_QE
York Sunbe7bebe2012-08-10 11:07:26 +0000388#if defined(CONFIG_P1012) || defined(CONFIG_P1021) || defined(CONFIG_P1025)
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530389 sys_info->freq_qe = sys_info->freq_systembus;
Haiying Wanga52d2f82011-02-11 01:25:30 -0600390#else
Haiying Wangb3d7f202009-05-20 12:30:29 -0400391 qe_ratio = ((gur->porpllsr) & MPC85xx_PORPLLSR_QE_RATIO)
392 >> MPC85xx_PORPLLSR_QE_RATIO_SHIFT;
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530393 sys_info->freq_qe = qe_ratio * CONFIG_SYS_CLK_FREQ;
Haiying Wangb3d7f202009-05-20 12:30:29 -0400394#endif
Haiying Wanga52d2f82011-02-11 01:25:30 -0600395#endif
Haiying Wangb3d7f202009-05-20 12:30:29 -0400396
Haiying Wang24995d82011-01-20 22:26:31 +0000397#ifdef CONFIG_SYS_DPAA_FMAN
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530398 sys_info->freq_fman[0] = sys_info->freq_systembus;
Haiying Wang24995d82011-01-20 22:26:31 +0000399#endif
400
401#endif /* CONFIG_FSL_CORENET */
402
Dipen Dudhatbeba93e2011-01-19 12:46:27 +0530403#if defined(CONFIG_FSL_LBC)
York Sun9a653a92012-10-08 07:44:11 +0000404 uint lcrr_div;
Trent Piephoada591d2008-12-03 15:16:37 -0800405#if defined(CONFIG_SYS_LBC_LCRR)
406 /* We will program LCRR to this value later */
407 lcrr_div = CONFIG_SYS_LBC_LCRR & LCRR_CLKDIV;
408#else
Becky Brucef51cdaf2010-06-17 11:37:20 -0500409 lcrr_div = in_be32(&(LBC_BASE_ADDR)->lcrr) & LCRR_CLKDIV;
Trent Piephoada591d2008-12-03 15:16:37 -0800410#endif
411 if (lcrr_div == 2 || lcrr_div == 4 || lcrr_div == 8) {
Dave Liu0fd2fa62009-11-17 20:49:05 +0800412#if defined(CONFIG_FSL_CORENET)
413 /* If this is corenet based SoC, bit-representation
414 * for four times the clock divider values.
415 */
416 lcrr_div *= 4;
417#elif !defined(CONFIG_MPC8540) && !defined(CONFIG_MPC8541) && \
Trent Piephoada591d2008-12-03 15:16:37 -0800418 !defined(CONFIG_MPC8555) && !defined(CONFIG_MPC8560)
419 /*
420 * Yes, the entire PQ38 family use the same
421 * bit-representation for twice the clock divider values.
422 */
423 lcrr_div *= 2;
424#endif
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530425 sys_info->freq_localbus = sys_info->freq_systembus / lcrr_div;
Trent Piephoada591d2008-12-03 15:16:37 -0800426 } else {
427 /* In case anyone cares what the unknown value is */
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530428 sys_info->freq_localbus = lcrr_div;
Trent Piephoada591d2008-12-03 15:16:37 -0800429 }
Dipen Dudhatbeba93e2011-01-19 12:46:27 +0530430#endif
Kumar Gala800c73c2012-10-08 07:44:06 +0000431
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;
435
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530436 sys_info->freq_localbus = sys_info->freq_systembus / ccr;
Kumar Gala800c73c2012-10-08 07:44:06 +0000437#endif
wdenk42d1f032003-10-15 23:53:47 +0000438}
439
Andy Fleming66ed6cc2007-04-23 02:37:47 -0500440
wdenk42d1f032003-10-15 23:53:47 +0000441int get_clocks (void)
442{
wdenk42d1f032003-10-15 23:53:47 +0000443 sys_info_t sys_info;
Timur Tabi88353a92008-04-04 11:15:58 -0500444#ifdef CONFIG_MPC8544
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200445 volatile ccsr_gur_t *gur = (void *) CONFIG_SYS_MPC85xx_GUTS_ADDR;
Timur Tabi88353a92008-04-04 11:15:58 -0500446#endif
Jon Loeliger9c4c5ae2005-07-23 10:37:35 -0500447#if defined(CONFIG_CPM2)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200448 volatile ccsr_cpm_t *cpm = (ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR;
wdenk42d1f032003-10-15 23:53:47 +0000449 uint sccr, dfbrg;
450
451 /* set VCO = 4 * BRG */
Kumar Galaaafeefb2007-11-28 00:36:33 -0600452 cpm->im_cpm_intctl.sccr &= 0xfffffffc;
453 sccr = cpm->im_cpm_intctl.sccr;
wdenk42d1f032003-10-15 23:53:47 +0000454 dfbrg = (sccr & SCCR_DFBRG_MSK) >> SCCR_DFBRG_SHIFT;
455#endif
456 get_sys_info (&sys_info);
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530457 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;
Timur Tabi88353a92008-04-04 11:15:58 -0500461
Haiying Wangb3d7f202009-05-20 12:30:29 -0400462#ifdef CONFIG_QE
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530463 gd->arch.qe_clk = sys_info.freq_qe;
Simon Glass45bae2e2012-12-13 20:48:50 +0000464 gd->arch.brg_clk = gd->arch.qe_clk / 2;
Haiying Wangb3d7f202009-05-20 12:30:29 -0400465#endif
Timur Tabi88353a92008-04-04 11:15:58 -0500466 /*
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
471 * AN2919.
472 */
473#if defined(CONFIG_MPC8540) || defined(CONFIG_MPC8541) || \
Tang Yuantianf62b1232013-09-06 10:45:40 +0800474 defined(CONFIG_MPC8560) || defined(CONFIG_MPC8555) || \
475 defined(CONFIG_P1022)
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530476 gd->arch.i2c1_clk = sys_info.freq_systembus;
Timur Tabi88353a92008-04-04 11:15:58 -0500477#elif defined(CONFIG_MPC8544)
478 /*
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.
484 */
485 if (gur->pordevsr2 & MPC85xx_PORDEVSR2_SEC_CFG)
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530486 gd->arch.i2c1_clk = sys_info.freq_systembus / 3;
Kumar Gala42653b82008-10-16 21:58:49 -0500487 else
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530488 gd->arch.i2c1_clk = sys_info.freq_systembus / 2;
Timur Tabi88353a92008-04-04 11:15:58 -0500489#else
490 /* Most 85xx SOCs use CCB/2, so this is the default behavior. */
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530491 gd->arch.i2c1_clk = sys_info.freq_systembus / 2;
Timur Tabi88353a92008-04-04 11:15:58 -0500492#endif
Simon Glass609e6ec2012-12-13 20:48:49 +0000493 gd->arch.i2c2_clk = gd->arch.i2c1_clk;
Timur Tabi943afa22008-01-09 14:35:26 -0600494
Dipen Dudhat6b9ea082009-09-01 17:27:00 +0530495#if defined(CONFIG_FSL_ESDHC)
Priyanka Jain7d640e92011-02-08 15:45:25 +0530496#if defined(CONFIG_MPC8569) || defined(CONFIG_P1010) ||\
497 defined(CONFIG_P1014)
Simon Glasse9adeca2012-12-13 20:49:05 +0000498 gd->arch.sdhc_clk = gd->bus_clk;
Anton Vorontsov7f52ed52009-10-15 17:47:06 +0400499#else
Simon Glasse9adeca2012-12-13 20:49:05 +0000500 gd->arch.sdhc_clk = gd->bus_clk / 2;
Kumar Galaef50d6c2008-08-12 11:14:19 -0500501#endif
Anton Vorontsov7f52ed52009-10-15 17:47:06 +0400502#endif /* defined(CONFIG_FSL_ESDHC) */
Kumar Galaef50d6c2008-08-12 11:14:19 -0500503
Jon Loeliger9c4c5ae2005-07-23 10:37:35 -0500504#if defined(CONFIG_CPM2)
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530505 gd->arch.vco_out = 2*sys_info.freq_systembus;
Simon Glass748cd052012-12-13 20:48:46 +0000506 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)));
wdenk42d1f032003-10-15 23:53:47 +0000509#endif
510
511 if(gd->cpu_clk != 0) return (0);
512 else return (1);
513}
514
515
516/********************************************
517 * get_bus_freq
518 * return system bus freq in Hz
519 *********************************************/
520ulong get_bus_freq (ulong dummy)
521{
James Yanga3e77fa2008-02-08 18:05:08 -0600522 return gd->bus_clk;
wdenk42d1f032003-10-15 23:53:47 +0000523}
Kumar Galad4357932007-12-07 04:59:26 -0600524
525/********************************************
526 * get_ddr_freq
527 * return ddr bus freq in Hz
528 *********************************************/
529ulong get_ddr_freq (ulong dummy)
530{
James Yanga3e77fa2008-02-08 18:05:08 -0600531 return gd->mem_clk;
Kumar Galad4357932007-12-07 04:59:26 -0600532}