MINI2440: Updated early nand loader
[u-boot-openmoko/mini2440.git] / cpu / mpc86xx / speed.c
blob7e884f8e0142334c96bf15996199d1f6d75d2a76
1 /*
2 * Copyright 2004 Freescale Semiconductor.
3 * Jeff Brown
4 * Srikanth Srinivasan (srikanth.srinivasan@freescale.com)
6 * (C) Copyright 2000-2002
7 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
9 * See file CREDITS for list of people who contributed to this
10 * project.
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.
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.
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
28 #include <common.h>
29 #include <mpc86xx.h>
30 #include <asm/processor.h>
32 DECLARE_GLOBAL_DATA_PTR;
34 /* used in some defintiions of CONFIG_SYS_CLK_FREQ */
35 extern unsigned long get_board_sys_clk(unsigned long dummy);
37 void get_sys_info(sys_info_t *sysInfo)
39 volatile immap_t *immap = (immap_t *) CFG_IMMR;
40 volatile ccsr_gur_t *gur = &immap->im_gur;
41 uint plat_ratio, e600_ratio;
43 plat_ratio = (gur->porpllsr) & 0x0000003e;
44 plat_ratio >>= 1;
46 switch (plat_ratio) {
47 case 0x0:
48 sysInfo->freqSystemBus = 16 * CONFIG_SYS_CLK_FREQ;
49 break;
50 case 0x02:
51 case 0x03:
52 case 0x04:
53 case 0x05:
54 case 0x06:
55 case 0x08:
56 case 0x09:
57 case 0x0a:
58 case 0x0c:
59 case 0x10:
60 sysInfo->freqSystemBus = plat_ratio * CONFIG_SYS_CLK_FREQ;
61 break;
62 default:
63 sysInfo->freqSystemBus = 0;
64 break;
67 e600_ratio = (gur->porpllsr) & 0x003f0000;
68 e600_ratio >>= 16;
70 switch (e600_ratio) {
71 case 0x10:
72 sysInfo->freqProcessor = 2 * sysInfo->freqSystemBus;
73 break;
74 case 0x19:
75 sysInfo->freqProcessor = 5 * sysInfo->freqSystemBus / 2;
76 break;
77 case 0x20:
78 sysInfo->freqProcessor = 3 * sysInfo->freqSystemBus;
79 break;
80 case 0x39:
81 sysInfo->freqProcessor = 7 * sysInfo->freqSystemBus / 2;
82 break;
83 case 0x28:
84 sysInfo->freqProcessor = 4 * sysInfo->freqSystemBus;
85 break;
86 case 0x1d:
87 sysInfo->freqProcessor = 9 * sysInfo->freqSystemBus / 2;
88 break;
89 default:
90 sysInfo->freqProcessor = e600_ratio + sysInfo->freqSystemBus;
91 break;
97 * Measure CPU clock speed (core clock GCLK1, GCLK2)
98 * (Approx. GCLK frequency in Hz)
101 int get_clocks(void)
103 sys_info_t sys_info;
105 get_sys_info(&sys_info);
106 gd->cpu_clk = sys_info.freqProcessor;
107 gd->bus_clk = sys_info.freqSystemBus;
108 gd->i2c1_clk = sys_info.freqSystemBus;
109 gd->i2c2_clk = sys_info.freqSystemBus;
111 if (gd->cpu_clk != 0)
112 return 0;
113 else
114 return 1;
119 * get_bus_freq
120 * Return system bus freq in Hz
123 ulong get_bus_freq(ulong dummy)
125 ulong val;
126 sys_info_t sys_info;
128 get_sys_info(&sys_info);
129 val = sys_info.freqSystemBus;
131 return val;