]> git.sur5r.net Git - u-boot/blob - cpu/mpc86xx/speed.c
Merge branch 'mpc86xx'
[u-boot] / cpu / mpc86xx / speed.c
1 /*
2  * Copyright 2004 Freescale Semiconductor.
3  * Jeff Brown
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
32
33 /*
34  * get_board_sys_clk
35  *      Reads the FPGA on board for CONFIG_SYS_CLK_FREQ
36  */
37
38 unsigned long get_board_sys_clk(ulong dummy)
39 {
40         u8 i, go_bit, rd_clks;
41         ulong val = 0;
42
43         go_bit = in8(PIXIS_BASE + PIXIS_VCTL);
44         go_bit &= 0x01;
45
46         rd_clks = in8(PIXIS_BASE + PIXIS_VCFGEN0);
47         rd_clks &= 0x1C;
48
49         /*
50          * Only if both go bit and the SCLK bit in VCFGEN0 are set
51          * should we be using the AUX register. Remember, we also set the
52          * GO bit to boot from the alternate bank on the on-board flash
53          */
54
55         if (go_bit) {
56                 if (rd_clks == 0x1c)
57                         i = in8(PIXIS_BASE + PIXIS_AUX);
58                 else
59                         i = in8(PIXIS_BASE + PIXIS_SPD);
60         } else {
61                 i = in8(PIXIS_BASE + PIXIS_SPD);
62         }
63
64         i &= 0x07;
65
66         switch (i) {
67         case 0:
68                 val = 33000000;
69                 break;
70         case 1:
71                 val = 40000000;
72                 break;
73         case 2:
74                 val = 50000000;
75                 break;
76         case 3:
77                 val = 66000000;
78                 break;
79         case 4:
80                 val = 83000000;
81                 break;
82         case 5:
83                 val = 100000000;
84                 break;
85         case 6:
86                 val = 134000000;
87                 break;
88         case 7:
89                 val = 166000000;
90                 break;
91         }
92
93         return val;
94 }
95
96
97 void get_sys_info (sys_info_t *sysInfo)
98 {
99         volatile immap_t    *immap = (immap_t *)CFG_IMMR;
100         volatile ccsr_gur_t *gur = &immap->im_gur;
101         uint plat_ratio, e600_ratio;
102
103         plat_ratio = (gur->porpllsr) & 0x0000003e;
104         plat_ratio >>= 1;
105
106         switch(plat_ratio) {
107         case 0x0:
108                 sysInfo->freqSystemBus = 16 * CONFIG_SYS_CLK_FREQ;
109                 break;
110         case 0x02:
111         case 0x03:
112         case 0x04:
113         case 0x05:
114         case 0x06:
115         case 0x08:
116         case 0x09:
117         case 0x0a:
118         case 0x0c:
119         case 0x10:
120                 sysInfo->freqSystemBus = plat_ratio * CONFIG_SYS_CLK_FREQ;
121                 break;
122         default:
123                 sysInfo->freqSystemBus = 0;
124                 break;
125         }
126
127         e600_ratio = (gur->porpllsr) & 0x003f0000;
128         e600_ratio >>= 16;
129
130         switch (e600_ratio) {
131         case 0x10:
132                 sysInfo->freqProcessor = 2 * sysInfo->freqSystemBus;
133                 break;
134         case 0x19:
135                 sysInfo->freqProcessor = 5 * sysInfo->freqSystemBus/2;
136                 break;
137         case 0x20:
138                 sysInfo->freqProcessor = 3 * sysInfo->freqSystemBus;
139                 break;
140         case 0x39:
141                 sysInfo->freqProcessor = 7 * sysInfo->freqSystemBus/2;
142                 break;
143         case 0x28:
144                 sysInfo->freqProcessor = 4 * sysInfo->freqSystemBus;
145                 break;
146         case 0x1d:
147                 sysInfo->freqProcessor = 9 * sysInfo->freqSystemBus/2;
148                 break;
149         default:
150                 sysInfo->freqProcessor = e600_ratio + sysInfo->freqSystemBus;
151                 break;
152         }
153 }
154
155
156 /*
157  * Measure CPU clock speed (core clock GCLK1, GCLK2)
158  * (Approx. GCLK frequency in Hz)
159  */
160
161 int get_clocks(void)
162 {
163         DECLARE_GLOBAL_DATA_PTR;
164         sys_info_t sys_info;
165
166         get_sys_info(&sys_info);
167         gd->cpu_clk = sys_info.freqProcessor;
168         gd->bus_clk = sys_info.freqSystemBus;
169
170         if (gd->cpu_clk != 0)
171                 return 0;
172         else
173                 return 1;
174 }
175
176
177 /*
178  * get_bus_freq
179  *      Return system bus freq in Hz
180  */
181
182 ulong get_bus_freq(ulong dummy)
183 {
184         ulong val;
185         sys_info_t sys_info;
186
187         get_sys_info(&sys_info);
188         val = sys_info.freqSystemBus;
189
190         return val;
191 }