blob: ad6b3f669fb38c77cda40e491c66e3370f0e5c5b [file] [log] [blame]
Eran Liberty9095d4a2005-07-28 10:08:46 -05001/*
2 * (C) Copyright 2000-2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * Copyright 2004 Freescale Semiconductor, Inc.
6 *
7 * See file CREDITS for list of people who contributed to this
8 * project.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 * MA 02111-1307 USA
24 *
25 * Change log:
26 *
27 * 20050101: Eran Liberty (liberty@freescale.com)
28 * Initial file creating (porting from 85XX & 8260)
29 */
30
31#include <common.h>
32#include <mpc83xx.h>
33#include <asm/processor.h>
34
Wolfgang Denk6405a152006-03-31 18:32:53 +020035DECLARE_GLOBAL_DATA_PTR;
36
Eran Liberty9095d4a2005-07-28 10:08:46 -050037/* ----------------------------------------------------------------- */
38
39typedef enum {
40 _unk,
41 _off,
42 _byp,
43 _x8,
44 _x4,
45 _x2,
46 _x1,
47 _1x,
48 _1_5x,
49 _2x,
50 _2_5x,
51 _3x
52} mult_t;
53
54typedef struct {
55 mult_t core_csb_ratio;
56 mult_t vco_divider;
57} corecnf_t;
58
59corecnf_t corecnf_tab[] = {
60 { _byp, _byp}, /* 0x00 */
61 { _byp, _byp}, /* 0x01 */
62 { _byp, _byp}, /* 0x02 */
63 { _byp, _byp}, /* 0x03 */
64 { _byp, _byp}, /* 0x04 */
65 { _byp, _byp}, /* 0x05 */
66 { _byp, _byp}, /* 0x06 */
67 { _byp, _byp}, /* 0x07 */
68 { _1x, _x2}, /* 0x08 */
69 { _1x, _x4}, /* 0x09 */
70 { _1x, _x8}, /* 0x0A */
71 { _1x, _x8}, /* 0x0B */
72 {_1_5x, _x2}, /* 0x0C */
73 {_1_5x, _x4}, /* 0x0D */
74 {_1_5x, _x8}, /* 0x0E */
75 {_1_5x, _x8}, /* 0x0F */
76 { _2x, _x2}, /* 0x10 */
77 { _2x, _x4}, /* 0x11 */
78 { _2x, _x8}, /* 0x12 */
79 { _2x, _x8}, /* 0x13 */
80 {_2_5x, _x2}, /* 0x14 */
81 {_2_5x, _x4}, /* 0x15 */
82 {_2_5x, _x8}, /* 0x16 */
83 {_2_5x, _x8}, /* 0x17 */
84 { _3x, _x2}, /* 0x18 */
85 { _3x, _x4}, /* 0x19 */
86 { _3x, _x8}, /* 0x1A */
87 { _3x, _x8}, /* 0x1B */
88};
89
90/* ----------------------------------------------------------------- */
91
92/*
93 *
94 */
95int get_clocks (void)
96{
Eran Liberty9095d4a2005-07-28 10:08:46 -050097 volatile immap_t *im = (immap_t *)CFG_IMMRBAR;
98 u32 pci_sync_in;
99 u8 spmf;
100 u8 clkin_div;
101 u32 sccr;
102 u32 corecnf_tab_index;
103 u8 corepll;
104 u32 lcrr;
Jon Loeligerebc72242005-08-01 13:20:47 -0500105
Eran Liberty9095d4a2005-07-28 10:08:46 -0500106 u32 csb_clk;
107 u32 tsec1_clk;
108 u32 tsec2_clk;
109 u32 core_clk;
110 u32 usbmph_clk;
111 u32 usbdr_clk;
112 u32 i2c_clk;
113 u32 enc_clk;
114 u32 lbiu_clk;
115 u32 lclk_clk;
116 u32 ddr_clk;
Jon Loeligerebc72242005-08-01 13:20:47 -0500117
Eran Liberty9095d4a2005-07-28 10:08:46 -0500118 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im)
119 return -1;
Jon Loeligerebc72242005-08-01 13:20:47 -0500120
Eran Liberty9095d4a2005-07-28 10:08:46 -0500121#ifndef CFG_HRCW_HIGH
Marian Balakowicz513b4a12005-10-11 19:09:42 +0200122# error "CFG_HRCW_HIGH must be defined in board config file"
Eran Liberty9095d4a2005-07-28 10:08:46 -0500123#endif /* CFG_HCWD_HIGH */
124
125#if (CFG_HRCW_HIGH & HRCWH_PCI_HOST)
Marian Balakowicz513b4a12005-10-11 19:09:42 +0200126
Eran Liberty9095d4a2005-07-28 10:08:46 -0500127# ifndef CONFIG_83XX_CLKIN
Marian Balakowicz513b4a12005-10-11 19:09:42 +0200128# error "In PCI Host Mode, CONFIG_83XX_CLKIN must be defined in board config file"
Eran Liberty9095d4a2005-07-28 10:08:46 -0500129# endif /* CONFIG_83XX_CLKIN */
130# ifdef CONFIG_83XX_PCICLK
Marian Balakowicz513b4a12005-10-11 19:09:42 +0200131# warning "In PCI Host Mode, CONFIG_83XX_PCICLK in board config file is igonred"
Eran Liberty9095d4a2005-07-28 10:08:46 -0500132# endif /* CONFIG_83XX_PCICLK */
Marian Balakowicz513b4a12005-10-11 19:09:42 +0200133
134 /* PCI Host Mode */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500135 if (!(im->reset.rcwh & RCWH_PCIHOST)) {
Wolfgang Denkf6a692b2005-12-04 00:40:34 +0100136 /* though RCWH_PCIHOST is defined in CFG_HRCW_HIGH
Marian Balakowicz513b4a12005-10-11 19:09:42 +0200137 * the im->reset.rcwhr PCI Host Mode is disabled
138 * FIXME: findout if there is a way to issue some warning */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500139 return -2;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500140 }
141 if (im->clk.spmr & SPMR_CKID) {
Marian Balakowicz513b4a12005-10-11 19:09:42 +0200142 /* PCI Clock is half CONFIG_83XX_CLKIN */
143 pci_sync_in = CONFIG_83XX_CLKIN / 2;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500144 }
145 else {
146 pci_sync_in = CONFIG_83XX_CLKIN;
147 }
Marian Balakowicz513b4a12005-10-11 19:09:42 +0200148
149#else /* (CFG_HRCW_HIGH & HRCWH_PCI_HOST) */
150
Eran Liberty9095d4a2005-07-28 10:08:46 -0500151# ifdef CONFIG_83XX_CLKIN
Marian Balakowicz513b4a12005-10-11 19:09:42 +0200152# warning "In PCI Agent Mode, CONFIG_83XX_CLKIN in board config file is igonred"
Eran Liberty9095d4a2005-07-28 10:08:46 -0500153# endif /* CONFIG_83XX_CLKIN */
154# ifndef CONFIG_83XX_PCICLK
Marian Balakowicz513b4a12005-10-11 19:09:42 +0200155# error "In PCI Agent Mode, CONFIG_83XX_PCICLK must be defined in board config file"
Eran Liberty9095d4a2005-07-28 10:08:46 -0500156# endif /* CONFIG_83XX_PCICLK */
Marian Balakowicz513b4a12005-10-11 19:09:42 +0200157
158 /* PCI Agent Mode */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500159 if (im->reset.rcwh & RCWH_PCIHOST) {
Wolfgang Denkf6a692b2005-12-04 00:40:34 +0100160 /* though RCWH_PCIHOST is not defined in CFG_HRCW_HIGH
Marian Balakowicz513b4a12005-10-11 19:09:42 +0200161 * the im->reset.rcwhr PCI Host Mode is enabled */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500162 return -3;
163 }
164 pci_sync_in = CONFIG_83XX_PCICLK;
Marian Balakowicz513b4a12005-10-11 19:09:42 +0200165
Eran Liberty9095d4a2005-07-28 10:08:46 -0500166#endif /* (CFG_HRCW_HIGH | RCWH_PCIHOST) */
167
168 /* we have up to date pci_sync_in */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500169 spmf = ((im->reset.rcwl & RCWL_SPMF) >> RCWL_SPMF_SHIFT);
170 clkin_div = ((im->clk.spmr & SPMR_CKID) >> SPMR_CKID_SHIFT);
Jon Loeligerebc72242005-08-01 13:20:47 -0500171
Eran Liberty9095d4a2005-07-28 10:08:46 -0500172 if ((im->reset.rcwl & RCWL_LBIUCM) || (im->reset.rcwl & RCWL_DDRCM)) {
173 csb_clk = (pci_sync_in * spmf * (1 + clkin_div)) / 2;
174 }
175 else {
176 csb_clk = pci_sync_in * spmf * (1 + clkin_div);
177 }
Jon Loeligerebc72242005-08-01 13:20:47 -0500178
Eran Liberty9095d4a2005-07-28 10:08:46 -0500179 sccr = im->clk.sccr;
180 switch ((sccr & SCCR_TSEC1CM) >> SCCR_TSEC1CM_SHIFT) {
181 case 0:
182 tsec1_clk = 0;
183 break;
184 case 1:
185 tsec1_clk = csb_clk;
186 break;
187 case 2:
188 tsec1_clk = csb_clk / 2;
189 break;
190 case 3:
191 tsec1_clk = csb_clk / 3;
192 break;
193 default:
194 /* unkown SCCR_TSEC1CM value */
195 return -4;
196 }
Jon Loeligerebc72242005-08-01 13:20:47 -0500197
Eran Liberty9095d4a2005-07-28 10:08:46 -0500198 switch ((sccr & SCCR_TSEC2CM) >> SCCR_TSEC2CM_SHIFT) {
199 case 0:
200 tsec2_clk = 0;
201 break;
202 case 1:
203 tsec2_clk = csb_clk;
204 break;
205 case 2:
206 tsec2_clk = csb_clk / 2;
207 break;
208 case 3:
209 tsec2_clk = csb_clk / 3;
210 break;
211 default:
212 /* unkown SCCR_TSEC2CM value */
213 return -5;
214 }
215 i2c_clk = tsec2_clk;
Jon Loeligerebc72242005-08-01 13:20:47 -0500216
Eran Liberty9095d4a2005-07-28 10:08:46 -0500217 switch ((sccr & SCCR_ENCCM) >> SCCR_ENCCM_SHIFT) {
218 case 0:
219 enc_clk = 0;
220 break;
221 case 1:
222 enc_clk = csb_clk;
223 break;
224 case 2:
225 enc_clk = csb_clk / 2;
226 break;
227 case 3:
228 enc_clk = csb_clk / 3;
229 break;
230 default:
231 /* unkown SCCR_ENCCM value */
232 return -6;
233 }
Jon Loeligerebc72242005-08-01 13:20:47 -0500234
Eran Liberty9095d4a2005-07-28 10:08:46 -0500235 switch ((sccr & SCCR_USBMPHCM) >> SCCR_USBMPHCM_SHIFT) {
236 case 0:
237 usbmph_clk = 0;
238 break;
239 case 1:
240 usbmph_clk = csb_clk;
241 break;
242 case 2:
243 usbmph_clk = csb_clk / 2;
244 break;
245 case 3:
246 usbmph_clk = csb_clk / 3;
247 break;
248 default:
249 /* unkown SCCR_USBMPHCM value */
250 return -7;
251 }
252
253 switch ((sccr & SCCR_USBDRCM) >> SCCR_USBDRCM_SHIFT) {
254 case 0:
255 usbdr_clk = 0;
256 break;
257 case 1:
258 usbdr_clk = csb_clk;
259 break;
260 case 2:
261 usbdr_clk = csb_clk / 2;
262 break;
263 case 3:
264 usbdr_clk = csb_clk / 3;
265 break;
266 default:
267 /* unkown SCCR_USBDRCM value */
268 return -8;
269 }
Jon Loeligerebc72242005-08-01 13:20:47 -0500270
Eran Liberty9095d4a2005-07-28 10:08:46 -0500271 if (usbmph_clk != 0
272 && usbdr_clk != 0
273 && usbmph_clk != usbdr_clk ) {
274 /* if USB MPH clock is not disabled and USB DR clock is not disabled than USB MPH & USB DR must have the same rate */
275 return -9;
276 }
Jon Loeligerebc72242005-08-01 13:20:47 -0500277
Eran Liberty9095d4a2005-07-28 10:08:46 -0500278 lbiu_clk = csb_clk * (1 + ((im->reset.rcwl & RCWL_LBIUCM) >> RCWL_LBIUCM_SHIFT));
279 lcrr = (im->lbus.lcrr & LCRR_CLKDIV) >> LCRR_CLKDIV_SHIFT;
280 switch (lcrr) {
281 case 2:
282 case 4:
283 case 8:
284 lclk_clk = lbiu_clk / lcrr;
285 break;
286 default:
287 /* unknown lcrr */
288 return -10;
289 }
Jon Loeligerebc72242005-08-01 13:20:47 -0500290
Eran Liberty9095d4a2005-07-28 10:08:46 -0500291 ddr_clk = csb_clk * (1 + ((im->reset.rcwl & RCWL_DDRCM) >> RCWL_DDRCM_SHIFT));
Jon Loeligerebc72242005-08-01 13:20:47 -0500292
Eran Liberty9095d4a2005-07-28 10:08:46 -0500293 corepll = (im->reset.rcwl & RCWL_COREPLL) >> RCWL_COREPLL_SHIFT;
294 corecnf_tab_index = ((corepll & 0x1F) << 2) | ((corepll & 0x60) >> 5);
295 if (corecnf_tab_index > (sizeof(corecnf_tab)/sizeof(corecnf_t)) ) {
296 /* corecnf_tab_index is too high, possibly worng value */
297 return -11;
298 }
299 switch (corecnf_tab[corecnf_tab_index].core_csb_ratio) {
300 case _byp:
301 case _x1:
302 case _1x:
303 core_clk = csb_clk;
304 break;
305 case _1_5x:
306 core_clk = (3 * csb_clk) / 2;
307 break;
308 case _2x:
309 core_clk = 2 * csb_clk;
310 break;
311 case _2_5x:
312 core_clk = ( 5 * csb_clk) / 2;
313 break;
314 case _3x:
315 core_clk = 3 * csb_clk;
316 break;
317 default:
318 /* unkown core to csb ratio */
319 return -12;
320 }
Jon Loeligerebc72242005-08-01 13:20:47 -0500321
Eran Liberty9095d4a2005-07-28 10:08:46 -0500322 gd->csb_clk = csb_clk ;
323 gd->tsec1_clk = tsec1_clk ;
324 gd->tsec2_clk = tsec2_clk ;
325 gd->core_clk = core_clk ;
326 gd->usbmph_clk = usbmph_clk;
327 gd->usbdr_clk = usbdr_clk ;
328 gd->i2c_clk = i2c_clk ;
Jon Loeligerebc72242005-08-01 13:20:47 -0500329 gd->enc_clk = enc_clk ;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500330 gd->lbiu_clk = lbiu_clk ;
331 gd->lclk_clk = lclk_clk ;
332 gd->ddr_clk = ddr_clk ;
Rafal Jaworowski384da5e2005-10-17 02:39:53 +0200333 gd->pci_clk = pci_sync_in;
Jon Loeligerebc72242005-08-01 13:20:47 -0500334
Eran Liberty9095d4a2005-07-28 10:08:46 -0500335 gd->cpu_clk = gd->core_clk;
336 gd->bus_clk = gd->lbiu_clk;
337 return 0;
338}
339
340/********************************************
341 * get_bus_freq
342 * return system bus freq in Hz
343 *********************************************/
344ulong get_bus_freq (ulong dummy)
345{
Eran Liberty9095d4a2005-07-28 10:08:46 -0500346 return gd->csb_clk;
347}
348
349int print_clock_conf (void)
350{
Eran Liberty9095d4a2005-07-28 10:08:46 -0500351 printf("Clock configuration:\n");
352 printf(" Coherent System Bus: %4d MHz\n",gd->csb_clk/1000000);
353 printf(" Core: %4d MHz\n",gd->core_clk/1000000);
Marian Balakowicz513b4a12005-10-11 19:09:42 +0200354 debug(" Local Bus Controller:%4d MHz\n",gd->lbiu_clk/1000000);
Eran Liberty9095d4a2005-07-28 10:08:46 -0500355 printf(" Local Bus: %4d MHz\n",gd->lclk_clk/1000000);
Marian Balakowicz513b4a12005-10-11 19:09:42 +0200356 debug(" DDR: %4d MHz\n",gd->ddr_clk/1000000);
357 debug(" I2C: %4d MHz\n",gd->i2c_clk/1000000);
358 debug(" TSEC1: %4d MHz\n",gd->tsec1_clk/1000000);
359 debug(" TSEC2: %4d MHz\n",gd->tsec2_clk/1000000);
360 debug(" USB MPH: %4d MHz\n",gd->usbmph_clk/1000000);
361 debug(" USB DR: %4d MHz\n",gd->usbdr_clk/1000000);
Eran Liberty9095d4a2005-07-28 10:08:46 -0500362
Jon Loeligerebc72242005-08-01 13:20:47 -0500363 return 0;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500364}