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