blob: 33835682a883b9e6beecfa7474166b56ec217a61 [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 *
Dave Liu5245ff52007-09-18 12:36:11 +08005 * Copyright (C) 2004-2007 Freescale Semiconductor, Inc.
Eran Liberty9095d4a2005-07-28 10:08:46 -05006 *
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
Eran Liberty9095d4a2005-07-28 10:08:46 -050024 */
25
26#include <common.h>
27#include <mpc83xx.h>
Kim Phillipsd82b0772007-04-30 15:26:21 -050028#include <command.h>
Eran Liberty9095d4a2005-07-28 10:08:46 -050029#include <asm/processor.h>
30
Wolfgang Denk6405a152006-03-31 18:32:53 +020031DECLARE_GLOBAL_DATA_PTR;
32
Eran Liberty9095d4a2005-07-28 10:08:46 -050033/* ----------------------------------------------------------------- */
34
35typedef enum {
36 _unk,
37 _off,
38 _byp,
39 _x8,
40 _x4,
41 _x2,
42 _x1,
43 _1x,
44 _1_5x,
45 _2x,
46 _2_5x,
47 _3x
48} mult_t;
49
50typedef struct {
51 mult_t core_csb_ratio;
Kim Phillipsbae24792006-11-02 19:47:11 -060052 mult_t vco_divider;
Eran Liberty9095d4a2005-07-28 10:08:46 -050053} corecnf_t;
54
55corecnf_t corecnf_tab[] = {
Kim Phillipsbae24792006-11-02 19:47:11 -060056 {_byp, _byp}, /* 0x00 */
57 {_byp, _byp}, /* 0x01 */
58 {_byp, _byp}, /* 0x02 */
59 {_byp, _byp}, /* 0x03 */
60 {_byp, _byp}, /* 0x04 */
61 {_byp, _byp}, /* 0x05 */
62 {_byp, _byp}, /* 0x06 */
63 {_byp, _byp}, /* 0x07 */
64 {_1x, _x2}, /* 0x08 */
65 {_1x, _x4}, /* 0x09 */
66 {_1x, _x8}, /* 0x0A */
67 {_1x, _x8}, /* 0x0B */
68 {_1_5x, _x2}, /* 0x0C */
69 {_1_5x, _x4}, /* 0x0D */
70 {_1_5x, _x8}, /* 0x0E */
71 {_1_5x, _x8}, /* 0x0F */
72 {_2x, _x2}, /* 0x10 */
73 {_2x, _x4}, /* 0x11 */
74 {_2x, _x8}, /* 0x12 */
75 {_2x, _x8}, /* 0x13 */
76 {_2_5x, _x2}, /* 0x14 */
77 {_2_5x, _x4}, /* 0x15 */
78 {_2_5x, _x8}, /* 0x16 */
79 {_2_5x, _x8}, /* 0x17 */
80 {_3x, _x2}, /* 0x18 */
81 {_3x, _x4}, /* 0x19 */
82 {_3x, _x8}, /* 0x1A */
83 {_3x, _x8}, /* 0x1B */
Eran Liberty9095d4a2005-07-28 10:08:46 -050084};
85
86/* ----------------------------------------------------------------- */
87
88/*
89 *
90 */
Kim Phillipsbae24792006-11-02 19:47:11 -060091int get_clocks(void)
Eran Liberty9095d4a2005-07-28 10:08:46 -050092{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020093 volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
Eran Liberty9095d4a2005-07-28 10:08:46 -050094 u32 pci_sync_in;
Kim Phillipsbae24792006-11-02 19:47:11 -060095 u8 spmf;
96 u8 clkin_div;
Eran Liberty9095d4a2005-07-28 10:08:46 -050097 u32 sccr;
98 u32 corecnf_tab_index;
Kim Phillipsbae24792006-11-02 19:47:11 -060099 u8 corepll;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500100 u32 lcrr;
Jon Loeligerebc72242005-08-01 13:20:47 -0500101
Eran Liberty9095d4a2005-07-28 10:08:46 -0500102 u32 csb_clk;
Ilya Yanoka3e5fd52010-06-28 16:44:33 +0400103#if defined(CONFIG_MPC8308) || defined(CONFIG_MPC831x) || \
104 defined(CONFIG_MPC834x) || defined(CONFIG_MPC837x)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500105 u32 tsec1_clk;
106 u32 tsec2_clk;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500107 u32 usbdr_clk;
Dave Liua46daea2006-11-03 19:33:44 -0600108#endif
Peter Tyser72f2d392009-05-22 17:23:25 -0500109#ifdef CONFIG_MPC834x
Scott Woodc036fc92007-04-16 14:34:19 -0500110 u32 usbmph_clk;
111#endif
Dave Liua46daea2006-11-03 19:33:44 -0600112 u32 core_clk;
113 u32 i2c1_clk;
Peter Tyser72f2d392009-05-22 17:23:25 -0500114#if !defined(CONFIG_MPC832x)
Dave Liua46daea2006-11-03 19:33:44 -0600115 u32 i2c2_clk;
Dave Liue740c462006-12-07 21:13:15 +0800116#endif
Dave Liue0cfec82007-09-18 12:36:58 +0800117#if defined(CONFIG_MPC8315)
118 u32 tdm_clk;
119#endif
Rini van Zettena2496172010-04-15 16:03:05 +0200120#if defined(CONFIG_FSL_ESDHC)
Dave Liu5245ff52007-09-18 12:36:11 +0800121 u32 sdhc_clk;
122#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500123 u32 enc_clk;
124 u32 lbiu_clk;
125 u32 lclk_clk;
Kim Phillipsc02cf1e2008-03-28 10:18:40 -0500126 u32 mem_clk;
Dave Liue740c462006-12-07 21:13:15 +0800127#if defined(CONFIG_MPC8360)
Kim Phillipsc02cf1e2008-03-28 10:18:40 -0500128 u32 mem_sec_clk;
Dave Liue740c462006-12-07 21:13:15 +0800129#endif
Gerlando Falauto77cf2832012-10-10 22:13:06 +0000130#if defined(CONFIG_QE)
Dave Liua46daea2006-11-03 19:33:44 -0600131 u32 qepmf;
132 u32 qepdf;
Dave Liua46daea2006-11-03 19:33:44 -0600133 u32 qe_clk;
134 u32 brg_clk;
135#endif
Ilya Yanoka3e5fd52010-06-28 16:44:33 +0400136#if defined(CONFIG_MPC8308) || defined(CONFIG_MPC831x) || \
137 defined(CONFIG_MPC837x)
Dave Liu5245ff52007-09-18 12:36:11 +0800138 u32 pciexp1_clk;
139 u32 pciexp2_clk;
Dave Liue0cfec82007-09-18 12:36:58 +0800140#endif
Peter Tyser72f2d392009-05-22 17:23:25 -0500141#if defined(CONFIG_MPC837x) || defined(CONFIG_MPC8315)
Dave Liu5245ff52007-09-18 12:36:11 +0800142 u32 sata_clk;
143#endif
Jon Loeligerebc72242005-08-01 13:20:47 -0500144
Kim Phillipsbae24792006-11-02 19:47:11 -0600145 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500146 return -1;
Jon Loeligerebc72242005-08-01 13:20:47 -0500147
Dave Liua46daea2006-11-03 19:33:44 -0600148 clkin_div = ((im->clk.spmr & SPMR_CKID) >> SPMR_CKID_SHIFT);
Marian Balakowicz513b4a12005-10-11 19:09:42 +0200149
Dave Liua46daea2006-11-03 19:33:44 -0600150 if (im->reset.rcwh & HRCWH_PCI_HOST) {
151#if defined(CONFIG_83XX_CLKIN)
152 pci_sync_in = CONFIG_83XX_CLKIN / (1 + clkin_div);
153#else
154 pci_sync_in = 0xDEADBEEF;
155#endif
156 } else {
157#if defined(CONFIG_83XX_PCICLK)
158 pci_sync_in = CONFIG_83XX_PCICLK;
159#else
160 pci_sync_in = 0xDEADBEEF;
161#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500162 }
Marian Balakowicz513b4a12005-10-11 19:09:42 +0200163
Joakim Tjernlundf2af1bb2011-01-27 16:30:54 +0100164 spmf = (im->clk.spmr & SPMR_SPMF) >> SPMR_SPMF_SHIFT;
Dave Liua46daea2006-11-03 19:33:44 -0600165 csb_clk = pci_sync_in * (1 + clkin_div) * spmf;
Jon Loeligerebc72242005-08-01 13:20:47 -0500166
Eran Liberty9095d4a2005-07-28 10:08:46 -0500167 sccr = im->clk.sccr;
Dave Liua46daea2006-11-03 19:33:44 -0600168
Ilya Yanoka3e5fd52010-06-28 16:44:33 +0400169#if defined(CONFIG_MPC8308) || defined(CONFIG_MPC831x) || \
170 defined(CONFIG_MPC834x) || defined(CONFIG_MPC837x)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500171 switch ((sccr & SCCR_TSEC1CM) >> SCCR_TSEC1CM_SHIFT) {
172 case 0:
173 tsec1_clk = 0;
174 break;
175 case 1:
176 tsec1_clk = csb_clk;
177 break;
178 case 2:
179 tsec1_clk = csb_clk / 2;
180 break;
181 case 3:
182 tsec1_clk = csb_clk / 3;
183 break;
184 default:
185 /* unkown SCCR_TSEC1CM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800186 return -2;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500187 }
Jon Loeligerebc72242005-08-01 13:20:47 -0500188
Scott Woodc036fc92007-04-16 14:34:19 -0500189 switch ((sccr & SCCR_USBDRCM) >> SCCR_USBDRCM_SHIFT) {
190 case 0:
191 usbdr_clk = 0;
192 break;
193 case 1:
194 usbdr_clk = csb_clk;
195 break;
196 case 2:
197 usbdr_clk = csb_clk / 2;
198 break;
199 case 3:
200 usbdr_clk = csb_clk / 3;
201 break;
202 default:
203 /* unkown SCCR_USBDRCM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800204 return -3;
Scott Woodc036fc92007-04-16 14:34:19 -0500205 }
206#endif
207
Ilya Yanoka3e5fd52010-06-28 16:44:33 +0400208#if defined(CONFIG_MPC8308) || defined(CONFIG_MPC8315) || \
209 defined(CONFIG_MPC834x) || defined(CONFIG_MPC837x)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500210 switch ((sccr & SCCR_TSEC2CM) >> SCCR_TSEC2CM_SHIFT) {
211 case 0:
212 tsec2_clk = 0;
213 break;
214 case 1:
215 tsec2_clk = csb_clk;
216 break;
217 case 2:
218 tsec2_clk = csb_clk / 2;
219 break;
220 case 3:
221 tsec2_clk = csb_clk / 3;
222 break;
223 default:
224 /* unkown SCCR_TSEC2CM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800225 return -4;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500226 }
Dave Liue0cfec82007-09-18 12:36:58 +0800227#elif defined(CONFIG_MPC8313)
Dave Liu5245ff52007-09-18 12:36:11 +0800228 tsec2_clk = tsec1_clk;
Jon Loeligerebc72242005-08-01 13:20:47 -0500229
Dave Liu5245ff52007-09-18 12:36:11 +0800230 if (!(sccr & SCCR_TSEC1ON))
231 tsec1_clk = 0;
232 if (!(sccr & SCCR_TSEC2ON))
233 tsec2_clk = 0;
234#endif
Jon Loeligerebc72242005-08-01 13:20:47 -0500235
Peter Tyser72f2d392009-05-22 17:23:25 -0500236#if defined(CONFIG_MPC834x)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500237 switch ((sccr & SCCR_USBMPHCM) >> SCCR_USBMPHCM_SHIFT) {
238 case 0:
239 usbmph_clk = 0;
240 break;
241 case 1:
242 usbmph_clk = csb_clk;
243 break;
244 case 2:
245 usbmph_clk = csb_clk / 2;
246 break;
247 case 3:
248 usbmph_clk = csb_clk / 3;
249 break;
250 default:
251 /* unkown SCCR_USBMPHCM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800252 return -5;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500253 }
254
Kim Phillipsbae24792006-11-02 19:47:11 -0600255 if (usbmph_clk != 0 && usbdr_clk != 0 && usbmph_clk != usbdr_clk) {
256 /* if USB MPH clock is not disabled and
257 * USB DR clock is not disabled then
258 * USB MPH & USB DR must have the same rate
259 */
Dave Liu5245ff52007-09-18 12:36:11 +0800260 return -6;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500261 }
Dave Liu5245ff52007-09-18 12:36:11 +0800262#endif
263 switch ((sccr & SCCR_ENCCM) >> SCCR_ENCCM_SHIFT) {
264 case 0:
265 enc_clk = 0;
266 break;
267 case 1:
268 enc_clk = csb_clk;
269 break;
270 case 2:
271 enc_clk = csb_clk / 2;
272 break;
273 case 3:
274 enc_clk = csb_clk / 3;
275 break;
276 default:
277 /* unkown SCCR_ENCCM value */
278 return -7;
279 }
Scott Woodc036fc92007-04-16 14:34:19 -0500280
Rini van Zettena2496172010-04-15 16:03:05 +0200281#if defined(CONFIG_FSL_ESDHC)
Dave Liu5245ff52007-09-18 12:36:11 +0800282 switch ((sccr & SCCR_SDHCCM) >> SCCR_SDHCCM_SHIFT) {
283 case 0:
284 sdhc_clk = 0;
285 break;
286 case 1:
287 sdhc_clk = csb_clk;
288 break;
289 case 2:
290 sdhc_clk = csb_clk / 2;
291 break;
292 case 3:
293 sdhc_clk = csb_clk / 3;
294 break;
295 default:
296 /* unkown SCCR_SDHCCM value */
297 return -8;
298 }
Dave Liua46daea2006-11-03 19:33:44 -0600299#endif
Dave Liue0cfec82007-09-18 12:36:58 +0800300#if defined(CONFIG_MPC8315)
301 switch ((sccr & SCCR_TDMCM) >> SCCR_TDMCM_SHIFT) {
302 case 0:
303 tdm_clk = 0;
304 break;
305 case 1:
306 tdm_clk = csb_clk;
307 break;
308 case 2:
309 tdm_clk = csb_clk / 2;
310 break;
311 case 3:
312 tdm_clk = csb_clk / 3;
313 break;
314 default:
315 /* unkown SCCR_TDMCM value */
316 return -8;
317 }
318#endif
Scott Woodc036fc92007-04-16 14:34:19 -0500319
Peter Tyser72f2d392009-05-22 17:23:25 -0500320#if defined(CONFIG_MPC834x)
Dave Liu5245ff52007-09-18 12:36:11 +0800321 i2c1_clk = tsec2_clk;
322#elif defined(CONFIG_MPC8360)
Dave Liua46daea2006-11-03 19:33:44 -0600323 i2c1_clk = csb_clk;
Peter Tyser72f2d392009-05-22 17:23:25 -0500324#elif defined(CONFIG_MPC832x)
Dave Liu5245ff52007-09-18 12:36:11 +0800325 i2c1_clk = enc_clk;
Ilya Yanoka3e5fd52010-06-28 16:44:33 +0400326#elif defined(CONFIG_MPC8308) || defined(CONFIG_MPC831x)
Dave Liu5245ff52007-09-18 12:36:11 +0800327 i2c1_clk = enc_clk;
Rini van Zettena2496172010-04-15 16:03:05 +0200328#elif defined(CONFIG_FSL_ESDHC)
Dave Liu5245ff52007-09-18 12:36:11 +0800329 i2c1_clk = sdhc_clk;
Andre Schwarza76cc612011-04-14 14:57:40 +0200330#elif defined(CONFIG_MPC837x)
331 i2c1_clk = enc_clk;
Dave Liua46daea2006-11-03 19:33:44 -0600332#endif
Peter Tyser72f2d392009-05-22 17:23:25 -0500333#if !defined(CONFIG_MPC832x)
Dave Liu5245ff52007-09-18 12:36:11 +0800334 i2c2_clk = csb_clk; /* i2c-2 clk is equal to csb clk */
Dave Liue740c462006-12-07 21:13:15 +0800335#endif
Jon Loeligerebc72242005-08-01 13:20:47 -0500336
Ilya Yanoka3e5fd52010-06-28 16:44:33 +0400337#if defined(CONFIG_MPC8308) || defined(CONFIG_MPC831x) || \
338 defined(CONFIG_MPC837x)
Dave Liu5245ff52007-09-18 12:36:11 +0800339 switch ((sccr & SCCR_PCIEXP1CM) >> SCCR_PCIEXP1CM_SHIFT) {
Dave Liua46daea2006-11-03 19:33:44 -0600340 case 0:
Dave Liu5245ff52007-09-18 12:36:11 +0800341 pciexp1_clk = 0;
Dave Liua46daea2006-11-03 19:33:44 -0600342 break;
343 case 1:
Dave Liu5245ff52007-09-18 12:36:11 +0800344 pciexp1_clk = csb_clk;
Dave Liua46daea2006-11-03 19:33:44 -0600345 break;
346 case 2:
Dave Liu5245ff52007-09-18 12:36:11 +0800347 pciexp1_clk = csb_clk / 2;
Dave Liua46daea2006-11-03 19:33:44 -0600348 break;
349 case 3:
Dave Liu5245ff52007-09-18 12:36:11 +0800350 pciexp1_clk = csb_clk / 3;
Dave Liua46daea2006-11-03 19:33:44 -0600351 break;
352 default:
Dave Liu5245ff52007-09-18 12:36:11 +0800353 /* unkown SCCR_PCIEXP1CM value */
354 return -9;
Dave Liua46daea2006-11-03 19:33:44 -0600355 }
Dave Liue740c462006-12-07 21:13:15 +0800356
Dave Liu5245ff52007-09-18 12:36:11 +0800357 switch ((sccr & SCCR_PCIEXP2CM) >> SCCR_PCIEXP2CM_SHIFT) {
358 case 0:
359 pciexp2_clk = 0;
360 break;
361 case 1:
362 pciexp2_clk = csb_clk;
363 break;
364 case 2:
365 pciexp2_clk = csb_clk / 2;
366 break;
367 case 3:
368 pciexp2_clk = csb_clk / 3;
369 break;
370 default:
371 /* unkown SCCR_PCIEXP2CM value */
372 return -10;
373 }
374#endif
375
Peter Tyser72f2d392009-05-22 17:23:25 -0500376#if defined(CONFIG_MPC837x) || defined(CONFIG_MPC8315)
Dave Liub7896ad2008-01-17 18:23:19 +0800377 switch ((sccr & SCCR_SATA1CM) >> SCCR_SATA1CM_SHIFT) {
378 case 0:
Dave Liu5245ff52007-09-18 12:36:11 +0800379 sata_clk = 0;
380 break;
Dave Liub7896ad2008-01-17 18:23:19 +0800381 case 1:
Dave Liu5245ff52007-09-18 12:36:11 +0800382 sata_clk = csb_clk;
383 break;
Dave Liub7896ad2008-01-17 18:23:19 +0800384 case 2:
Dave Liu5245ff52007-09-18 12:36:11 +0800385 sata_clk = csb_clk / 2;
386 break;
Dave Liub7896ad2008-01-17 18:23:19 +0800387 case 3:
Dave Liu5245ff52007-09-18 12:36:11 +0800388 sata_clk = csb_clk / 3;
389 break;
390 default:
Kim Phillips19a91de2008-01-16 12:06:16 -0600391 /* unkown SCCR_SATACM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800392 return -11;
393 }
394#endif
395
Kim Phillipsbae24792006-11-02 19:47:11 -0600396 lbiu_clk = csb_clk *
Joakim Tjernlundf2af1bb2011-01-27 16:30:54 +0100397 (1 + ((im->clk.spmr & SPMR_LBIUCM) >> SPMR_LBIUCM_SHIFT));
Becky Bruce0d4cee12010-06-17 11:37:20 -0500398 lcrr = (im->im_lbc.lcrr & LCRR_CLKDIV) >> LCRR_CLKDIV_SHIFT;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500399 switch (lcrr) {
400 case 2:
401 case 4:
402 case 8:
403 lclk_clk = lbiu_clk / lcrr;
404 break;
405 default:
406 /* unknown lcrr */
Dave Liu5245ff52007-09-18 12:36:11 +0800407 return -12;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500408 }
Dave Liue740c462006-12-07 21:13:15 +0800409
Kim Phillipsc02cf1e2008-03-28 10:18:40 -0500410 mem_clk = csb_clk *
Joakim Tjernlundf2af1bb2011-01-27 16:30:54 +0100411 (1 + ((im->clk.spmr & SPMR_DDRCM) >> SPMR_DDRCM_SHIFT));
412 corepll = (im->clk.spmr & SPMR_COREPLL) >> SPMR_COREPLL_SHIFT;
413
Dave Liue740c462006-12-07 21:13:15 +0800414#if defined(CONFIG_MPC8360)
Kim Phillipsc02cf1e2008-03-28 10:18:40 -0500415 mem_sec_clk = csb_clk * (1 +
Joakim Tjernlundf2af1bb2011-01-27 16:30:54 +0100416 ((im->clk.spmr & SPMR_LBIUCM) >> SPMR_LBIUCM_SHIFT));
Dave Liua46daea2006-11-03 19:33:44 -0600417#endif
Dave Liua46daea2006-11-03 19:33:44 -0600418
Eran Liberty9095d4a2005-07-28 10:08:46 -0500419 corecnf_tab_index = ((corepll & 0x1F) << 2) | ((corepll & 0x60) >> 5);
Kim Phillipsbae24792006-11-02 19:47:11 -0600420 if (corecnf_tab_index > (sizeof(corecnf_tab) / sizeof(corecnf_t))) {
Eran Liberty9095d4a2005-07-28 10:08:46 -0500421 /* corecnf_tab_index is too high, possibly worng value */
422 return -11;
423 }
424 switch (corecnf_tab[corecnf_tab_index].core_csb_ratio) {
425 case _byp:
426 case _x1:
427 case _1x:
428 core_clk = csb_clk;
429 break;
430 case _1_5x:
431 core_clk = (3 * csb_clk) / 2;
432 break;
433 case _2x:
434 core_clk = 2 * csb_clk;
435 break;
436 case _2_5x:
Kim Phillipsbae24792006-11-02 19:47:11 -0600437 core_clk = (5 * csb_clk) / 2;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500438 break;
439 case _3x:
440 core_clk = 3 * csb_clk;
441 break;
442 default:
443 /* unkown core to csb ratio */
Dave Liu5245ff52007-09-18 12:36:11 +0800444 return -13;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500445 }
Jon Loeligerebc72242005-08-01 13:20:47 -0500446
Gerlando Falauto77cf2832012-10-10 22:13:06 +0000447#if defined(CONFIG_QE)
Joakim Tjernlundf2af1bb2011-01-27 16:30:54 +0100448 qepmf = (im->clk.spmr & SPMR_CEPMF) >> SPMR_CEPMF_SHIFT;
449 qepdf = (im->clk.spmr & SPMR_CEPDF) >> SPMR_CEPDF_SHIFT;
Kim Phillipsbae24792006-11-02 19:47:11 -0600450 qe_clk = (pci_sync_in * qepmf) / (1 + qepdf);
Dave Liua46daea2006-11-03 19:33:44 -0600451 brg_clk = qe_clk / 2;
452#endif
Jon Loeligerebc72242005-08-01 13:20:47 -0500453
Kim Phillipsbae24792006-11-02 19:47:11 -0600454 gd->csb_clk = csb_clk;
Ilya Yanoka3e5fd52010-06-28 16:44:33 +0400455#if defined(CONFIG_MPC8308) || defined(CONFIG_MPC831x) || \
456 defined(CONFIG_MPC834x) || defined(CONFIG_MPC837x)
Kim Phillipsbae24792006-11-02 19:47:11 -0600457 gd->tsec1_clk = tsec1_clk;
458 gd->tsec2_clk = tsec2_clk;
Kim Phillipsbae24792006-11-02 19:47:11 -0600459 gd->usbdr_clk = usbdr_clk;
Dave Liua46daea2006-11-03 19:33:44 -0600460#endif
Peter Tyser72f2d392009-05-22 17:23:25 -0500461#if defined(CONFIG_MPC834x)
Scott Woodc036fc92007-04-16 14:34:19 -0500462 gd->usbmph_clk = usbmph_clk;
463#endif
Dave Liue0cfec82007-09-18 12:36:58 +0800464#if defined(CONFIG_MPC8315)
465 gd->tdm_clk = tdm_clk;
466#endif
Rini van Zettena2496172010-04-15 16:03:05 +0200467#if defined(CONFIG_FSL_ESDHC)
Dave Liu5245ff52007-09-18 12:36:11 +0800468 gd->sdhc_clk = sdhc_clk;
469#endif
Kim Phillipsbae24792006-11-02 19:47:11 -0600470 gd->core_clk = core_clk;
471 gd->i2c1_clk = i2c1_clk;
Peter Tyser72f2d392009-05-22 17:23:25 -0500472#if !defined(CONFIG_MPC832x)
Kim Phillipsbae24792006-11-02 19:47:11 -0600473 gd->i2c2_clk = i2c2_clk;
Dave Liue740c462006-12-07 21:13:15 +0800474#endif
Kim Phillipsbae24792006-11-02 19:47:11 -0600475 gd->enc_clk = enc_clk;
476 gd->lbiu_clk = lbiu_clk;
477 gd->lclk_clk = lclk_clk;
Kim Phillipsc02cf1e2008-03-28 10:18:40 -0500478 gd->mem_clk = mem_clk;
Dave Liue740c462006-12-07 21:13:15 +0800479#if defined(CONFIG_MPC8360)
Kim Phillipsc02cf1e2008-03-28 10:18:40 -0500480 gd->mem_sec_clk = mem_sec_clk;
Dave Liue740c462006-12-07 21:13:15 +0800481#endif
Gerlando Falauto77cf2832012-10-10 22:13:06 +0000482#if defined(CONFIG_QE)
Kim Phillipsbae24792006-11-02 19:47:11 -0600483 gd->qe_clk = qe_clk;
484 gd->brg_clk = brg_clk;
Dave Liua46daea2006-11-03 19:33:44 -0600485#endif
Bill Cook5a043d92011-05-25 15:51:07 -0400486#if defined(CONFIG_MPC8308) || defined(CONFIG_MPC831x) || \
487 defined(CONFIG_MPC837x)
Dave Liu5245ff52007-09-18 12:36:11 +0800488 gd->pciexp1_clk = pciexp1_clk;
489 gd->pciexp2_clk = pciexp2_clk;
Dave Liue0cfec82007-09-18 12:36:58 +0800490#endif
Peter Tyser72f2d392009-05-22 17:23:25 -0500491#if defined(CONFIG_MPC837x) || defined(CONFIG_MPC8315)
Dave Liu5245ff52007-09-18 12:36:11 +0800492 gd->sata_clk = sata_clk;
493#endif
Kim Phillipscd9fd702007-08-15 22:30:19 -0500494 gd->pci_clk = pci_sync_in;
Kim Phillipsbae24792006-11-02 19:47:11 -0600495 gd->cpu_clk = gd->core_clk;
496 gd->bus_clk = gd->csb_clk;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500497 return 0;
Dave Liua46daea2006-11-03 19:33:44 -0600498
Eran Liberty9095d4a2005-07-28 10:08:46 -0500499}
500
501/********************************************
502 * get_bus_freq
503 * return system bus freq in Hz
504 *********************************************/
Kim Phillipsbae24792006-11-02 19:47:11 -0600505ulong get_bus_freq(ulong dummy)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500506{
Eran Liberty9095d4a2005-07-28 10:08:46 -0500507 return gd->csb_clk;
508}
509
York Sune12ce982011-08-26 11:32:44 -0700510/********************************************
511 * get_ddr_freq
512 * return ddr bus freq in Hz
513 *********************************************/
514ulong get_ddr_freq(ulong dummy)
515{
516 return gd->mem_clk;
517}
518
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200519int do_clocks (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
Eran Liberty9095d4a2005-07-28 10:08:46 -0500520{
Wolfgang Denk20591042008-10-19 02:35:49 +0200521 char buf[32];
522
Eran Liberty9095d4a2005-07-28 10:08:46 -0500523 printf("Clock configuration:\n");
Wolfgang Denk20591042008-10-19 02:35:49 +0200524 printf(" Core: %-4s MHz\n", strmhz(buf, gd->core_clk));
525 printf(" Coherent System Bus: %-4s MHz\n", strmhz(buf, gd->csb_clk));
Gerlando Falauto77cf2832012-10-10 22:13:06 +0000526#if defined(CONFIG_QE)
Wolfgang Denk20591042008-10-19 02:35:49 +0200527 printf(" QE: %-4s MHz\n", strmhz(buf, gd->qe_clk));
528 printf(" BRG: %-4s MHz\n", strmhz(buf, gd->brg_clk));
Dave Liua46daea2006-11-03 19:33:44 -0600529#endif
Wolfgang Denk20591042008-10-19 02:35:49 +0200530 printf(" Local Bus Controller:%-4s MHz\n", strmhz(buf, gd->lbiu_clk));
531 printf(" Local Bus: %-4s MHz\n", strmhz(buf, gd->lclk_clk));
532 printf(" DDR: %-4s MHz\n", strmhz(buf, gd->mem_clk));
Dave Liue740c462006-12-07 21:13:15 +0800533#if defined(CONFIG_MPC8360)
Wolfgang Denk20591042008-10-19 02:35:49 +0200534 printf(" DDR Secondary: %-4s MHz\n", strmhz(buf, gd->mem_sec_clk));
Dave Liua46daea2006-11-03 19:33:44 -0600535#endif
Wolfgang Denk20591042008-10-19 02:35:49 +0200536 printf(" SEC: %-4s MHz\n", strmhz(buf, gd->enc_clk));
537 printf(" I2C1: %-4s MHz\n", strmhz(buf, gd->i2c1_clk));
Peter Tyser72f2d392009-05-22 17:23:25 -0500538#if !defined(CONFIG_MPC832x)
Wolfgang Denk20591042008-10-19 02:35:49 +0200539 printf(" I2C2: %-4s MHz\n", strmhz(buf, gd->i2c2_clk));
Dave Liue740c462006-12-07 21:13:15 +0800540#endif
Dave Liue0cfec82007-09-18 12:36:58 +0800541#if defined(CONFIG_MPC8315)
Wolfgang Denk20591042008-10-19 02:35:49 +0200542 printf(" TDM: %-4s MHz\n", strmhz(buf, gd->tdm_clk));
Dave Liue0cfec82007-09-18 12:36:58 +0800543#endif
Rini van Zettena2496172010-04-15 16:03:05 +0200544#if defined(CONFIG_FSL_ESDHC)
Wolfgang Denk20591042008-10-19 02:35:49 +0200545 printf(" SDHC: %-4s MHz\n", strmhz(buf, gd->sdhc_clk));
Dave Liu5245ff52007-09-18 12:36:11 +0800546#endif
Ilya Yanoka3e5fd52010-06-28 16:44:33 +0400547#if defined(CONFIG_MPC8308) || defined(CONFIG_MPC831x) || \
548 defined(CONFIG_MPC834x) || defined(CONFIG_MPC837x)
Wolfgang Denk20591042008-10-19 02:35:49 +0200549 printf(" TSEC1: %-4s MHz\n", strmhz(buf, gd->tsec1_clk));
550 printf(" TSEC2: %-4s MHz\n", strmhz(buf, gd->tsec2_clk));
551 printf(" USB DR: %-4s MHz\n", strmhz(buf, gd->usbdr_clk));
Dave Liua46daea2006-11-03 19:33:44 -0600552#endif
Peter Tyser72f2d392009-05-22 17:23:25 -0500553#if defined(CONFIG_MPC834x)
Wolfgang Denk20591042008-10-19 02:35:49 +0200554 printf(" USB MPH: %-4s MHz\n", strmhz(buf, gd->usbmph_clk));
Scott Woodc036fc92007-04-16 14:34:19 -0500555#endif
Bill Cook5a043d92011-05-25 15:51:07 -0400556#if defined(CONFIG_MPC8308) || defined(CONFIG_MPC831x) || \
557 defined(CONFIG_MPC837x)
Wolfgang Denk20591042008-10-19 02:35:49 +0200558 printf(" PCIEXP1: %-4s MHz\n", strmhz(buf, gd->pciexp1_clk));
559 printf(" PCIEXP2: %-4s MHz\n", strmhz(buf, gd->pciexp2_clk));
Dave Liue0cfec82007-09-18 12:36:58 +0800560#endif
Peter Tyser72f2d392009-05-22 17:23:25 -0500561#if defined(CONFIG_MPC837x) || defined(CONFIG_MPC8315)
Wolfgang Denk20591042008-10-19 02:35:49 +0200562 printf(" SATA: %-4s MHz\n", strmhz(buf, gd->sata_clk));
Dave Liu5245ff52007-09-18 12:36:11 +0800563#endif
Jon Loeligerebc72242005-08-01 13:20:47 -0500564 return 0;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500565}
Kim Phillipsd82b0772007-04-30 15:26:21 -0500566
567U_BOOT_CMD(clocks, 1, 0, do_clocks,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600568 "print clock configuration",
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200569 " clocks"
Kim Phillipsd82b0772007-04-30 15:26:21 -0500570);