blob: a08ae5f94b92713bac3d2c5bb490462b71a5d46c [file] [log] [blame]
Jon Loeligerdebb7352006-04-26 17:58:56 -05001/*
2 * Copyright 2004 Freescale Semiconductor.
3 * Jeff Brown (jeffrey@freescale.com)
4 * Srikanth Srinivasan (srikanth.srinivasan@freescale.com)
5 *
6 * (C) Copyright 2000-2002
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 <mpc86xx.h>
30#include <asm/processor.h>
31
32unsigned long get_board_sys_clk(ulong dummy);
33unsigned long get_sysclk_from_px_regs(void);
34
35
Jon Loeliger5c9efb32006-04-27 10:15:16 -050036void get_sys_info (sys_info_t *sysInfo)
Jon Loeligerdebb7352006-04-26 17:58:56 -050037{
38 volatile immap_t *immap = (immap_t *)CFG_IMMR;
39 volatile ccsr_gur_t *gur = &immap->im_gur;
40 uint plat_ratio, e600_ratio;
41
42 plat_ratio = (gur->porpllsr) & 0x0000003e;
43 plat_ratio >>= 1;
Jon Loeliger5c9efb32006-04-27 10:15:16 -050044
Jon Loeligerdebb7352006-04-26 17:58:56 -050045 switch(plat_ratio) {
46 case 0x0:
47 sysInfo->freqSystemBus = 16 * CONFIG_SYS_CLK_FREQ;
48 break;
49 case 0x02:
50 case 0x03:
51 case 0x04:
52 case 0x05:
53 case 0x06:
54 case 0x08:
55 case 0x09:
56 case 0x0a:
57 case 0x0c:
58 case 0x10:
59 sysInfo->freqSystemBus = plat_ratio * CONFIG_SYS_CLK_FREQ;
60 break;
61 default:
62 sysInfo->freqSystemBus = 0;
63 break;
64 }
65
Jon Loeliger5c9efb32006-04-27 10:15:16 -050066#if 0
67 printf("assigned system bus freq = %d for plat ratio 0x%08lx\n",
68 sysInfo->freqSystemBus, plat_ratio);
69#endif
70
Jon Loeligerdebb7352006-04-26 17:58:56 -050071 e600_ratio = (gur->porpllsr) & 0x003f0000;
72 e600_ratio >>= 16;
Jon Loeliger5c9efb32006-04-27 10:15:16 -050073
74 switch (e600_ratio) {
Jon Loeligerdebb7352006-04-26 17:58:56 -050075 case 0x10:
Jon Loeliger5c9efb32006-04-27 10:15:16 -050076 sysInfo->freqProcessor = 2 * sysInfo->freqSystemBus;
Jon Loeligerdebb7352006-04-26 17:58:56 -050077 break;
Jon Loeliger5c9efb32006-04-27 10:15:16 -050078 case 0x19:
79 sysInfo->freqProcessor = 5 * sysInfo->freqSystemBus/2;
Jon Loeligerdebb7352006-04-26 17:58:56 -050080 break;
81 case 0x20:
Jon Loeliger5c9efb32006-04-27 10:15:16 -050082 sysInfo->freqProcessor = 3 * sysInfo->freqSystemBus;
Jon Loeligerdebb7352006-04-26 17:58:56 -050083 break;
84 case 0x39:
Jon Loeliger5c9efb32006-04-27 10:15:16 -050085 sysInfo->freqProcessor = 7 * sysInfo->freqSystemBus/2;
Jon Loeligerdebb7352006-04-26 17:58:56 -050086 break;
87 case 0x28:
Jon Loeliger5c9efb32006-04-27 10:15:16 -050088 sysInfo->freqProcessor = 4 * sysInfo->freqSystemBus;
Jon Loeligerdebb7352006-04-26 17:58:56 -050089 break;
90 case 0x1d:
Jon Loeliger5c9efb32006-04-27 10:15:16 -050091 sysInfo->freqProcessor = 9 * sysInfo->freqSystemBus/2;
Jon Loeligerdebb7352006-04-26 17:58:56 -050092 break;
93 default:
Jon Loeliger5c9efb32006-04-27 10:15:16 -050094 /* JB - Emulator workaround until real cop is plugged in */
95 /* sysInfo->freqProcessor = 3 * sysInfo->freqSystemBus; */
96 sysInfo->freqProcessor = e600_ratio + sysInfo->freqSystemBus;
Jon Loeligerdebb7352006-04-26 17:58:56 -050097 break;
98 }
Jon Loeliger5c9efb32006-04-27 10:15:16 -050099#if 0
100 printf("assigned processor freq = %d for e600 ratio 0x%08lx\n",
101 sysInfo->freqProcessor, e600_ratio);
102#endif
Jon Loeligerdebb7352006-04-26 17:58:56 -0500103}
104
105
Jon Loeligerdebb7352006-04-26 17:58:56 -0500106/*
107 * Measure CPU clock speed (core clock GCLK1, GCLK2)
Jon Loeligerdebb7352006-04-26 17:58:56 -0500108 * (Approx. GCLK frequency in Hz)
109 */
110
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500111int get_clocks(void)
Jon Loeligerdebb7352006-04-26 17:58:56 -0500112{
113 DECLARE_GLOBAL_DATA_PTR;
114 sys_info_t sys_info;
115
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500116 get_sys_info(&sys_info);
Jon Loeligerdebb7352006-04-26 17:58:56 -0500117 gd->cpu_clk = sys_info.freqProcessor;
118 gd->bus_clk = sys_info.freqSystemBus;
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500119
120 if (gd->cpu_clk != 0)
121 return 0;
122 else
123 return 1;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500124}
125
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500126
127/*
Jon Loeligerdebb7352006-04-26 17:58:56 -0500128 * get_bus_freq
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500129 * Return system bus freq in Hz
130 */
131ulong get_bus_freq(ulong dummy)
Jon Loeligerdebb7352006-04-26 17:58:56 -0500132{
133 ulong val;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500134 sys_info_t sys_info;
135
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500136 get_sys_info(&sys_info);
Jon Loeligerdebb7352006-04-26 17:58:56 -0500137 val = sys_info.freqSystemBus;
138
139 return val;
140}
141
142unsigned long get_sysclk_from_px_regs()
143{
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500144 ulong val;
145 u8 vclkh, vclkl;
146
147 vclkh = in8(PIXIS_BASE + PIXIS_VCLKH);
148 vclkl = in8(PIXIS_BASE + PIXIS_VCLKL);
149
150 if ((vclkh == 0x84) && (vclkl == 0x07)) {
151 val = 33000000;
152 }
153 if ((vclkh == 0x3F) && (vclkl == 0x20)) {
154 val = 40000000;
155 }
156 if ((vclkh == 0x3F) && (vclkl == 0x2A)) {
157 val = 50000000;
158 }
159 if ((vclkh == 0x24) && (vclkl == 0x04)) {
160 val = 66000000;
161 }
162 if ((vclkh == 0x3F) && (vclkl == 0x4B)) {
163 val = 83000000;
164 }
165 if ((vclkh == 0x3F) && (vclkl == 0x5C)) {
166 val = 100000000;
167 }
168 if ((vclkh == 0xDF) && (vclkl == 0x3B)) {
169 val = 134000000;
170 }
171 if ((vclkh == 0xDF) && (vclkl == 0x4B)) {
172 val = 166000000;
173 }
174
175 return val;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500176}
177
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500178
179/*
Jon Loeligerdebb7352006-04-26 17:58:56 -0500180 * get_board_sys_clk
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500181 * Reads the FPGA on board for CONFIG_SYS_CLK_FREQ
182 */
Jon Loeligerdebb7352006-04-26 17:58:56 -0500183
184unsigned long get_board_sys_clk(ulong dummy)
185{
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500186 u8 i, go_bit, rd_clks;
187 ulong val;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500188
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500189 go_bit = in8(PIXIS_BASE + PIXIS_VCTL);
190 go_bit &= 0x01;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500191
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500192 rd_clks = in8(PIXIS_BASE + PIXIS_VCFGEN0);
193 rd_clks &= 0x1C;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500194
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500195 /*
196 * Only if both go bit and the SCLK bit in VCFGEN0 are set
197 * should we be using the AUX register. Remember, we also set the
198 * GO bit to boot from the alternate bank on the on-board flash
199 */
200
201 if (go_bit) {
202 if (rd_clks == 0x1c)
203 i = in8(PIXIS_BASE + PIXIS_AUX);
204 else
205 i = in8(PIXIS_BASE + PIXIS_SPD);
206 } else {
207 i = in8(PIXIS_BASE + PIXIS_SPD);
208 }
209
210 i &= 0x07;
211
212 switch (i) {
213 case 0:
214 val = 33000000;
215 break;
216 case 1:
217 val = 40000000;
218 break;
219 case 2:
220 val = 50000000;
221 break;
222 case 3:
223 val = 66000000;
224 break;
225 case 4:
226 val = 83000000;
227 break;
228 case 5:
229 val = 100000000;
230 break;
231 case 6:
232 val = 134000000;
233 break;
234 case 7:
235 val = 166000000;
236 break;
237 }
238
239 return val;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500240}