blob: b0f47e042e96455120d38e397f8f20c6d0397648 [file] [log] [blame]
wdenk9c53f402003-10-15 23:53:47 +00001/*
wdenka445ddf2004-06-09 00:34:46 +00002 * Copyright 2004 Freescale Semiconductor.
wdenk9c53f402003-10-15 23:53:47 +00003 * (C) Copyright 2003 Motorola Inc.
4 * Xianghua Xiao, (X.Xiao@motorola.com)
5 *
6 * (C) Copyright 2000
7 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
8 *
9 * See file CREDITS for list of people who contributed to this
10 * project.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 * MA 02111-1307 USA
26 */
27
28#include <common.h>
29#include <ppc_asm.tmpl>
30#include <asm/processor.h>
Trent Piepho0b691fc2008-12-03 15:16:37 -080031#include <asm/io.h>
wdenk9c53f402003-10-15 23:53:47 +000032
Wolfgang Denk6405a152006-03-31 18:32:53 +020033DECLARE_GLOBAL_DATA_PTR;
34
wdenk9c53f402003-10-15 23:53:47 +000035/* --------------------------------------------------------------- */
36
wdenk9c53f402003-10-15 23:53:47 +000037void get_sys_info (sys_info_t * sysInfo)
38{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020039 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Andy Fleming6d972762007-04-23 02:37:47 -050040 uint plat_ratio,e500_ratio,half_freqSystemBus;
Trent Piepho0b691fc2008-12-03 15:16:37 -080041 uint lcrr_div;
Haiying Wangbb8aea72009-01-15 11:58:35 -050042 int i;
wdenk9c53f402003-10-15 23:53:47 +000043
44 plat_ratio = (gur->porpllsr) & 0x0000003e;
45 plat_ratio >>= 1;
Andy Fleming6d972762007-04-23 02:37:47 -050046 sysInfo->freqSystemBus = plat_ratio * CONFIG_SYS_CLK_FREQ;
Andy Fleming6d972762007-04-23 02:37:47 -050047
48 /* Divide before multiply to avoid integer
49 * overflow for processor speeds above 2GHz */
50 half_freqSystemBus = sysInfo->freqSystemBus/2;
Haiying Wangbb8aea72009-01-15 11:58:35 -050051 for (i = 0; i < CONFIG_NUM_CPUS; i++) {
52 e500_ratio = ((gur->porpllsr) >> (i * 8 + 16)) & 0x3f;
53 sysInfo->freqProcessor[i] = e500_ratio * half_freqSystemBus;
54 }
James Yangd1d51ad2008-02-08 18:05:08 -060055
56 /* Note: freqDDRBus is the MCLK frequency, not the data rate. */
Kumar Gala07db1702007-12-07 04:59:26 -060057 sysInfo->freqDDRBus = sysInfo->freqSystemBus;
58
59#ifdef CONFIG_DDR_CLK_FREQ
60 {
Jason Jinbfcd6c32008-09-27 14:40:57 +080061 u32 ddr_ratio = ((gur->porpllsr) & MPC85xx_PORPLLSR_DDR_RATIO)
62 >> MPC85xx_PORPLLSR_DDR_RATIO_SHIFT;
Kumar Gala07db1702007-12-07 04:59:26 -060063 if (ddr_ratio != 0x7)
64 sysInfo->freqDDRBus = ddr_ratio * CONFIG_DDR_CLK_FREQ;
65 }
66#endif
Trent Piepho0b691fc2008-12-03 15:16:37 -080067
68#if defined(CONFIG_SYS_LBC_LCRR)
69 /* We will program LCRR to this value later */
70 lcrr_div = CONFIG_SYS_LBC_LCRR & LCRR_CLKDIV;
71#else
72 {
73 volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
74 lcrr_div = in_be32(&lbc->lcrr) & LCRR_CLKDIV;
75 }
76#endif
77 if (lcrr_div == 2 || lcrr_div == 4 || lcrr_div == 8) {
78#if !defined(CONFIG_MPC8540) && !defined(CONFIG_MPC8541) && \
79 !defined(CONFIG_MPC8555) && !defined(CONFIG_MPC8560)
80 /*
81 * Yes, the entire PQ38 family use the same
82 * bit-representation for twice the clock divider values.
83 */
84 lcrr_div *= 2;
85#endif
86 sysInfo->freqLocalBus = sysInfo->freqSystemBus / lcrr_div;
87 } else {
88 /* In case anyone cares what the unknown value is */
89 sysInfo->freqLocalBus = lcrr_div;
90 }
wdenk9c53f402003-10-15 23:53:47 +000091}
92
Andy Fleming6d972762007-04-23 02:37:47 -050093
wdenk9c53f402003-10-15 23:53:47 +000094int get_clocks (void)
95{
wdenk9c53f402003-10-15 23:53:47 +000096 sys_info_t sys_info;
Timur Tabi44befe02008-04-04 11:15:58 -050097#ifdef CONFIG_MPC8544
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020098 volatile ccsr_gur_t *gur = (void *) CONFIG_SYS_MPC85xx_GUTS_ADDR;
Timur Tabi44befe02008-04-04 11:15:58 -050099#endif
Jon Loeligerf5ad3782005-07-23 10:37:35 -0500100#if defined(CONFIG_CPM2)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200101 volatile ccsr_cpm_t *cpm = (ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR;
wdenk9c53f402003-10-15 23:53:47 +0000102 uint sccr, dfbrg;
103
104 /* set VCO = 4 * BRG */
Kumar Galacd113a02007-11-28 00:36:33 -0600105 cpm->im_cpm_intctl.sccr &= 0xfffffffc;
106 sccr = cpm->im_cpm_intctl.sccr;
wdenk9c53f402003-10-15 23:53:47 +0000107 dfbrg = (sccr & SCCR_DFBRG_MSK) >> SCCR_DFBRG_SHIFT;
108#endif
109 get_sys_info (&sys_info);
Haiying Wangbb8aea72009-01-15 11:58:35 -0500110 gd->cpu_clk = sys_info.freqProcessor[0];
wdenk9c53f402003-10-15 23:53:47 +0000111 gd->bus_clk = sys_info.freqSystemBus;
James Yangd1d51ad2008-02-08 18:05:08 -0600112 gd->mem_clk = sys_info.freqDDRBus;
Trent Piepho0b691fc2008-12-03 15:16:37 -0800113 gd->lbc_clk = sys_info.freqLocalBus;
Timur Tabi44befe02008-04-04 11:15:58 -0500114
115 /*
116 * The base clock for I2C depends on the actual SOC. Unfortunately,
117 * there is no pattern that can be used to determine the frequency, so
118 * the only choice is to look up the actual SOC number and use the value
119 * for that SOC. This information is taken from application note
120 * AN2919.
121 */
122#if defined(CONFIG_MPC8540) || defined(CONFIG_MPC8541) || \
123 defined(CONFIG_MPC8560) || defined(CONFIG_MPC8555)
Timur Tabic1499f482008-01-09 14:35:26 -0600124 gd->i2c1_clk = sys_info.freqSystemBus;
Timur Tabi44befe02008-04-04 11:15:58 -0500125#elif defined(CONFIG_MPC8544)
126 /*
127 * On the 8544, the I2C clock is the same as the SEC clock. This can be
128 * either CCB/2 or CCB/3, depending on the value of cfg_sec_freq. See
129 * 4.4.3.3 of the 8544 RM. Note that this might actually work for all
130 * 85xx, but only the 8544 has cfg_sec_freq, so it's unknown if the
131 * PORDEVSR2_SEC_CFG bit is 0 on all 85xx boards that are not an 8544.
132 */
133 if (gur->pordevsr2 & MPC85xx_PORDEVSR2_SEC_CFG)
Wolfgang Grandegger7ac0ff42008-09-30 10:55:57 +0200134 gd->i2c1_clk = sys_info.freqSystemBus / 3;
Kumar Gala9632f662008-10-16 21:58:49 -0500135 else
136 gd->i2c1_clk = sys_info.freqSystemBus / 2;
Timur Tabi44befe02008-04-04 11:15:58 -0500137#else
138 /* Most 85xx SOCs use CCB/2, so this is the default behavior. */
139 gd->i2c1_clk = sys_info.freqSystemBus / 2;
140#endif
141 gd->i2c2_clk = gd->i2c1_clk;
Timur Tabic1499f482008-01-09 14:35:26 -0600142
Kumar Galacd777282008-08-12 11:14:19 -0500143#if defined(CONFIG_MPC8536)
144 gd->sdhc_clk = gd->bus_clk / 2;
145#endif
146
Jon Loeligerf5ad3782005-07-23 10:37:35 -0500147#if defined(CONFIG_CPM2)
wdenk9c53f402003-10-15 23:53:47 +0000148 gd->vco_out = 2*sys_info.freqSystemBus;
149 gd->cpm_clk = gd->vco_out / 2;
150 gd->scc_clk = gd->vco_out / 4;
151 gd->brg_clk = gd->vco_out / (1 << (2 * (dfbrg + 1)));
152#endif
153
154 if(gd->cpu_clk != 0) return (0);
155 else return (1);
156}
157
158
159/********************************************
160 * get_bus_freq
161 * return system bus freq in Hz
162 *********************************************/
163ulong get_bus_freq (ulong dummy)
164{
James Yangd1d51ad2008-02-08 18:05:08 -0600165 return gd->bus_clk;
wdenk9c53f402003-10-15 23:53:47 +0000166}
Kumar Gala07db1702007-12-07 04:59:26 -0600167
168/********************************************
169 * get_ddr_freq
170 * return ddr bus freq in Hz
171 *********************************************/
172ulong get_ddr_freq (ulong dummy)
173{
James Yangd1d51ad2008-02-08 18:05:08 -0600174 return gd->mem_clk;
Kumar Gala07db1702007-12-07 04:59:26 -0600175}