blob: 39bc1c5340655ab84cc70a0952f377b5e7399edc [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Eran Liberty9095d4a2005-07-28 10:08:46 -05002/*
3 * (C) Copyright 2000-2002
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 *
Dave Liu5245ff52007-09-18 12:36:11 +08006 * Copyright (C) 2004-2007 Freescale Semiconductor, Inc.
Eran Liberty9095d4a2005-07-28 10:08:46 -05007 */
8
Mario Six7cab1472018-08-06 10:23:36 +02009#ifndef CONFIG_CLK_MPC83XX
10
Eran Liberty9095d4a2005-07-28 10:08:46 -050011#include <common.h>
12#include <mpc83xx.h>
Kim Phillipsd82b0772007-04-30 15:26:21 -050013#include <command.h>
Eran Liberty9095d4a2005-07-28 10:08:46 -050014#include <asm/processor.h>
15
Wolfgang Denk6405a152006-03-31 18:32:53 +020016DECLARE_GLOBAL_DATA_PTR;
17
Eran Liberty9095d4a2005-07-28 10:08:46 -050018/* ----------------------------------------------------------------- */
19
20typedef enum {
21 _unk,
22 _off,
23 _byp,
24 _x8,
25 _x4,
26 _x2,
27 _x1,
28 _1x,
29 _1_5x,
30 _2x,
31 _2_5x,
32 _3x
33} mult_t;
34
35typedef struct {
36 mult_t core_csb_ratio;
Kim Phillipsbae24792006-11-02 19:47:11 -060037 mult_t vco_divider;
Eran Liberty9095d4a2005-07-28 10:08:46 -050038} corecnf_t;
39
Kim Phillipsb5c312a2012-10-29 13:34:39 +000040static corecnf_t corecnf_tab[] = {
Kim Phillipsbae24792006-11-02 19:47:11 -060041 {_byp, _byp}, /* 0x00 */
42 {_byp, _byp}, /* 0x01 */
43 {_byp, _byp}, /* 0x02 */
44 {_byp, _byp}, /* 0x03 */
45 {_byp, _byp}, /* 0x04 */
46 {_byp, _byp}, /* 0x05 */
47 {_byp, _byp}, /* 0x06 */
48 {_byp, _byp}, /* 0x07 */
49 {_1x, _x2}, /* 0x08 */
50 {_1x, _x4}, /* 0x09 */
51 {_1x, _x8}, /* 0x0A */
52 {_1x, _x8}, /* 0x0B */
53 {_1_5x, _x2}, /* 0x0C */
54 {_1_5x, _x4}, /* 0x0D */
55 {_1_5x, _x8}, /* 0x0E */
56 {_1_5x, _x8}, /* 0x0F */
57 {_2x, _x2}, /* 0x10 */
58 {_2x, _x4}, /* 0x11 */
59 {_2x, _x8}, /* 0x12 */
60 {_2x, _x8}, /* 0x13 */
61 {_2_5x, _x2}, /* 0x14 */
62 {_2_5x, _x4}, /* 0x15 */
63 {_2_5x, _x8}, /* 0x16 */
64 {_2_5x, _x8}, /* 0x17 */
65 {_3x, _x2}, /* 0x18 */
66 {_3x, _x4}, /* 0x19 */
67 {_3x, _x8}, /* 0x1A */
68 {_3x, _x8}, /* 0x1B */
Eran Liberty9095d4a2005-07-28 10:08:46 -050069};
70
71/* ----------------------------------------------------------------- */
72
73/*
74 *
75 */
Kim Phillipsbae24792006-11-02 19:47:11 -060076int get_clocks(void)
Eran Liberty9095d4a2005-07-28 10:08:46 -050077{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020078 volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
Eran Liberty9095d4a2005-07-28 10:08:46 -050079 u32 pci_sync_in;
Kim Phillipsbae24792006-11-02 19:47:11 -060080 u8 spmf;
81 u8 clkin_div;
Eran Liberty9095d4a2005-07-28 10:08:46 -050082 u32 sccr;
83 u32 corecnf_tab_index;
Kim Phillipsbae24792006-11-02 19:47:11 -060084 u8 corepll;
Eran Liberty9095d4a2005-07-28 10:08:46 -050085 u32 lcrr;
Jon Loeligerebc72242005-08-01 13:20:47 -050086
Eran Liberty9095d4a2005-07-28 10:08:46 -050087 u32 csb_clk;
Ilya Yanoka3e5fd52010-06-28 16:44:33 +040088#if defined(CONFIG_MPC8308) || defined(CONFIG_MPC831x) || \
89 defined(CONFIG_MPC834x) || defined(CONFIG_MPC837x)
Eran Liberty9095d4a2005-07-28 10:08:46 -050090 u32 tsec1_clk;
91 u32 tsec2_clk;
Eran Liberty9095d4a2005-07-28 10:08:46 -050092 u32 usbdr_clk;
Gerlando Falautofe201cb2012-10-10 22:13:08 +000093#elif defined(CONFIG_MPC8309)
94 u32 usbdr_clk;
Dave Liua46daea2006-11-03 19:33:44 -060095#endif
Peter Tyser72f2d392009-05-22 17:23:25 -050096#ifdef CONFIG_MPC834x
Scott Woodc036fc92007-04-16 14:34:19 -050097 u32 usbmph_clk;
98#endif
Dave Liua46daea2006-11-03 19:33:44 -060099 u32 core_clk;
100 u32 i2c1_clk;
Peter Tyser72f2d392009-05-22 17:23:25 -0500101#if !defined(CONFIG_MPC832x)
Dave Liua46daea2006-11-03 19:33:44 -0600102 u32 i2c2_clk;
Dave Liue740c462006-12-07 21:13:15 +0800103#endif
Dave Liue0cfec82007-09-18 12:36:58 +0800104#if defined(CONFIG_MPC8315)
105 u32 tdm_clk;
106#endif
Rini van Zettena2496172010-04-15 16:03:05 +0200107#if defined(CONFIG_FSL_ESDHC)
Dave Liu5245ff52007-09-18 12:36:11 +0800108 u32 sdhc_clk;
109#endif
Gerlando Falautofe201cb2012-10-10 22:13:08 +0000110#if !defined(CONFIG_MPC8309)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500111 u32 enc_clk;
Gerlando Falautofe201cb2012-10-10 22:13:08 +0000112#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500113 u32 lbiu_clk;
114 u32 lclk_clk;
Kim Phillipsc02cf1e2008-03-28 10:18:40 -0500115 u32 mem_clk;
Dave Liue740c462006-12-07 21:13:15 +0800116#if defined(CONFIG_MPC8360)
Kim Phillipsc02cf1e2008-03-28 10:18:40 -0500117 u32 mem_sec_clk;
Dave Liue740c462006-12-07 21:13:15 +0800118#endif
Gerlando Falauto77cf2832012-10-10 22:13:06 +0000119#if defined(CONFIG_QE)
Dave Liua46daea2006-11-03 19:33:44 -0600120 u32 qepmf;
121 u32 qepdf;
Dave Liua46daea2006-11-03 19:33:44 -0600122 u32 qe_clk;
123 u32 brg_clk;
124#endif
Ilya Yanoka3e5fd52010-06-28 16:44:33 +0400125#if defined(CONFIG_MPC8308) || defined(CONFIG_MPC831x) || \
126 defined(CONFIG_MPC837x)
Dave Liu5245ff52007-09-18 12:36:11 +0800127 u32 pciexp1_clk;
128 u32 pciexp2_clk;
Dave Liue0cfec82007-09-18 12:36:58 +0800129#endif
Peter Tyser72f2d392009-05-22 17:23:25 -0500130#if defined(CONFIG_MPC837x) || defined(CONFIG_MPC8315)
Dave Liu5245ff52007-09-18 12:36:11 +0800131 u32 sata_clk;
132#endif
Jon Loeligerebc72242005-08-01 13:20:47 -0500133
Kim Phillipsbae24792006-11-02 19:47:11 -0600134 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500135 return -1;
Jon Loeligerebc72242005-08-01 13:20:47 -0500136
Dave Liua46daea2006-11-03 19:33:44 -0600137 clkin_div = ((im->clk.spmr & SPMR_CKID) >> SPMR_CKID_SHIFT);
Marian Balakowicz513b4a12005-10-11 19:09:42 +0200138
Dave Liua46daea2006-11-03 19:33:44 -0600139 if (im->reset.rcwh & HRCWH_PCI_HOST) {
140#if defined(CONFIG_83XX_CLKIN)
141 pci_sync_in = CONFIG_83XX_CLKIN / (1 + clkin_div);
142#else
143 pci_sync_in = 0xDEADBEEF;
144#endif
145 } else {
146#if defined(CONFIG_83XX_PCICLK)
147 pci_sync_in = CONFIG_83XX_PCICLK;
148#else
149 pci_sync_in = 0xDEADBEEF;
150#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500151 }
Marian Balakowicz513b4a12005-10-11 19:09:42 +0200152
Joakim Tjernlundf2af1bb2011-01-27 16:30:54 +0100153 spmf = (im->clk.spmr & SPMR_SPMF) >> SPMR_SPMF_SHIFT;
Dave Liua46daea2006-11-03 19:33:44 -0600154 csb_clk = pci_sync_in * (1 + clkin_div) * spmf;
Jon Loeligerebc72242005-08-01 13:20:47 -0500155
Eran Liberty9095d4a2005-07-28 10:08:46 -0500156 sccr = im->clk.sccr;
Dave Liua46daea2006-11-03 19:33:44 -0600157
Ilya Yanoka3e5fd52010-06-28 16:44:33 +0400158#if defined(CONFIG_MPC8308) || defined(CONFIG_MPC831x) || \
159 defined(CONFIG_MPC834x) || defined(CONFIG_MPC837x)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500160 switch ((sccr & SCCR_TSEC1CM) >> SCCR_TSEC1CM_SHIFT) {
161 case 0:
162 tsec1_clk = 0;
163 break;
164 case 1:
165 tsec1_clk = csb_clk;
166 break;
167 case 2:
168 tsec1_clk = csb_clk / 2;
169 break;
170 case 3:
171 tsec1_clk = csb_clk / 3;
172 break;
173 default:
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500174 /* unknown SCCR_TSEC1CM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800175 return -2;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500176 }
Gerlando Falauto74735552012-10-10 22:13:07 +0000177#endif
Jon Loeligerebc72242005-08-01 13:20:47 -0500178
Gerlando Falauto74735552012-10-10 22:13:07 +0000179#if defined(CONFIG_MPC830x) || defined(CONFIG_MPC831x) || \
180 defined(CONFIG_MPC834x) || defined(CONFIG_MPC837x)
Scott Woodc036fc92007-04-16 14:34:19 -0500181 switch ((sccr & SCCR_USBDRCM) >> SCCR_USBDRCM_SHIFT) {
182 case 0:
183 usbdr_clk = 0;
184 break;
185 case 1:
186 usbdr_clk = csb_clk;
187 break;
188 case 2:
189 usbdr_clk = csb_clk / 2;
190 break;
191 case 3:
192 usbdr_clk = csb_clk / 3;
193 break;
194 default:
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500195 /* unknown SCCR_USBDRCM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800196 return -3;
Scott Woodc036fc92007-04-16 14:34:19 -0500197 }
198#endif
199
Ilya Yanoka3e5fd52010-06-28 16:44:33 +0400200#if defined(CONFIG_MPC8308) || defined(CONFIG_MPC8315) || \
201 defined(CONFIG_MPC834x) || defined(CONFIG_MPC837x)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500202 switch ((sccr & SCCR_TSEC2CM) >> SCCR_TSEC2CM_SHIFT) {
203 case 0:
204 tsec2_clk = 0;
205 break;
206 case 1:
207 tsec2_clk = csb_clk;
208 break;
209 case 2:
210 tsec2_clk = csb_clk / 2;
211 break;
212 case 3:
213 tsec2_clk = csb_clk / 3;
214 break;
215 default:
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500216 /* unknown SCCR_TSEC2CM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800217 return -4;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500218 }
Dave Liue0cfec82007-09-18 12:36:58 +0800219#elif defined(CONFIG_MPC8313)
Dave Liu5245ff52007-09-18 12:36:11 +0800220 tsec2_clk = tsec1_clk;
Jon Loeligerebc72242005-08-01 13:20:47 -0500221
Dave Liu5245ff52007-09-18 12:36:11 +0800222 if (!(sccr & SCCR_TSEC1ON))
223 tsec1_clk = 0;
224 if (!(sccr & SCCR_TSEC2ON))
225 tsec2_clk = 0;
226#endif
Jon Loeligerebc72242005-08-01 13:20:47 -0500227
Peter Tyser72f2d392009-05-22 17:23:25 -0500228#if defined(CONFIG_MPC834x)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500229 switch ((sccr & SCCR_USBMPHCM) >> SCCR_USBMPHCM_SHIFT) {
230 case 0:
231 usbmph_clk = 0;
232 break;
233 case 1:
234 usbmph_clk = csb_clk;
235 break;
236 case 2:
237 usbmph_clk = csb_clk / 2;
238 break;
239 case 3:
240 usbmph_clk = csb_clk / 3;
241 break;
242 default:
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500243 /* unknown SCCR_USBMPHCM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800244 return -5;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500245 }
246
Kim Phillipsbae24792006-11-02 19:47:11 -0600247 if (usbmph_clk != 0 && usbdr_clk != 0 && usbmph_clk != usbdr_clk) {
248 /* if USB MPH clock is not disabled and
249 * USB DR clock is not disabled then
250 * USB MPH & USB DR must have the same rate
251 */
Dave Liu5245ff52007-09-18 12:36:11 +0800252 return -6;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500253 }
Dave Liu5245ff52007-09-18 12:36:11 +0800254#endif
Gerlando Falautofe201cb2012-10-10 22:13:08 +0000255#if !defined(CONFIG_MPC8309)
Dave Liu5245ff52007-09-18 12:36:11 +0800256 switch ((sccr & SCCR_ENCCM) >> SCCR_ENCCM_SHIFT) {
257 case 0:
258 enc_clk = 0;
259 break;
260 case 1:
261 enc_clk = csb_clk;
262 break;
263 case 2:
264 enc_clk = csb_clk / 2;
265 break;
266 case 3:
267 enc_clk = csb_clk / 3;
268 break;
269 default:
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500270 /* unknown SCCR_ENCCM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800271 return -7;
272 }
Gerlando Falautofe201cb2012-10-10 22:13:08 +0000273#endif
Scott Woodc036fc92007-04-16 14:34:19 -0500274
Rini van Zettena2496172010-04-15 16:03:05 +0200275#if defined(CONFIG_FSL_ESDHC)
Dave Liu5245ff52007-09-18 12:36:11 +0800276 switch ((sccr & SCCR_SDHCCM) >> SCCR_SDHCCM_SHIFT) {
277 case 0:
278 sdhc_clk = 0;
279 break;
280 case 1:
281 sdhc_clk = csb_clk;
282 break;
283 case 2:
284 sdhc_clk = csb_clk / 2;
285 break;
286 case 3:
287 sdhc_clk = csb_clk / 3;
288 break;
289 default:
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500290 /* unknown SCCR_SDHCCM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800291 return -8;
292 }
Dave Liua46daea2006-11-03 19:33:44 -0600293#endif
Dave Liue0cfec82007-09-18 12:36:58 +0800294#if defined(CONFIG_MPC8315)
295 switch ((sccr & SCCR_TDMCM) >> SCCR_TDMCM_SHIFT) {
296 case 0:
297 tdm_clk = 0;
298 break;
299 case 1:
300 tdm_clk = csb_clk;
301 break;
302 case 2:
303 tdm_clk = csb_clk / 2;
304 break;
305 case 3:
306 tdm_clk = csb_clk / 3;
307 break;
308 default:
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500309 /* unknown SCCR_TDMCM value */
Dave Liue0cfec82007-09-18 12:36:58 +0800310 return -8;
311 }
312#endif
Scott Woodc036fc92007-04-16 14:34:19 -0500313
Peter Tyser72f2d392009-05-22 17:23:25 -0500314#if defined(CONFIG_MPC834x)
Dave Liu5245ff52007-09-18 12:36:11 +0800315 i2c1_clk = tsec2_clk;
316#elif defined(CONFIG_MPC8360)
Dave Liua46daea2006-11-03 19:33:44 -0600317 i2c1_clk = csb_clk;
Peter Tyser72f2d392009-05-22 17:23:25 -0500318#elif defined(CONFIG_MPC832x)
Dave Liu5245ff52007-09-18 12:36:11 +0800319 i2c1_clk = enc_clk;
Ilya Yanoka3e5fd52010-06-28 16:44:33 +0400320#elif defined(CONFIG_MPC8308) || defined(CONFIG_MPC831x)
Dave Liu5245ff52007-09-18 12:36:11 +0800321 i2c1_clk = enc_clk;
Rini van Zettena2496172010-04-15 16:03:05 +0200322#elif defined(CONFIG_FSL_ESDHC)
Dave Liu5245ff52007-09-18 12:36:11 +0800323 i2c1_clk = sdhc_clk;
Andre Schwarza76cc612011-04-14 14:57:40 +0200324#elif defined(CONFIG_MPC837x)
325 i2c1_clk = enc_clk;
Gerlando Falautofe201cb2012-10-10 22:13:08 +0000326#elif defined(CONFIG_MPC8309)
327 i2c1_clk = csb_clk;
Dave Liua46daea2006-11-03 19:33:44 -0600328#endif
Peter Tyser72f2d392009-05-22 17:23:25 -0500329#if !defined(CONFIG_MPC832x)
Dave Liu5245ff52007-09-18 12:36:11 +0800330 i2c2_clk = csb_clk; /* i2c-2 clk is equal to csb clk */
Dave Liue740c462006-12-07 21:13:15 +0800331#endif
Jon Loeligerebc72242005-08-01 13:20:47 -0500332
Ilya Yanoka3e5fd52010-06-28 16:44:33 +0400333#if defined(CONFIG_MPC8308) || defined(CONFIG_MPC831x) || \
334 defined(CONFIG_MPC837x)
Dave Liu5245ff52007-09-18 12:36:11 +0800335 switch ((sccr & SCCR_PCIEXP1CM) >> SCCR_PCIEXP1CM_SHIFT) {
Dave Liua46daea2006-11-03 19:33:44 -0600336 case 0:
Dave Liu5245ff52007-09-18 12:36:11 +0800337 pciexp1_clk = 0;
Dave Liua46daea2006-11-03 19:33:44 -0600338 break;
339 case 1:
Dave Liu5245ff52007-09-18 12:36:11 +0800340 pciexp1_clk = csb_clk;
Dave Liua46daea2006-11-03 19:33:44 -0600341 break;
342 case 2:
Dave Liu5245ff52007-09-18 12:36:11 +0800343 pciexp1_clk = csb_clk / 2;
Dave Liua46daea2006-11-03 19:33:44 -0600344 break;
345 case 3:
Dave Liu5245ff52007-09-18 12:36:11 +0800346 pciexp1_clk = csb_clk / 3;
Dave Liua46daea2006-11-03 19:33:44 -0600347 break;
348 default:
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500349 /* unknown SCCR_PCIEXP1CM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800350 return -9;
Dave Liua46daea2006-11-03 19:33:44 -0600351 }
Dave Liue740c462006-12-07 21:13:15 +0800352
Dave Liu5245ff52007-09-18 12:36:11 +0800353 switch ((sccr & SCCR_PCIEXP2CM) >> SCCR_PCIEXP2CM_SHIFT) {
354 case 0:
355 pciexp2_clk = 0;
356 break;
357 case 1:
358 pciexp2_clk = csb_clk;
359 break;
360 case 2:
361 pciexp2_clk = csb_clk / 2;
362 break;
363 case 3:
364 pciexp2_clk = csb_clk / 3;
365 break;
366 default:
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500367 /* unknown SCCR_PCIEXP2CM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800368 return -10;
369 }
370#endif
371
Peter Tyser72f2d392009-05-22 17:23:25 -0500372#if defined(CONFIG_MPC837x) || defined(CONFIG_MPC8315)
Dave Liub7896ad2008-01-17 18:23:19 +0800373 switch ((sccr & SCCR_SATA1CM) >> SCCR_SATA1CM_SHIFT) {
374 case 0:
Dave Liu5245ff52007-09-18 12:36:11 +0800375 sata_clk = 0;
376 break;
Dave Liub7896ad2008-01-17 18:23:19 +0800377 case 1:
Dave Liu5245ff52007-09-18 12:36:11 +0800378 sata_clk = csb_clk;
379 break;
Dave Liub7896ad2008-01-17 18:23:19 +0800380 case 2:
Dave Liu5245ff52007-09-18 12:36:11 +0800381 sata_clk = csb_clk / 2;
382 break;
Dave Liub7896ad2008-01-17 18:23:19 +0800383 case 3:
Dave Liu5245ff52007-09-18 12:36:11 +0800384 sata_clk = csb_clk / 3;
385 break;
386 default:
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500387 /* unknown SCCR_SATA1CM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800388 return -11;
389 }
390#endif
391
Kim Phillipsbae24792006-11-02 19:47:11 -0600392 lbiu_clk = csb_clk *
Joakim Tjernlundf2af1bb2011-01-27 16:30:54 +0100393 (1 + ((im->clk.spmr & SPMR_LBIUCM) >> SPMR_LBIUCM_SHIFT));
Becky Bruce0d4cee12010-06-17 11:37:20 -0500394 lcrr = (im->im_lbc.lcrr & LCRR_CLKDIV) >> LCRR_CLKDIV_SHIFT;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500395 switch (lcrr) {
396 case 2:
397 case 4:
398 case 8:
399 lclk_clk = lbiu_clk / lcrr;
400 break;
401 default:
402 /* unknown lcrr */
Dave Liu5245ff52007-09-18 12:36:11 +0800403 return -12;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500404 }
Dave Liue740c462006-12-07 21:13:15 +0800405
Kim Phillipsc02cf1e2008-03-28 10:18:40 -0500406 mem_clk = csb_clk *
Joakim Tjernlundf2af1bb2011-01-27 16:30:54 +0100407 (1 + ((im->clk.spmr & SPMR_DDRCM) >> SPMR_DDRCM_SHIFT));
408 corepll = (im->clk.spmr & SPMR_COREPLL) >> SPMR_COREPLL_SHIFT;
409
Dave Liue740c462006-12-07 21:13:15 +0800410#if defined(CONFIG_MPC8360)
Kim Phillipsc02cf1e2008-03-28 10:18:40 -0500411 mem_sec_clk = csb_clk * (1 +
Joakim Tjernlundf2af1bb2011-01-27 16:30:54 +0100412 ((im->clk.spmr & SPMR_LBIUCM) >> SPMR_LBIUCM_SHIFT));
Dave Liua46daea2006-11-03 19:33:44 -0600413#endif
Dave Liua46daea2006-11-03 19:33:44 -0600414
Eran Liberty9095d4a2005-07-28 10:08:46 -0500415 corecnf_tab_index = ((corepll & 0x1F) << 2) | ((corepll & 0x60) >> 5);
Robert P. J. Day0c911592016-05-23 06:49:21 -0400416 if (corecnf_tab_index > (ARRAY_SIZE(corecnf_tab))) {
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500417 /* corecnf_tab_index is too high, possibly wrong value */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500418 return -11;
419 }
420 switch (corecnf_tab[corecnf_tab_index].core_csb_ratio) {
421 case _byp:
422 case _x1:
423 case _1x:
424 core_clk = csb_clk;
425 break;
426 case _1_5x:
427 core_clk = (3 * csb_clk) / 2;
428 break;
429 case _2x:
430 core_clk = 2 * csb_clk;
431 break;
432 case _2_5x:
Kim Phillipsbae24792006-11-02 19:47:11 -0600433 core_clk = (5 * csb_clk) / 2;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500434 break;
435 case _3x:
436 core_clk = 3 * csb_clk;
437 break;
438 default:
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500439 /* unknown core to csb ratio */
Dave Liu5245ff52007-09-18 12:36:11 +0800440 return -13;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500441 }
Jon Loeligerebc72242005-08-01 13:20:47 -0500442
Gerlando Falauto77cf2832012-10-10 22:13:06 +0000443#if defined(CONFIG_QE)
Joakim Tjernlundf2af1bb2011-01-27 16:30:54 +0100444 qepmf = (im->clk.spmr & SPMR_CEPMF) >> SPMR_CEPMF_SHIFT;
445 qepdf = (im->clk.spmr & SPMR_CEPDF) >> SPMR_CEPDF_SHIFT;
Kim Phillipsbae24792006-11-02 19:47:11 -0600446 qe_clk = (pci_sync_in * qepmf) / (1 + qepdf);
Dave Liua46daea2006-11-03 19:33:44 -0600447 brg_clk = qe_clk / 2;
448#endif
Jon Loeligerebc72242005-08-01 13:20:47 -0500449
Simon Glasscc76e9e2012-12-13 20:48:47 +0000450 gd->arch.csb_clk = csb_clk;
Ilya Yanoka3e5fd52010-06-28 16:44:33 +0400451#if defined(CONFIG_MPC8308) || defined(CONFIG_MPC831x) || \
452 defined(CONFIG_MPC834x) || defined(CONFIG_MPC837x)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000453 gd->arch.tsec1_clk = tsec1_clk;
454 gd->arch.tsec2_clk = tsec2_clk;
455 gd->arch.usbdr_clk = usbdr_clk;
Gerlando Falautofe201cb2012-10-10 22:13:08 +0000456#elif defined(CONFIG_MPC8309)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000457 gd->arch.usbdr_clk = usbdr_clk;
Dave Liua46daea2006-11-03 19:33:44 -0600458#endif
Peter Tyser72f2d392009-05-22 17:23:25 -0500459#if defined(CONFIG_MPC834x)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000460 gd->arch.usbmph_clk = usbmph_clk;
Scott Woodc036fc92007-04-16 14:34:19 -0500461#endif
Dave Liue0cfec82007-09-18 12:36:58 +0800462#if defined(CONFIG_MPC8315)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000463 gd->arch.tdm_clk = tdm_clk;
Dave Liue0cfec82007-09-18 12:36:58 +0800464#endif
Rini van Zettena2496172010-04-15 16:03:05 +0200465#if defined(CONFIG_FSL_ESDHC)
Simon Glass9e247d12012-12-13 20:49:05 +0000466 gd->arch.sdhc_clk = sdhc_clk;
Dave Liu5245ff52007-09-18 12:36:11 +0800467#endif
Simon Glasscc76e9e2012-12-13 20:48:47 +0000468 gd->arch.core_clk = core_clk;
Simon Glassc2baaec2012-12-13 20:48:49 +0000469 gd->arch.i2c1_clk = i2c1_clk;
Peter Tyser72f2d392009-05-22 17:23:25 -0500470#if !defined(CONFIG_MPC832x)
Simon Glassc2baaec2012-12-13 20:48:49 +0000471 gd->arch.i2c2_clk = i2c2_clk;
Dave Liue740c462006-12-07 21:13:15 +0800472#endif
Gerlando Falautofe201cb2012-10-10 22:13:08 +0000473#if !defined(CONFIG_MPC8309)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000474 gd->arch.enc_clk = enc_clk;
Gerlando Falautofe201cb2012-10-10 22:13:08 +0000475#endif
Simon Glasscc76e9e2012-12-13 20:48:47 +0000476 gd->arch.lbiu_clk = lbiu_clk;
477 gd->arch.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)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000480 gd->arch.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)
Simon Glass8518b172012-12-13 20:48:50 +0000483 gd->arch.qe_clk = qe_clk;
Simon Glass34a194f2012-12-13 20:48:44 +0000484 gd->arch.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)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000488 gd->arch.pciexp1_clk = pciexp1_clk;
489 gd->arch.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)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000492 gd->arch.sata_clk = sata_clk;
Dave Liu5245ff52007-09-18 12:36:11 +0800493#endif
Kim Phillipscd9fd702007-08-15 22:30:19 -0500494 gd->pci_clk = pci_sync_in;
Simon Glasscc76e9e2012-12-13 20:48:47 +0000495 gd->cpu_clk = gd->arch.core_clk;
496 gd->bus_clk = gd->arch.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{
Simon Glasscc76e9e2012-12-13 20:48:47 +0000507 return gd->arch.csb_clk;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500508}
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
Kim Phillipsb5c312a2012-10-29 13:34:39 +0000519static int 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");
Simon Glasscc76e9e2012-12-13 20:48:47 +0000524 printf(" Core: %-4s MHz\n",
525 strmhz(buf, gd->arch.core_clk));
526 printf(" Coherent System Bus: %-4s MHz\n",
527 strmhz(buf, gd->arch.csb_clk));
Gerlando Falauto77cf2832012-10-10 22:13:06 +0000528#if defined(CONFIG_QE)
Simon Glass8518b172012-12-13 20:48:50 +0000529 printf(" QE: %-4s MHz\n",
530 strmhz(buf, gd->arch.qe_clk));
Simon Glass34a194f2012-12-13 20:48:44 +0000531 printf(" BRG: %-4s MHz\n",
532 strmhz(buf, gd->arch.brg_clk));
Dave Liua46daea2006-11-03 19:33:44 -0600533#endif
Simon Glasscc76e9e2012-12-13 20:48:47 +0000534 printf(" Local Bus Controller:%-4s MHz\n",
535 strmhz(buf, gd->arch.lbiu_clk));
536 printf(" Local Bus: %-4s MHz\n",
537 strmhz(buf, gd->arch.lclk_clk));
Wolfgang Denk20591042008-10-19 02:35:49 +0200538 printf(" DDR: %-4s MHz\n", strmhz(buf, gd->mem_clk));
Dave Liue740c462006-12-07 21:13:15 +0800539#if defined(CONFIG_MPC8360)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000540 printf(" DDR Secondary: %-4s MHz\n",
541 strmhz(buf, gd->arch.mem_sec_clk));
Dave Liua46daea2006-11-03 19:33:44 -0600542#endif
Gerlando Falautofe201cb2012-10-10 22:13:08 +0000543#if !defined(CONFIG_MPC8309)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000544 printf(" SEC: %-4s MHz\n",
545 strmhz(buf, gd->arch.enc_clk));
Gerlando Falautofe201cb2012-10-10 22:13:08 +0000546#endif
Simon Glassc2baaec2012-12-13 20:48:49 +0000547 printf(" I2C1: %-4s MHz\n",
548 strmhz(buf, gd->arch.i2c1_clk));
Peter Tyser72f2d392009-05-22 17:23:25 -0500549#if !defined(CONFIG_MPC832x)
Simon Glassc2baaec2012-12-13 20:48:49 +0000550 printf(" I2C2: %-4s MHz\n",
551 strmhz(buf, gd->arch.i2c2_clk));
Dave Liue740c462006-12-07 21:13:15 +0800552#endif
Dave Liue0cfec82007-09-18 12:36:58 +0800553#if defined(CONFIG_MPC8315)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000554 printf(" TDM: %-4s MHz\n",
555 strmhz(buf, gd->arch.tdm_clk));
Dave Liue0cfec82007-09-18 12:36:58 +0800556#endif
Rini van Zettena2496172010-04-15 16:03:05 +0200557#if defined(CONFIG_FSL_ESDHC)
Simon Glass9e247d12012-12-13 20:49:05 +0000558 printf(" SDHC: %-4s MHz\n",
559 strmhz(buf, gd->arch.sdhc_clk));
Dave Liu5245ff52007-09-18 12:36:11 +0800560#endif
Ilya Yanoka3e5fd52010-06-28 16:44:33 +0400561#if defined(CONFIG_MPC8308) || defined(CONFIG_MPC831x) || \
562 defined(CONFIG_MPC834x) || defined(CONFIG_MPC837x)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000563 printf(" TSEC1: %-4s MHz\n",
564 strmhz(buf, gd->arch.tsec1_clk));
565 printf(" TSEC2: %-4s MHz\n",
566 strmhz(buf, gd->arch.tsec2_clk));
567 printf(" USB DR: %-4s MHz\n",
568 strmhz(buf, gd->arch.usbdr_clk));
Gerlando Falautofe201cb2012-10-10 22:13:08 +0000569#elif defined(CONFIG_MPC8309)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000570 printf(" USB DR: %-4s MHz\n",
571 strmhz(buf, gd->arch.usbdr_clk));
Dave Liua46daea2006-11-03 19:33:44 -0600572#endif
Peter Tyser72f2d392009-05-22 17:23:25 -0500573#if defined(CONFIG_MPC834x)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000574 printf(" USB MPH: %-4s MHz\n",
575 strmhz(buf, gd->arch.usbmph_clk));
Scott Woodc036fc92007-04-16 14:34:19 -0500576#endif
Bill Cook5a043d92011-05-25 15:51:07 -0400577#if defined(CONFIG_MPC8308) || defined(CONFIG_MPC831x) || \
578 defined(CONFIG_MPC837x)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000579 printf(" PCIEXP1: %-4s MHz\n",
580 strmhz(buf, gd->arch.pciexp1_clk));
581 printf(" PCIEXP2: %-4s MHz\n",
582 strmhz(buf, gd->arch.pciexp2_clk));
Dave Liue0cfec82007-09-18 12:36:58 +0800583#endif
Peter Tyser72f2d392009-05-22 17:23:25 -0500584#if defined(CONFIG_MPC837x) || defined(CONFIG_MPC8315)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000585 printf(" SATA: %-4s MHz\n",
586 strmhz(buf, gd->arch.sata_clk));
Dave Liu5245ff52007-09-18 12:36:11 +0800587#endif
Jon Loeligerebc72242005-08-01 13:20:47 -0500588 return 0;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500589}
Kim Phillipsd82b0772007-04-30 15:26:21 -0500590
591U_BOOT_CMD(clocks, 1, 0, do_clocks,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600592 "print clock configuration",
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200593 " clocks"
Kim Phillipsd82b0772007-04-30 15:26:21 -0500594);
Mario Six7cab1472018-08-06 10:23:36 +0200595
596#endif