]> 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 (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
32 unsigned long get_board_sys_clk(ulong dummy);
33 unsigned long get_sysclk_from_px_regs(void);
34
35
36 void get_sys_info (sys_info_t *sysInfo)
37 {
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;
44
45         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
66 #if 0
67         printf("assigned system bus freq = %d for plat ratio 0x%08lx\n",
68                sysInfo->freqSystemBus, plat_ratio);
69 #endif
70
71         e600_ratio = (gur->porpllsr) & 0x003f0000;
72         e600_ratio >>= 16;
73
74         switch (e600_ratio) {
75         case 0x10:
76                 sysInfo->freqProcessor = 2 * sysInfo->freqSystemBus;
77                 break;
78         case 0x19:
79                 sysInfo->freqProcessor = 5 * sysInfo->freqSystemBus/2;
80                 break;
81         case 0x20:
82                 sysInfo->freqProcessor = 3 * sysInfo->freqSystemBus;
83                 break;
84         case 0x39:
85                 sysInfo->freqProcessor = 7 * sysInfo->freqSystemBus/2;
86                 break;
87         case 0x28:
88                 sysInfo->freqProcessor = 4 * sysInfo->freqSystemBus;
89                 break;
90         case 0x1d:
91                 sysInfo->freqProcessor = 9 * sysInfo->freqSystemBus/2;
92                 break;
93         default:
94                 /* JB - Emulator workaround until real cop is plugged in */
95                 /* sysInfo->freqProcessor = 3 * sysInfo->freqSystemBus; */
96                 sysInfo->freqProcessor = e600_ratio + sysInfo->freqSystemBus;
97                 break;
98         }
99 #if 0
100         printf("assigned processor freq = %d for e600 ratio 0x%08lx\n",
101                sysInfo->freqProcessor, e600_ratio);
102 #endif
103 }
104
105
106 /*
107  * Measure CPU clock speed (core clock GCLK1, GCLK2)
108  * (Approx. GCLK frequency in Hz)
109  */
110
111 int get_clocks(void)
112 {
113         DECLARE_GLOBAL_DATA_PTR;
114         sys_info_t sys_info;
115
116         get_sys_info(&sys_info);
117         gd->cpu_clk = sys_info.freqProcessor;
118         gd->bus_clk = sys_info.freqSystemBus;
119
120         if (gd->cpu_clk != 0)
121                 return 0;
122         else
123                 return 1;
124 }
125
126
127 /*
128  * get_bus_freq
129  *      Return system bus freq in Hz
130  */
131 ulong get_bus_freq(ulong dummy)
132 {
133         ulong val;
134         sys_info_t sys_info;
135
136         get_sys_info(&sys_info);
137         val = sys_info.freqSystemBus;
138
139         return val;
140 }
141
142 unsigned long get_sysclk_from_px_regs()
143 {
144         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;
176 }
177
178
179 /*
180  * get_board_sys_clk
181  *      Reads the FPGA on board for CONFIG_SYS_CLK_FREQ
182  */
183
184 unsigned long get_board_sys_clk(ulong dummy)
185 {
186         u8 i, go_bit, rd_clks;
187         ulong val;
188
189         go_bit = in8(PIXIS_BASE + PIXIS_VCTL);
190         go_bit &= 0x01;
191
192         rd_clks = in8(PIXIS_BASE + PIXIS_VCFGEN0);
193         rd_clks &= 0x1C;
194
195         /*
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;
240 }