blob: b8c05d15929ce33800e9848a5419a50560633f17 [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
Kim Phillipsb5c312a2012-10-29 13:34:39 +000055static corecnf_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;
Gerlando Falautofe201cb2012-10-10 22:13:08 +0000108#elif defined(CONFIG_MPC8309)
109 u32 usbdr_clk;
Dave Liua46daea2006-11-03 19:33:44 -0600110#endif
Peter Tyser72f2d392009-05-22 17:23:25 -0500111#ifdef CONFIG_MPC834x
Scott Woodc036fc92007-04-16 14:34:19 -0500112 u32 usbmph_clk;
113#endif
Dave Liua46daea2006-11-03 19:33:44 -0600114 u32 core_clk;
115 u32 i2c1_clk;
Peter Tyser72f2d392009-05-22 17:23:25 -0500116#if !defined(CONFIG_MPC832x)
Dave Liua46daea2006-11-03 19:33:44 -0600117 u32 i2c2_clk;
Dave Liue740c462006-12-07 21:13:15 +0800118#endif
Dave Liue0cfec82007-09-18 12:36:58 +0800119#if defined(CONFIG_MPC8315)
120 u32 tdm_clk;
121#endif
Rini van Zettena2496172010-04-15 16:03:05 +0200122#if defined(CONFIG_FSL_ESDHC)
Dave Liu5245ff52007-09-18 12:36:11 +0800123 u32 sdhc_clk;
124#endif
Gerlando Falautofe201cb2012-10-10 22:13:08 +0000125#if !defined(CONFIG_MPC8309)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500126 u32 enc_clk;
Gerlando Falautofe201cb2012-10-10 22:13:08 +0000127#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500128 u32 lbiu_clk;
129 u32 lclk_clk;
Kim Phillipsc02cf1e2008-03-28 10:18:40 -0500130 u32 mem_clk;
Dave Liue740c462006-12-07 21:13:15 +0800131#if defined(CONFIG_MPC8360)
Kim Phillipsc02cf1e2008-03-28 10:18:40 -0500132 u32 mem_sec_clk;
Dave Liue740c462006-12-07 21:13:15 +0800133#endif
Gerlando Falauto77cf2832012-10-10 22:13:06 +0000134#if defined(CONFIG_QE)
Dave Liua46daea2006-11-03 19:33:44 -0600135 u32 qepmf;
136 u32 qepdf;
Dave Liua46daea2006-11-03 19:33:44 -0600137 u32 qe_clk;
138 u32 brg_clk;
139#endif
Ilya Yanoka3e5fd52010-06-28 16:44:33 +0400140#if defined(CONFIG_MPC8308) || defined(CONFIG_MPC831x) || \
141 defined(CONFIG_MPC837x)
Dave Liu5245ff52007-09-18 12:36:11 +0800142 u32 pciexp1_clk;
143 u32 pciexp2_clk;
Dave Liue0cfec82007-09-18 12:36:58 +0800144#endif
Peter Tyser72f2d392009-05-22 17:23:25 -0500145#if defined(CONFIG_MPC837x) || defined(CONFIG_MPC8315)
Dave Liu5245ff52007-09-18 12:36:11 +0800146 u32 sata_clk;
147#endif
Jon Loeligerebc72242005-08-01 13:20:47 -0500148
Kim Phillipsbae24792006-11-02 19:47:11 -0600149 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500150 return -1;
Jon Loeligerebc72242005-08-01 13:20:47 -0500151
Dave Liua46daea2006-11-03 19:33:44 -0600152 clkin_div = ((im->clk.spmr & SPMR_CKID) >> SPMR_CKID_SHIFT);
Marian Balakowicz513b4a12005-10-11 19:09:42 +0200153
Dave Liua46daea2006-11-03 19:33:44 -0600154 if (im->reset.rcwh & HRCWH_PCI_HOST) {
155#if defined(CONFIG_83XX_CLKIN)
156 pci_sync_in = CONFIG_83XX_CLKIN / (1 + clkin_div);
157#else
158 pci_sync_in = 0xDEADBEEF;
159#endif
160 } else {
161#if defined(CONFIG_83XX_PCICLK)
162 pci_sync_in = CONFIG_83XX_PCICLK;
163#else
164 pci_sync_in = 0xDEADBEEF;
165#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500166 }
Marian Balakowicz513b4a12005-10-11 19:09:42 +0200167
Joakim Tjernlundf2af1bb2011-01-27 16:30:54 +0100168 spmf = (im->clk.spmr & SPMR_SPMF) >> SPMR_SPMF_SHIFT;
Dave Liua46daea2006-11-03 19:33:44 -0600169 csb_clk = pci_sync_in * (1 + clkin_div) * spmf;
Jon Loeligerebc72242005-08-01 13:20:47 -0500170
Eran Liberty9095d4a2005-07-28 10:08:46 -0500171 sccr = im->clk.sccr;
Dave Liua46daea2006-11-03 19:33:44 -0600172
Ilya Yanoka3e5fd52010-06-28 16:44:33 +0400173#if defined(CONFIG_MPC8308) || defined(CONFIG_MPC831x) || \
174 defined(CONFIG_MPC834x) || defined(CONFIG_MPC837x)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500175 switch ((sccr & SCCR_TSEC1CM) >> SCCR_TSEC1CM_SHIFT) {
176 case 0:
177 tsec1_clk = 0;
178 break;
179 case 1:
180 tsec1_clk = csb_clk;
181 break;
182 case 2:
183 tsec1_clk = csb_clk / 2;
184 break;
185 case 3:
186 tsec1_clk = csb_clk / 3;
187 break;
188 default:
189 /* unkown SCCR_TSEC1CM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800190 return -2;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500191 }
Gerlando Falauto74735552012-10-10 22:13:07 +0000192#endif
Jon Loeligerebc72242005-08-01 13:20:47 -0500193
Gerlando Falauto74735552012-10-10 22:13:07 +0000194#if defined(CONFIG_MPC830x) || defined(CONFIG_MPC831x) || \
195 defined(CONFIG_MPC834x) || defined(CONFIG_MPC837x)
Scott Woodc036fc92007-04-16 14:34:19 -0500196 switch ((sccr & SCCR_USBDRCM) >> SCCR_USBDRCM_SHIFT) {
197 case 0:
198 usbdr_clk = 0;
199 break;
200 case 1:
201 usbdr_clk = csb_clk;
202 break;
203 case 2:
204 usbdr_clk = csb_clk / 2;
205 break;
206 case 3:
207 usbdr_clk = csb_clk / 3;
208 break;
209 default:
210 /* unkown SCCR_USBDRCM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800211 return -3;
Scott Woodc036fc92007-04-16 14:34:19 -0500212 }
213#endif
214
Ilya Yanoka3e5fd52010-06-28 16:44:33 +0400215#if defined(CONFIG_MPC8308) || defined(CONFIG_MPC8315) || \
216 defined(CONFIG_MPC834x) || defined(CONFIG_MPC837x)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500217 switch ((sccr & SCCR_TSEC2CM) >> SCCR_TSEC2CM_SHIFT) {
218 case 0:
219 tsec2_clk = 0;
220 break;
221 case 1:
222 tsec2_clk = csb_clk;
223 break;
224 case 2:
225 tsec2_clk = csb_clk / 2;
226 break;
227 case 3:
228 tsec2_clk = csb_clk / 3;
229 break;
230 default:
231 /* unkown SCCR_TSEC2CM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800232 return -4;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500233 }
Dave Liue0cfec82007-09-18 12:36:58 +0800234#elif defined(CONFIG_MPC8313)
Dave Liu5245ff52007-09-18 12:36:11 +0800235 tsec2_clk = tsec1_clk;
Jon Loeligerebc72242005-08-01 13:20:47 -0500236
Dave Liu5245ff52007-09-18 12:36:11 +0800237 if (!(sccr & SCCR_TSEC1ON))
238 tsec1_clk = 0;
239 if (!(sccr & SCCR_TSEC2ON))
240 tsec2_clk = 0;
241#endif
Jon Loeligerebc72242005-08-01 13:20:47 -0500242
Peter Tyser72f2d392009-05-22 17:23:25 -0500243#if defined(CONFIG_MPC834x)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500244 switch ((sccr & SCCR_USBMPHCM) >> SCCR_USBMPHCM_SHIFT) {
245 case 0:
246 usbmph_clk = 0;
247 break;
248 case 1:
249 usbmph_clk = csb_clk;
250 break;
251 case 2:
252 usbmph_clk = csb_clk / 2;
253 break;
254 case 3:
255 usbmph_clk = csb_clk / 3;
256 break;
257 default:
258 /* unkown SCCR_USBMPHCM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800259 return -5;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500260 }
261
Kim Phillipsbae24792006-11-02 19:47:11 -0600262 if (usbmph_clk != 0 && usbdr_clk != 0 && usbmph_clk != usbdr_clk) {
263 /* if USB MPH clock is not disabled and
264 * USB DR clock is not disabled then
265 * USB MPH & USB DR must have the same rate
266 */
Dave Liu5245ff52007-09-18 12:36:11 +0800267 return -6;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500268 }
Dave Liu5245ff52007-09-18 12:36:11 +0800269#endif
Gerlando Falautofe201cb2012-10-10 22:13:08 +0000270#if !defined(CONFIG_MPC8309)
Dave Liu5245ff52007-09-18 12:36:11 +0800271 switch ((sccr & SCCR_ENCCM) >> SCCR_ENCCM_SHIFT) {
272 case 0:
273 enc_clk = 0;
274 break;
275 case 1:
276 enc_clk = csb_clk;
277 break;
278 case 2:
279 enc_clk = csb_clk / 2;
280 break;
281 case 3:
282 enc_clk = csb_clk / 3;
283 break;
284 default:
285 /* unkown SCCR_ENCCM value */
286 return -7;
287 }
Gerlando Falautofe201cb2012-10-10 22:13:08 +0000288#endif
Scott Woodc036fc92007-04-16 14:34:19 -0500289
Rini van Zettena2496172010-04-15 16:03:05 +0200290#if defined(CONFIG_FSL_ESDHC)
Dave Liu5245ff52007-09-18 12:36:11 +0800291 switch ((sccr & SCCR_SDHCCM) >> SCCR_SDHCCM_SHIFT) {
292 case 0:
293 sdhc_clk = 0;
294 break;
295 case 1:
296 sdhc_clk = csb_clk;
297 break;
298 case 2:
299 sdhc_clk = csb_clk / 2;
300 break;
301 case 3:
302 sdhc_clk = csb_clk / 3;
303 break;
304 default:
305 /* unkown SCCR_SDHCCM value */
306 return -8;
307 }
Dave Liua46daea2006-11-03 19:33:44 -0600308#endif
Dave Liue0cfec82007-09-18 12:36:58 +0800309#if defined(CONFIG_MPC8315)
310 switch ((sccr & SCCR_TDMCM) >> SCCR_TDMCM_SHIFT) {
311 case 0:
312 tdm_clk = 0;
313 break;
314 case 1:
315 tdm_clk = csb_clk;
316 break;
317 case 2:
318 tdm_clk = csb_clk / 2;
319 break;
320 case 3:
321 tdm_clk = csb_clk / 3;
322 break;
323 default:
324 /* unkown SCCR_TDMCM value */
325 return -8;
326 }
327#endif
Scott Woodc036fc92007-04-16 14:34:19 -0500328
Peter Tyser72f2d392009-05-22 17:23:25 -0500329#if defined(CONFIG_MPC834x)
Dave Liu5245ff52007-09-18 12:36:11 +0800330 i2c1_clk = tsec2_clk;
331#elif defined(CONFIG_MPC8360)
Dave Liua46daea2006-11-03 19:33:44 -0600332 i2c1_clk = csb_clk;
Peter Tyser72f2d392009-05-22 17:23:25 -0500333#elif defined(CONFIG_MPC832x)
Dave Liu5245ff52007-09-18 12:36:11 +0800334 i2c1_clk = enc_clk;
Ilya Yanoka3e5fd52010-06-28 16:44:33 +0400335#elif defined(CONFIG_MPC8308) || defined(CONFIG_MPC831x)
Dave Liu5245ff52007-09-18 12:36:11 +0800336 i2c1_clk = enc_clk;
Rini van Zettena2496172010-04-15 16:03:05 +0200337#elif defined(CONFIG_FSL_ESDHC)
Dave Liu5245ff52007-09-18 12:36:11 +0800338 i2c1_clk = sdhc_clk;
Andre Schwarza76cc612011-04-14 14:57:40 +0200339#elif defined(CONFIG_MPC837x)
340 i2c1_clk = enc_clk;
Gerlando Falautofe201cb2012-10-10 22:13:08 +0000341#elif defined(CONFIG_MPC8309)
342 i2c1_clk = csb_clk;
Dave Liua46daea2006-11-03 19:33:44 -0600343#endif
Peter Tyser72f2d392009-05-22 17:23:25 -0500344#if !defined(CONFIG_MPC832x)
Dave Liu5245ff52007-09-18 12:36:11 +0800345 i2c2_clk = csb_clk; /* i2c-2 clk is equal to csb clk */
Dave Liue740c462006-12-07 21:13:15 +0800346#endif
Jon Loeligerebc72242005-08-01 13:20:47 -0500347
Ilya Yanoka3e5fd52010-06-28 16:44:33 +0400348#if defined(CONFIG_MPC8308) || defined(CONFIG_MPC831x) || \
349 defined(CONFIG_MPC837x)
Dave Liu5245ff52007-09-18 12:36:11 +0800350 switch ((sccr & SCCR_PCIEXP1CM) >> SCCR_PCIEXP1CM_SHIFT) {
Dave Liua46daea2006-11-03 19:33:44 -0600351 case 0:
Dave Liu5245ff52007-09-18 12:36:11 +0800352 pciexp1_clk = 0;
Dave Liua46daea2006-11-03 19:33:44 -0600353 break;
354 case 1:
Dave Liu5245ff52007-09-18 12:36:11 +0800355 pciexp1_clk = csb_clk;
Dave Liua46daea2006-11-03 19:33:44 -0600356 break;
357 case 2:
Dave Liu5245ff52007-09-18 12:36:11 +0800358 pciexp1_clk = csb_clk / 2;
Dave Liua46daea2006-11-03 19:33:44 -0600359 break;
360 case 3:
Dave Liu5245ff52007-09-18 12:36:11 +0800361 pciexp1_clk = csb_clk / 3;
Dave Liua46daea2006-11-03 19:33:44 -0600362 break;
363 default:
Dave Liu5245ff52007-09-18 12:36:11 +0800364 /* unkown SCCR_PCIEXP1CM value */
365 return -9;
Dave Liua46daea2006-11-03 19:33:44 -0600366 }
Dave Liue740c462006-12-07 21:13:15 +0800367
Dave Liu5245ff52007-09-18 12:36:11 +0800368 switch ((sccr & SCCR_PCIEXP2CM) >> SCCR_PCIEXP2CM_SHIFT) {
369 case 0:
370 pciexp2_clk = 0;
371 break;
372 case 1:
373 pciexp2_clk = csb_clk;
374 break;
375 case 2:
376 pciexp2_clk = csb_clk / 2;
377 break;
378 case 3:
379 pciexp2_clk = csb_clk / 3;
380 break;
381 default:
382 /* unkown SCCR_PCIEXP2CM value */
383 return -10;
384 }
385#endif
386
Peter Tyser72f2d392009-05-22 17:23:25 -0500387#if defined(CONFIG_MPC837x) || defined(CONFIG_MPC8315)
Dave Liub7896ad2008-01-17 18:23:19 +0800388 switch ((sccr & SCCR_SATA1CM) >> SCCR_SATA1CM_SHIFT) {
389 case 0:
Dave Liu5245ff52007-09-18 12:36:11 +0800390 sata_clk = 0;
391 break;
Dave Liub7896ad2008-01-17 18:23:19 +0800392 case 1:
Dave Liu5245ff52007-09-18 12:36:11 +0800393 sata_clk = csb_clk;
394 break;
Dave Liub7896ad2008-01-17 18:23:19 +0800395 case 2:
Dave Liu5245ff52007-09-18 12:36:11 +0800396 sata_clk = csb_clk / 2;
397 break;
Dave Liub7896ad2008-01-17 18:23:19 +0800398 case 3:
Dave Liu5245ff52007-09-18 12:36:11 +0800399 sata_clk = csb_clk / 3;
400 break;
401 default:
Kim Phillips19a91de2008-01-16 12:06:16 -0600402 /* unkown SCCR_SATACM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800403 return -11;
404 }
405#endif
406
Kim Phillipsbae24792006-11-02 19:47:11 -0600407 lbiu_clk = csb_clk *
Joakim Tjernlundf2af1bb2011-01-27 16:30:54 +0100408 (1 + ((im->clk.spmr & SPMR_LBIUCM) >> SPMR_LBIUCM_SHIFT));
Becky Bruce0d4cee12010-06-17 11:37:20 -0500409 lcrr = (im->im_lbc.lcrr & LCRR_CLKDIV) >> LCRR_CLKDIV_SHIFT;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500410 switch (lcrr) {
411 case 2:
412 case 4:
413 case 8:
414 lclk_clk = lbiu_clk / lcrr;
415 break;
416 default:
417 /* unknown lcrr */
Dave Liu5245ff52007-09-18 12:36:11 +0800418 return -12;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500419 }
Dave Liue740c462006-12-07 21:13:15 +0800420
Kim Phillipsc02cf1e2008-03-28 10:18:40 -0500421 mem_clk = csb_clk *
Joakim Tjernlundf2af1bb2011-01-27 16:30:54 +0100422 (1 + ((im->clk.spmr & SPMR_DDRCM) >> SPMR_DDRCM_SHIFT));
423 corepll = (im->clk.spmr & SPMR_COREPLL) >> SPMR_COREPLL_SHIFT;
424
Dave Liue740c462006-12-07 21:13:15 +0800425#if defined(CONFIG_MPC8360)
Kim Phillipsc02cf1e2008-03-28 10:18:40 -0500426 mem_sec_clk = csb_clk * (1 +
Joakim Tjernlundf2af1bb2011-01-27 16:30:54 +0100427 ((im->clk.spmr & SPMR_LBIUCM) >> SPMR_LBIUCM_SHIFT));
Dave Liua46daea2006-11-03 19:33:44 -0600428#endif
Dave Liua46daea2006-11-03 19:33:44 -0600429
Eran Liberty9095d4a2005-07-28 10:08:46 -0500430 corecnf_tab_index = ((corepll & 0x1F) << 2) | ((corepll & 0x60) >> 5);
Kim Phillipsbae24792006-11-02 19:47:11 -0600431 if (corecnf_tab_index > (sizeof(corecnf_tab) / sizeof(corecnf_t))) {
Eran Liberty9095d4a2005-07-28 10:08:46 -0500432 /* corecnf_tab_index is too high, possibly worng value */
433 return -11;
434 }
435 switch (corecnf_tab[corecnf_tab_index].core_csb_ratio) {
436 case _byp:
437 case _x1:
438 case _1x:
439 core_clk = csb_clk;
440 break;
441 case _1_5x:
442 core_clk = (3 * csb_clk) / 2;
443 break;
444 case _2x:
445 core_clk = 2 * csb_clk;
446 break;
447 case _2_5x:
Kim Phillipsbae24792006-11-02 19:47:11 -0600448 core_clk = (5 * csb_clk) / 2;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500449 break;
450 case _3x:
451 core_clk = 3 * csb_clk;
452 break;
453 default:
454 /* unkown core to csb ratio */
Dave Liu5245ff52007-09-18 12:36:11 +0800455 return -13;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500456 }
Jon Loeligerebc72242005-08-01 13:20:47 -0500457
Gerlando Falauto77cf2832012-10-10 22:13:06 +0000458#if defined(CONFIG_QE)
Joakim Tjernlundf2af1bb2011-01-27 16:30:54 +0100459 qepmf = (im->clk.spmr & SPMR_CEPMF) >> SPMR_CEPMF_SHIFT;
460 qepdf = (im->clk.spmr & SPMR_CEPDF) >> SPMR_CEPDF_SHIFT;
Kim Phillipsbae24792006-11-02 19:47:11 -0600461 qe_clk = (pci_sync_in * qepmf) / (1 + qepdf);
Dave Liua46daea2006-11-03 19:33:44 -0600462 brg_clk = qe_clk / 2;
463#endif
Jon Loeligerebc72242005-08-01 13:20:47 -0500464
Kim Phillipsbae24792006-11-02 19:47:11 -0600465 gd->csb_clk = csb_clk;
Ilya Yanoka3e5fd52010-06-28 16:44:33 +0400466#if defined(CONFIG_MPC8308) || defined(CONFIG_MPC831x) || \
467 defined(CONFIG_MPC834x) || defined(CONFIG_MPC837x)
Kim Phillipsbae24792006-11-02 19:47:11 -0600468 gd->tsec1_clk = tsec1_clk;
469 gd->tsec2_clk = tsec2_clk;
Kim Phillipsbae24792006-11-02 19:47:11 -0600470 gd->usbdr_clk = usbdr_clk;
Gerlando Falautofe201cb2012-10-10 22:13:08 +0000471#elif defined(CONFIG_MPC8309)
472 gd->usbdr_clk = usbdr_clk;
Dave Liua46daea2006-11-03 19:33:44 -0600473#endif
Peter Tyser72f2d392009-05-22 17:23:25 -0500474#if defined(CONFIG_MPC834x)
Scott Woodc036fc92007-04-16 14:34:19 -0500475 gd->usbmph_clk = usbmph_clk;
476#endif
Dave Liue0cfec82007-09-18 12:36:58 +0800477#if defined(CONFIG_MPC8315)
478 gd->tdm_clk = tdm_clk;
479#endif
Rini van Zettena2496172010-04-15 16:03:05 +0200480#if defined(CONFIG_FSL_ESDHC)
Dave Liu5245ff52007-09-18 12:36:11 +0800481 gd->sdhc_clk = sdhc_clk;
482#endif
Kim Phillipsbae24792006-11-02 19:47:11 -0600483 gd->core_clk = core_clk;
484 gd->i2c1_clk = i2c1_clk;
Peter Tyser72f2d392009-05-22 17:23:25 -0500485#if !defined(CONFIG_MPC832x)
Kim Phillipsbae24792006-11-02 19:47:11 -0600486 gd->i2c2_clk = i2c2_clk;
Dave Liue740c462006-12-07 21:13:15 +0800487#endif
Gerlando Falautofe201cb2012-10-10 22:13:08 +0000488#if !defined(CONFIG_MPC8309)
Kim Phillipsbae24792006-11-02 19:47:11 -0600489 gd->enc_clk = enc_clk;
Gerlando Falautofe201cb2012-10-10 22:13:08 +0000490#endif
Kim Phillipsbae24792006-11-02 19:47:11 -0600491 gd->lbiu_clk = lbiu_clk;
492 gd->lclk_clk = lclk_clk;
Kim Phillipsc02cf1e2008-03-28 10:18:40 -0500493 gd->mem_clk = mem_clk;
Dave Liue740c462006-12-07 21:13:15 +0800494#if defined(CONFIG_MPC8360)
Kim Phillipsc02cf1e2008-03-28 10:18:40 -0500495 gd->mem_sec_clk = mem_sec_clk;
Dave Liue740c462006-12-07 21:13:15 +0800496#endif
Gerlando Falauto77cf2832012-10-10 22:13:06 +0000497#if defined(CONFIG_QE)
Kim Phillipsbae24792006-11-02 19:47:11 -0600498 gd->qe_clk = qe_clk;
499 gd->brg_clk = brg_clk;
Dave Liua46daea2006-11-03 19:33:44 -0600500#endif
Bill Cook5a043d92011-05-25 15:51:07 -0400501#if defined(CONFIG_MPC8308) || defined(CONFIG_MPC831x) || \
502 defined(CONFIG_MPC837x)
Dave Liu5245ff52007-09-18 12:36:11 +0800503 gd->pciexp1_clk = pciexp1_clk;
504 gd->pciexp2_clk = pciexp2_clk;
Dave Liue0cfec82007-09-18 12:36:58 +0800505#endif
Peter Tyser72f2d392009-05-22 17:23:25 -0500506#if defined(CONFIG_MPC837x) || defined(CONFIG_MPC8315)
Dave Liu5245ff52007-09-18 12:36:11 +0800507 gd->sata_clk = sata_clk;
508#endif
Kim Phillipscd9fd702007-08-15 22:30:19 -0500509 gd->pci_clk = pci_sync_in;
Kim Phillipsbae24792006-11-02 19:47:11 -0600510 gd->cpu_clk = gd->core_clk;
511 gd->bus_clk = gd->csb_clk;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500512 return 0;
Dave Liua46daea2006-11-03 19:33:44 -0600513
Eran Liberty9095d4a2005-07-28 10:08:46 -0500514}
515
516/********************************************
517 * get_bus_freq
518 * return system bus freq in Hz
519 *********************************************/
Kim Phillipsbae24792006-11-02 19:47:11 -0600520ulong get_bus_freq(ulong dummy)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500521{
Eran Liberty9095d4a2005-07-28 10:08:46 -0500522 return gd->csb_clk;
523}
524
York Sune12ce982011-08-26 11:32:44 -0700525/********************************************
526 * get_ddr_freq
527 * return ddr bus freq in Hz
528 *********************************************/
529ulong get_ddr_freq(ulong dummy)
530{
531 return gd->mem_clk;
532}
533
Kim Phillipsb5c312a2012-10-29 13:34:39 +0000534static int do_clocks(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Eran Liberty9095d4a2005-07-28 10:08:46 -0500535{
Wolfgang Denk20591042008-10-19 02:35:49 +0200536 char buf[32];
537
Eran Liberty9095d4a2005-07-28 10:08:46 -0500538 printf("Clock configuration:\n");
Wolfgang Denk20591042008-10-19 02:35:49 +0200539 printf(" Core: %-4s MHz\n", strmhz(buf, gd->core_clk));
540 printf(" Coherent System Bus: %-4s MHz\n", strmhz(buf, gd->csb_clk));
Gerlando Falauto77cf2832012-10-10 22:13:06 +0000541#if defined(CONFIG_QE)
Wolfgang Denk20591042008-10-19 02:35:49 +0200542 printf(" QE: %-4s MHz\n", strmhz(buf, gd->qe_clk));
543 printf(" BRG: %-4s MHz\n", strmhz(buf, gd->brg_clk));
Dave Liua46daea2006-11-03 19:33:44 -0600544#endif
Wolfgang Denk20591042008-10-19 02:35:49 +0200545 printf(" Local Bus Controller:%-4s MHz\n", strmhz(buf, gd->lbiu_clk));
546 printf(" Local Bus: %-4s MHz\n", strmhz(buf, gd->lclk_clk));
547 printf(" DDR: %-4s MHz\n", strmhz(buf, gd->mem_clk));
Dave Liue740c462006-12-07 21:13:15 +0800548#if defined(CONFIG_MPC8360)
Wolfgang Denk20591042008-10-19 02:35:49 +0200549 printf(" DDR Secondary: %-4s MHz\n", strmhz(buf, gd->mem_sec_clk));
Dave Liua46daea2006-11-03 19:33:44 -0600550#endif
Gerlando Falautofe201cb2012-10-10 22:13:08 +0000551#if !defined(CONFIG_MPC8309)
Wolfgang Denk20591042008-10-19 02:35:49 +0200552 printf(" SEC: %-4s MHz\n", strmhz(buf, gd->enc_clk));
Gerlando Falautofe201cb2012-10-10 22:13:08 +0000553#endif
Wolfgang Denk20591042008-10-19 02:35:49 +0200554 printf(" I2C1: %-4s MHz\n", strmhz(buf, gd->i2c1_clk));
Peter Tyser72f2d392009-05-22 17:23:25 -0500555#if !defined(CONFIG_MPC832x)
Wolfgang Denk20591042008-10-19 02:35:49 +0200556 printf(" I2C2: %-4s MHz\n", strmhz(buf, gd->i2c2_clk));
Dave Liue740c462006-12-07 21:13:15 +0800557#endif
Dave Liue0cfec82007-09-18 12:36:58 +0800558#if defined(CONFIG_MPC8315)
Wolfgang Denk20591042008-10-19 02:35:49 +0200559 printf(" TDM: %-4s MHz\n", strmhz(buf, gd->tdm_clk));
Dave Liue0cfec82007-09-18 12:36:58 +0800560#endif
Rini van Zettena2496172010-04-15 16:03:05 +0200561#if defined(CONFIG_FSL_ESDHC)
Wolfgang Denk20591042008-10-19 02:35:49 +0200562 printf(" SDHC: %-4s MHz\n", strmhz(buf, gd->sdhc_clk));
Dave Liu5245ff52007-09-18 12:36:11 +0800563#endif
Ilya Yanoka3e5fd52010-06-28 16:44:33 +0400564#if defined(CONFIG_MPC8308) || defined(CONFIG_MPC831x) || \
565 defined(CONFIG_MPC834x) || defined(CONFIG_MPC837x)
Wolfgang Denk20591042008-10-19 02:35:49 +0200566 printf(" TSEC1: %-4s MHz\n", strmhz(buf, gd->tsec1_clk));
567 printf(" TSEC2: %-4s MHz\n", strmhz(buf, gd->tsec2_clk));
568 printf(" USB DR: %-4s MHz\n", strmhz(buf, gd->usbdr_clk));
Gerlando Falautofe201cb2012-10-10 22:13:08 +0000569#elif defined(CONFIG_MPC8309)
570 printf(" USB DR: %-4s MHz\n", strmhz(buf, gd->usbdr_clk));
Dave Liua46daea2006-11-03 19:33:44 -0600571#endif
Peter Tyser72f2d392009-05-22 17:23:25 -0500572#if defined(CONFIG_MPC834x)
Wolfgang Denk20591042008-10-19 02:35:49 +0200573 printf(" USB MPH: %-4s MHz\n", strmhz(buf, gd->usbmph_clk));
Scott Woodc036fc92007-04-16 14:34:19 -0500574#endif
Bill Cook5a043d92011-05-25 15:51:07 -0400575#if defined(CONFIG_MPC8308) || defined(CONFIG_MPC831x) || \
576 defined(CONFIG_MPC837x)
Wolfgang Denk20591042008-10-19 02:35:49 +0200577 printf(" PCIEXP1: %-4s MHz\n", strmhz(buf, gd->pciexp1_clk));
578 printf(" PCIEXP2: %-4s MHz\n", strmhz(buf, gd->pciexp2_clk));
Dave Liue0cfec82007-09-18 12:36:58 +0800579#endif
Peter Tyser72f2d392009-05-22 17:23:25 -0500580#if defined(CONFIG_MPC837x) || defined(CONFIG_MPC8315)
Wolfgang Denk20591042008-10-19 02:35:49 +0200581 printf(" SATA: %-4s MHz\n", strmhz(buf, gd->sata_clk));
Dave Liu5245ff52007-09-18 12:36:11 +0800582#endif
Jon Loeligerebc72242005-08-01 13:20:47 -0500583 return 0;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500584}
Kim Phillipsd82b0772007-04-30 15:26:21 -0500585
586U_BOOT_CMD(clocks, 1, 0, do_clocks,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600587 "print clock configuration",
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200588 " clocks"
Kim Phillipsd82b0772007-04-30 15:26:21 -0500589);