]> git.sur5r.net Git - u-boot/blob - cpu/mpc85xx/speed.c
Merge branch 'master' of git://git.denx.de/u-boot-mpc85xx
[u-boot] / cpu / mpc85xx / speed.c
1 /*
2  * Copyright 2004 Freescale Semiconductor.
3  * (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>
31 #include <asm/io.h>
32
33 DECLARE_GLOBAL_DATA_PTR;
34
35 /* --------------------------------------------------------------- */
36
37 void get_sys_info (sys_info_t * sysInfo)
38 {
39         volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
40         uint plat_ratio,e500_ratio,half_freqSystemBus;
41         uint lcrr_div;
42
43         plat_ratio = (gur->porpllsr) & 0x0000003e;
44         plat_ratio >>= 1;
45         sysInfo->freqSystemBus = plat_ratio * CONFIG_SYS_CLK_FREQ;
46         e500_ratio = (gur->porpllsr) & 0x003f0000;
47         e500_ratio >>= 16;
48
49         /* Divide before multiply to avoid integer
50          * overflow for processor speeds above 2GHz */
51         half_freqSystemBus = sysInfo->freqSystemBus/2;
52         sysInfo->freqProcessor = e500_ratio*half_freqSystemBus;
53
54         /* Note: freqDDRBus is the MCLK frequency, not the data rate. */
55         sysInfo->freqDDRBus = sysInfo->freqSystemBus;
56
57 #ifdef CONFIG_DDR_CLK_FREQ
58         {
59                 u32 ddr_ratio = ((gur->porpllsr) & MPC85xx_PORPLLSR_DDR_RATIO)
60                         >> MPC85xx_PORPLLSR_DDR_RATIO_SHIFT;
61                 if (ddr_ratio != 0x7)
62                         sysInfo->freqDDRBus = ddr_ratio * CONFIG_DDR_CLK_FREQ;
63         }
64 #endif
65
66 #if defined(CONFIG_SYS_LBC_LCRR)
67         /* We will program LCRR to this value later */
68         lcrr_div = CONFIG_SYS_LBC_LCRR & LCRR_CLKDIV;
69 #else
70         {
71             volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
72             lcrr_div = in_be32(&lbc->lcrr) & LCRR_CLKDIV;
73         }
74 #endif
75         if (lcrr_div == 2 || lcrr_div == 4 || lcrr_div == 8) {
76 #if !defined(CONFIG_MPC8540) && !defined(CONFIG_MPC8541) && \
77     !defined(CONFIG_MPC8555) && !defined(CONFIG_MPC8560)
78                 /*
79                  * Yes, the entire PQ38 family use the same
80                  * bit-representation for twice the clock divider values.
81                  */
82                 lcrr_div *= 2;
83 #endif
84                 sysInfo->freqLocalBus = sysInfo->freqSystemBus / lcrr_div;
85         } else {
86                 /* In case anyone cares what the unknown value is */
87                 sysInfo->freqLocalBus = lcrr_div;
88         }
89 }
90
91
92 int get_clocks (void)
93 {
94         sys_info_t sys_info;
95 #ifdef CONFIG_MPC8544
96         volatile ccsr_gur_t *gur = (void *) CONFIG_SYS_MPC85xx_GUTS_ADDR;
97 #endif
98 #if defined(CONFIG_CPM2)
99         volatile ccsr_cpm_t *cpm = (ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR;
100         uint sccr, dfbrg;
101
102         /* set VCO = 4 * BRG */
103         cpm->im_cpm_intctl.sccr &= 0xfffffffc;
104         sccr = cpm->im_cpm_intctl.sccr;
105         dfbrg = (sccr & SCCR_DFBRG_MSK) >> SCCR_DFBRG_SHIFT;
106 #endif
107         get_sys_info (&sys_info);
108         gd->cpu_clk = sys_info.freqProcessor;
109         gd->bus_clk = sys_info.freqSystemBus;
110         gd->mem_clk = sys_info.freqDDRBus;
111         gd->lbc_clk = sys_info.freqLocalBus;
112
113         /*
114          * The base clock for I2C depends on the actual SOC.  Unfortunately,
115          * there is no pattern that can be used to determine the frequency, so
116          * the only choice is to look up the actual SOC number and use the value
117          * for that SOC. This information is taken from application note
118          * AN2919.
119          */
120 #if defined(CONFIG_MPC8540) || defined(CONFIG_MPC8541) || \
121         defined(CONFIG_MPC8560) || defined(CONFIG_MPC8555)
122         gd->i2c1_clk = sys_info.freqSystemBus;
123 #elif defined(CONFIG_MPC8544)
124         /*
125          * On the 8544, the I2C clock is the same as the SEC clock.  This can be
126          * either CCB/2 or CCB/3, depending on the value of cfg_sec_freq. See
127          * 4.4.3.3 of the 8544 RM.  Note that this might actually work for all
128          * 85xx, but only the 8544 has cfg_sec_freq, so it's unknown if the
129          * PORDEVSR2_SEC_CFG bit is 0 on all 85xx boards that are not an 8544.
130          */
131         if (gur->pordevsr2 & MPC85xx_PORDEVSR2_SEC_CFG)
132                 gd->i2c1_clk = sys_info.freqSystemBus / 3;
133         else
134                 gd->i2c1_clk = sys_info.freqSystemBus / 2;
135 #else
136         /* Most 85xx SOCs use CCB/2, so this is the default behavior. */
137         gd->i2c1_clk = sys_info.freqSystemBus / 2;
138 #endif
139         gd->i2c2_clk = gd->i2c1_clk;
140
141 #if defined(CONFIG_MPC8536)
142         gd->sdhc_clk = gd->bus_clk / 2;
143 #endif
144
145 #if defined(CONFIG_CPM2)
146         gd->vco_out = 2*sys_info.freqSystemBus;
147         gd->cpm_clk = gd->vco_out / 2;
148         gd->scc_clk = gd->vco_out / 4;
149         gd->brg_clk = gd->vco_out / (1 << (2 * (dfbrg + 1)));
150 #endif
151
152         if(gd->cpu_clk != 0) return (0);
153         else return (1);
154 }
155
156
157 /********************************************
158  * get_bus_freq
159  * return system bus freq in Hz
160  *********************************************/
161 ulong get_bus_freq (ulong dummy)
162 {
163         return gd->bus_clk;
164 }
165
166 /********************************************
167  * get_ddr_freq
168  * return ddr bus freq in Hz
169  *********************************************/
170 ulong get_ddr_freq (ulong dummy)
171 {
172         return gd->mem_clk;
173 }