blob: 5e05ab81f1b9cf71cb131a74bbd610041c37652d [file] [log] [blame]
Jon Loeligerdebb7352006-04-26 17:58:56 -05001/*
2 * Copyright 2004 Freescale Semiconductor.
Jon Loeligerc934f652006-05-31 13:55:35 -05003 * Jeff Brown
Jon Loeligerdebb7352006-04-26 17:58:56 -05004 * 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
Jon Loeligerdebb7352006-04-26 17:58:56 -050032
Jon Loeliger5c9efb32006-04-27 10:15:16 -050033void get_sys_info (sys_info_t *sysInfo)
Jon Loeligerdebb7352006-04-26 17:58:56 -050034{
35 volatile immap_t *immap = (immap_t *)CFG_IMMR;
36 volatile ccsr_gur_t *gur = &immap->im_gur;
37 uint plat_ratio, e600_ratio;
38
Jon Loeligerc934f652006-05-31 13:55:35 -050039 plat_ratio = (gur->porpllsr) & 0x0000003e;
Jon Loeligerdebb7352006-04-26 17:58:56 -050040 plat_ratio >>= 1;
Jon Loeliger5c9efb32006-04-27 10:15:16 -050041
Jon Loeligerdebb7352006-04-26 17:58:56 -050042 switch(plat_ratio) {
Jon Loeligerc934f652006-05-31 13:55:35 -050043 case 0x0:
Jon Loeligerdebb7352006-04-26 17:58:56 -050044 sysInfo->freqSystemBus = 16 * CONFIG_SYS_CLK_FREQ;
45 break;
46 case 0x02:
47 case 0x03:
48 case 0x04:
49 case 0x05:
50 case 0x06:
51 case 0x08:
52 case 0x09:
53 case 0x0a:
54 case 0x0c:
Jon Loeligerc934f652006-05-31 13:55:35 -050055 case 0x10:
56 sysInfo->freqSystemBus = plat_ratio * CONFIG_SYS_CLK_FREQ;
57 break;
Jon Loeligerdebb7352006-04-26 17:58:56 -050058 default:
59 sysInfo->freqSystemBus = 0;
60 break;
61 }
62
Jon Loeligerdebb7352006-04-26 17:58:56 -050063 e600_ratio = (gur->porpllsr) & 0x003f0000;
64 e600_ratio >>= 16;
Jon Loeliger5c9efb32006-04-27 10:15:16 -050065
66 switch (e600_ratio) {
Jon Loeligerdebb7352006-04-26 17:58:56 -050067 case 0x10:
Jon Loeliger5c9efb32006-04-27 10:15:16 -050068 sysInfo->freqProcessor = 2 * sysInfo->freqSystemBus;
Jon Loeligerdebb7352006-04-26 17:58:56 -050069 break;
Jon Loeligerc934f652006-05-31 13:55:35 -050070 case 0x19:
Jon Loeliger5c9efb32006-04-27 10:15:16 -050071 sysInfo->freqProcessor = 5 * sysInfo->freqSystemBus/2;
Jon Loeligerdebb7352006-04-26 17:58:56 -050072 break;
73 case 0x20:
Jon Loeliger5c9efb32006-04-27 10:15:16 -050074 sysInfo->freqProcessor = 3 * sysInfo->freqSystemBus;
Jon Loeligerdebb7352006-04-26 17:58:56 -050075 break;
Jon Loeligerc934f652006-05-31 13:55:35 -050076 case 0x39:
Jon Loeliger5c9efb32006-04-27 10:15:16 -050077 sysInfo->freqProcessor = 7 * sysInfo->freqSystemBus/2;
Jon Loeligerdebb7352006-04-26 17:58:56 -050078 break;
79 case 0x28:
Jon Loeliger5c9efb32006-04-27 10:15:16 -050080 sysInfo->freqProcessor = 4 * sysInfo->freqSystemBus;
Jon Loeligerdebb7352006-04-26 17:58:56 -050081 break;
82 case 0x1d:
Jon Loeliger5c9efb32006-04-27 10:15:16 -050083 sysInfo->freqProcessor = 9 * sysInfo->freqSystemBus/2;
Jon Loeligerdebb7352006-04-26 17:58:56 -050084 break;
Jon Loeligerc934f652006-05-31 13:55:35 -050085 default:
Jon Loeliger5c9efb32006-04-27 10:15:16 -050086 sysInfo->freqProcessor = e600_ratio + sysInfo->freqSystemBus;
Jon Loeligerdebb7352006-04-26 17:58:56 -050087 break;
88 }
Jon Loeligerdebb7352006-04-26 17:58:56 -050089}
90
91
Jon Loeligerdebb7352006-04-26 17:58:56 -050092/*
93 * Measure CPU clock speed (core clock GCLK1, GCLK2)
Jon Loeligerdebb7352006-04-26 17:58:56 -050094 * (Approx. GCLK frequency in Hz)
95 */
96
Jon Loeliger5c9efb32006-04-27 10:15:16 -050097int get_clocks(void)
Jon Loeligerdebb7352006-04-26 17:58:56 -050098{
99 DECLARE_GLOBAL_DATA_PTR;
100 sys_info_t sys_info;
101
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500102 get_sys_info(&sys_info);
Jon Loeligerdebb7352006-04-26 17:58:56 -0500103 gd->cpu_clk = sys_info.freqProcessor;
104 gd->bus_clk = sys_info.freqSystemBus;
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500105
106 if (gd->cpu_clk != 0)
107 return 0;
108 else
109 return 1;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500110}
111
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500112
113/*
Jon Loeligerdebb7352006-04-26 17:58:56 -0500114 * get_bus_freq
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500115 * Return system bus freq in Hz
116 */
Jon Loeligerc934f652006-05-31 13:55:35 -0500117
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500118ulong get_bus_freq(ulong dummy)
Jon Loeligerdebb7352006-04-26 17:58:56 -0500119{
120 ulong val;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500121 sys_info_t sys_info;
122
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500123 get_sys_info(&sys_info);
Jon Loeligerdebb7352006-04-26 17:58:56 -0500124 val = sys_info.freqSystemBus;
125
126 return val;
127}
128
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500129
130/*
Jon Loeligerdebb7352006-04-26 17:58:56 -0500131 * get_board_sys_clk
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500132 * Reads the FPGA on board for CONFIG_SYS_CLK_FREQ
133 */
Jon Loeligerdebb7352006-04-26 17:58:56 -0500134
135unsigned long get_board_sys_clk(ulong dummy)
136{
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500137 u8 i, go_bit, rd_clks;
138 ulong val;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500139
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500140 go_bit = in8(PIXIS_BASE + PIXIS_VCTL);
141 go_bit &= 0x01;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500142
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500143 rd_clks = in8(PIXIS_BASE + PIXIS_VCFGEN0);
144 rd_clks &= 0x1C;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500145
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500146 /*
147 * Only if both go bit and the SCLK bit in VCFGEN0 are set
148 * should we be using the AUX register. Remember, we also set the
149 * GO bit to boot from the alternate bank on the on-board flash
150 */
151
152 if (go_bit) {
153 if (rd_clks == 0x1c)
154 i = in8(PIXIS_BASE + PIXIS_AUX);
155 else
156 i = in8(PIXIS_BASE + PIXIS_SPD);
157 } else {
158 i = in8(PIXIS_BASE + PIXIS_SPD);
159 }
160
161 i &= 0x07;
162
163 switch (i) {
164 case 0:
165 val = 33000000;
166 break;
167 case 1:
168 val = 40000000;
169 break;
170 case 2:
171 val = 50000000;
172 break;
173 case 3:
174 val = 66000000;
175 break;
176 case 4:
177 val = 83000000;
178 break;
179 case 5:
180 val = 100000000;
181 break;
182 case 6:
183 val = 134000000;
184 break;
185 case 7:
186 val = 166000000;
187 break;
188 }
189
190 return val;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500191}