blob: f835263f25d8ff9431916b7c98dc443baae58e34 [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>
Simon Glass85d65312019-12-28 10:44:58 -070012#include <clock_legacy.h>
Eran Liberty9095d4a2005-07-28 10:08:46 -050013#include <mpc83xx.h>
Kim Phillipsd82b0772007-04-30 15:26:21 -050014#include <command.h>
Simon Glassf5c208d2019-11-14 12:57:20 -070015#include <vsprintf.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060016#include <asm/global_data.h>
Eran Liberty9095d4a2005-07-28 10:08:46 -050017#include <asm/processor.h>
18
Wolfgang Denk6405a152006-03-31 18:32:53 +020019DECLARE_GLOBAL_DATA_PTR;
20
Eran Liberty9095d4a2005-07-28 10:08:46 -050021/* ----------------------------------------------------------------- */
22
23typedef enum {
24 _unk,
25 _off,
26 _byp,
27 _x8,
28 _x4,
29 _x2,
30 _x1,
31 _1x,
32 _1_5x,
33 _2x,
34 _2_5x,
35 _3x
36} mult_t;
37
38typedef struct {
39 mult_t core_csb_ratio;
Kim Phillipsbae24792006-11-02 19:47:11 -060040 mult_t vco_divider;
Eran Liberty9095d4a2005-07-28 10:08:46 -050041} corecnf_t;
42
Kim Phillipsb5c312a2012-10-29 13:34:39 +000043static corecnf_t corecnf_tab[] = {
Kim Phillipsbae24792006-11-02 19:47:11 -060044 {_byp, _byp}, /* 0x00 */
45 {_byp, _byp}, /* 0x01 */
46 {_byp, _byp}, /* 0x02 */
47 {_byp, _byp}, /* 0x03 */
48 {_byp, _byp}, /* 0x04 */
49 {_byp, _byp}, /* 0x05 */
50 {_byp, _byp}, /* 0x06 */
51 {_byp, _byp}, /* 0x07 */
52 {_1x, _x2}, /* 0x08 */
53 {_1x, _x4}, /* 0x09 */
54 {_1x, _x8}, /* 0x0A */
55 {_1x, _x8}, /* 0x0B */
56 {_1_5x, _x2}, /* 0x0C */
57 {_1_5x, _x4}, /* 0x0D */
58 {_1_5x, _x8}, /* 0x0E */
59 {_1_5x, _x8}, /* 0x0F */
60 {_2x, _x2}, /* 0x10 */
61 {_2x, _x4}, /* 0x11 */
62 {_2x, _x8}, /* 0x12 */
63 {_2x, _x8}, /* 0x13 */
64 {_2_5x, _x2}, /* 0x14 */
65 {_2_5x, _x4}, /* 0x15 */
66 {_2_5x, _x8}, /* 0x16 */
67 {_2_5x, _x8}, /* 0x17 */
68 {_3x, _x2}, /* 0x18 */
69 {_3x, _x4}, /* 0x19 */
70 {_3x, _x8}, /* 0x1A */
71 {_3x, _x8}, /* 0x1B */
Eran Liberty9095d4a2005-07-28 10:08:46 -050072};
73
74/* ----------------------------------------------------------------- */
75
76/*
77 *
78 */
Kim Phillipsbae24792006-11-02 19:47:11 -060079int get_clocks(void)
Eran Liberty9095d4a2005-07-28 10:08:46 -050080{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020081 volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
Eran Liberty9095d4a2005-07-28 10:08:46 -050082 u32 pci_sync_in;
Kim Phillipsbae24792006-11-02 19:47:11 -060083 u8 spmf;
84 u8 clkin_div;
Eran Liberty9095d4a2005-07-28 10:08:46 -050085 u32 sccr;
86 u32 corecnf_tab_index;
Kim Phillipsbae24792006-11-02 19:47:11 -060087 u8 corepll;
Eran Liberty9095d4a2005-07-28 10:08:46 -050088 u32 lcrr;
Jon Loeligerebc72242005-08-01 13:20:47 -050089
Eran Liberty9095d4a2005-07-28 10:08:46 -050090 u32 csb_clk;
Mario Six9164bdd2019-01-21 09:17:25 +010091#if defined(CONFIG_ARCH_MPC8308) || defined(CONFIG_ARCH_MPC831X) || \
Mario Six60b11232019-01-21 09:17:29 +010092 defined(CONFIG_ARCH_MPC834X) || defined(CONFIG_ARCH_MPC837X)
Eran Liberty9095d4a2005-07-28 10:08:46 -050093 u32 tsec1_clk;
94 u32 tsec2_clk;
Eran Liberty9095d4a2005-07-28 10:08:46 -050095 u32 usbdr_clk;
Mario Sixb2e701c2019-01-21 09:17:24 +010096#elif defined(CONFIG_ARCH_MPC8309)
Gerlando Falautofe201cb2012-10-10 22:13:08 +000097 u32 usbdr_clk;
Dave Liua46daea2006-11-03 19:33:44 -060098#endif
Mario Six0344f5e2019-01-21 09:17:27 +010099#ifdef CONFIG_ARCH_MPC834X
Scott Woodc036fc92007-04-16 14:34:19 -0500100 u32 usbmph_clk;
101#endif
Dave Liua46daea2006-11-03 19:33:44 -0600102 u32 core_clk;
103 u32 i2c1_clk;
Mario Sixbe07e552019-01-21 09:17:26 +0100104#if !defined(CONFIG_ARCH_MPC832X)
Dave Liua46daea2006-11-03 19:33:44 -0600105 u32 i2c2_clk;
Dave Liue740c462006-12-07 21:13:15 +0800106#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
Mario Sixb2e701c2019-01-21 09:17:24 +0100110#if !defined(CONFIG_ARCH_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;
Mario Six84eb4312019-01-21 09:17:28 +0100116#if defined(CONFIG_ARCH_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
Mario Six9164bdd2019-01-21 09:17:25 +0100125#if defined(CONFIG_ARCH_MPC8308) || defined(CONFIG_ARCH_MPC831X) || \
Mario Six60b11232019-01-21 09:17:29 +0100126 defined(CONFIG_ARCH_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
Tom Rinid9e6ef52021-05-14 21:34:27 -0400130#if defined(CONFIG_ARCH_MPC837X)
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) {
Tom Rini8c70baa2021-12-14 13:36:40 -0500140#if CONFIG_SYS_CLK_FREQ != 0
141 pci_sync_in = get_board_sys_clk() / (1 + clkin_div);
Dave Liua46daea2006-11-03 19:33:44 -0600142#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
Mario Six9164bdd2019-01-21 09:17:25 +0100158#if defined(CONFIG_ARCH_MPC8308) || defined(CONFIG_ARCH_MPC831X) || \
Mario Six60b11232019-01-21 09:17:29 +0100159 defined(CONFIG_ARCH_MPC834X) || defined(CONFIG_ARCH_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
Mario Six9164bdd2019-01-21 09:17:25 +0100179#if defined(CONFIG_ARCH_MPC830X) || defined(CONFIG_ARCH_MPC831X) || \
Mario Six60b11232019-01-21 09:17:29 +0100180 defined(CONFIG_ARCH_MPC834X) || defined(CONFIG_ARCH_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
Tom Rinid9e6ef52021-05-14 21:34:27 -0400200#if defined(CONFIG_ARCH_MPC8308) || defined(CONFIG_ARCH_MPC834X) || \
201 defined(CONFIG_ARCH_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 }
Mario Six9164bdd2019-01-21 09:17:25 +0100219#elif defined(CONFIG_ARCH_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
Mario Six0344f5e2019-01-21 09:17:27 +0100228#if defined(CONFIG_ARCH_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
Mario Sixb2e701c2019-01-21 09:17:24 +0100255#if !defined(CONFIG_ARCH_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
Scott Woodc036fc92007-04-16 14:34:19 -0500294
Mario Six0344f5e2019-01-21 09:17:27 +0100295#if defined(CONFIG_ARCH_MPC834X)
Dave Liu5245ff52007-09-18 12:36:11 +0800296 i2c1_clk = tsec2_clk;
Mario Six84eb4312019-01-21 09:17:28 +0100297#elif defined(CONFIG_ARCH_MPC8360)
Dave Liua46daea2006-11-03 19:33:44 -0600298 i2c1_clk = csb_clk;
Mario Sixbe07e552019-01-21 09:17:26 +0100299#elif defined(CONFIG_ARCH_MPC832X)
Dave Liu5245ff52007-09-18 12:36:11 +0800300 i2c1_clk = enc_clk;
Mario Six9164bdd2019-01-21 09:17:25 +0100301#elif defined(CONFIG_ARCH_MPC8308) || defined(CONFIG_ARCH_MPC831X)
Dave Liu5245ff52007-09-18 12:36:11 +0800302 i2c1_clk = enc_clk;
Rini van Zettena2496172010-04-15 16:03:05 +0200303#elif defined(CONFIG_FSL_ESDHC)
Dave Liu5245ff52007-09-18 12:36:11 +0800304 i2c1_clk = sdhc_clk;
Mario Six60b11232019-01-21 09:17:29 +0100305#elif defined(CONFIG_ARCH_MPC837X)
Andre Schwarza76cc612011-04-14 14:57:40 +0200306 i2c1_clk = enc_clk;
Mario Sixb2e701c2019-01-21 09:17:24 +0100307#elif defined(CONFIG_ARCH_MPC8309)
Gerlando Falautofe201cb2012-10-10 22:13:08 +0000308 i2c1_clk = csb_clk;
Dave Liua46daea2006-11-03 19:33:44 -0600309#endif
Mario Sixbe07e552019-01-21 09:17:26 +0100310#if !defined(CONFIG_ARCH_MPC832X)
Dave Liu5245ff52007-09-18 12:36:11 +0800311 i2c2_clk = csb_clk; /* i2c-2 clk is equal to csb clk */
Dave Liue740c462006-12-07 21:13:15 +0800312#endif
Jon Loeligerebc72242005-08-01 13:20:47 -0500313
Mario Six9164bdd2019-01-21 09:17:25 +0100314#if defined(CONFIG_ARCH_MPC8308) || defined(CONFIG_ARCH_MPC831X) || \
Mario Six60b11232019-01-21 09:17:29 +0100315 defined(CONFIG_ARCH_MPC837X)
Dave Liu5245ff52007-09-18 12:36:11 +0800316 switch ((sccr & SCCR_PCIEXP1CM) >> SCCR_PCIEXP1CM_SHIFT) {
Dave Liua46daea2006-11-03 19:33:44 -0600317 case 0:
Dave Liu5245ff52007-09-18 12:36:11 +0800318 pciexp1_clk = 0;
Dave Liua46daea2006-11-03 19:33:44 -0600319 break;
320 case 1:
Dave Liu5245ff52007-09-18 12:36:11 +0800321 pciexp1_clk = csb_clk;
Dave Liua46daea2006-11-03 19:33:44 -0600322 break;
323 case 2:
Dave Liu5245ff52007-09-18 12:36:11 +0800324 pciexp1_clk = csb_clk / 2;
Dave Liua46daea2006-11-03 19:33:44 -0600325 break;
326 case 3:
Dave Liu5245ff52007-09-18 12:36:11 +0800327 pciexp1_clk = csb_clk / 3;
Dave Liua46daea2006-11-03 19:33:44 -0600328 break;
329 default:
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500330 /* unknown SCCR_PCIEXP1CM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800331 return -9;
Dave Liua46daea2006-11-03 19:33:44 -0600332 }
Dave Liue740c462006-12-07 21:13:15 +0800333
Dave Liu5245ff52007-09-18 12:36:11 +0800334 switch ((sccr & SCCR_PCIEXP2CM) >> SCCR_PCIEXP2CM_SHIFT) {
335 case 0:
336 pciexp2_clk = 0;
337 break;
338 case 1:
339 pciexp2_clk = csb_clk;
340 break;
341 case 2:
342 pciexp2_clk = csb_clk / 2;
343 break;
344 case 3:
345 pciexp2_clk = csb_clk / 3;
346 break;
347 default:
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500348 /* unknown SCCR_PCIEXP2CM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800349 return -10;
350 }
351#endif
352
Tom Rinid9e6ef52021-05-14 21:34:27 -0400353#if defined(CONFIG_ARCH_MPC837X)
Dave Liub7896ad2008-01-17 18:23:19 +0800354 switch ((sccr & SCCR_SATA1CM) >> SCCR_SATA1CM_SHIFT) {
355 case 0:
Dave Liu5245ff52007-09-18 12:36:11 +0800356 sata_clk = 0;
357 break;
Dave Liub7896ad2008-01-17 18:23:19 +0800358 case 1:
Dave Liu5245ff52007-09-18 12:36:11 +0800359 sata_clk = csb_clk;
360 break;
Dave Liub7896ad2008-01-17 18:23:19 +0800361 case 2:
Dave Liu5245ff52007-09-18 12:36:11 +0800362 sata_clk = csb_clk / 2;
363 break;
Dave Liub7896ad2008-01-17 18:23:19 +0800364 case 3:
Dave Liu5245ff52007-09-18 12:36:11 +0800365 sata_clk = csb_clk / 3;
366 break;
367 default:
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500368 /* unknown SCCR_SATA1CM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800369 return -11;
370 }
371#endif
372
Kim Phillipsbae24792006-11-02 19:47:11 -0600373 lbiu_clk = csb_clk *
Joakim Tjernlundf2af1bb2011-01-27 16:30:54 +0100374 (1 + ((im->clk.spmr & SPMR_LBIUCM) >> SPMR_LBIUCM_SHIFT));
Becky Bruce0d4cee12010-06-17 11:37:20 -0500375 lcrr = (im->im_lbc.lcrr & LCRR_CLKDIV) >> LCRR_CLKDIV_SHIFT;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500376 switch (lcrr) {
377 case 2:
378 case 4:
379 case 8:
380 lclk_clk = lbiu_clk / lcrr;
381 break;
382 default:
383 /* unknown lcrr */
Dave Liu5245ff52007-09-18 12:36:11 +0800384 return -12;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500385 }
Dave Liue740c462006-12-07 21:13:15 +0800386
Kim Phillipsc02cf1e2008-03-28 10:18:40 -0500387 mem_clk = csb_clk *
Joakim Tjernlundf2af1bb2011-01-27 16:30:54 +0100388 (1 + ((im->clk.spmr & SPMR_DDRCM) >> SPMR_DDRCM_SHIFT));
389 corepll = (im->clk.spmr & SPMR_COREPLL) >> SPMR_COREPLL_SHIFT;
390
Mario Six84eb4312019-01-21 09:17:28 +0100391#if defined(CONFIG_ARCH_MPC8360)
Kim Phillipsc02cf1e2008-03-28 10:18:40 -0500392 mem_sec_clk = csb_clk * (1 +
Joakim Tjernlundf2af1bb2011-01-27 16:30:54 +0100393 ((im->clk.spmr & SPMR_LBIUCM) >> SPMR_LBIUCM_SHIFT));
Dave Liua46daea2006-11-03 19:33:44 -0600394#endif
Dave Liua46daea2006-11-03 19:33:44 -0600395
Eran Liberty9095d4a2005-07-28 10:08:46 -0500396 corecnf_tab_index = ((corepll & 0x1F) << 2) | ((corepll & 0x60) >> 5);
Robert P. J. Day0c911592016-05-23 06:49:21 -0400397 if (corecnf_tab_index > (ARRAY_SIZE(corecnf_tab))) {
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500398 /* corecnf_tab_index is too high, possibly wrong value */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500399 return -11;
400 }
401 switch (corecnf_tab[corecnf_tab_index].core_csb_ratio) {
402 case _byp:
403 case _x1:
404 case _1x:
405 core_clk = csb_clk;
406 break;
407 case _1_5x:
408 core_clk = (3 * csb_clk) / 2;
409 break;
410 case _2x:
411 core_clk = 2 * csb_clk;
412 break;
413 case _2_5x:
Kim Phillipsbae24792006-11-02 19:47:11 -0600414 core_clk = (5 * csb_clk) / 2;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500415 break;
416 case _3x:
417 core_clk = 3 * csb_clk;
418 break;
419 default:
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500420 /* unknown core to csb ratio */
Dave Liu5245ff52007-09-18 12:36:11 +0800421 return -13;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500422 }
Jon Loeligerebc72242005-08-01 13:20:47 -0500423
Gerlando Falauto77cf2832012-10-10 22:13:06 +0000424#if defined(CONFIG_QE)
Joakim Tjernlundf2af1bb2011-01-27 16:30:54 +0100425 qepmf = (im->clk.spmr & SPMR_CEPMF) >> SPMR_CEPMF_SHIFT;
426 qepdf = (im->clk.spmr & SPMR_CEPDF) >> SPMR_CEPDF_SHIFT;
Kim Phillipsbae24792006-11-02 19:47:11 -0600427 qe_clk = (pci_sync_in * qepmf) / (1 + qepdf);
Dave Liua46daea2006-11-03 19:33:44 -0600428 brg_clk = qe_clk / 2;
429#endif
Jon Loeligerebc72242005-08-01 13:20:47 -0500430
Simon Glasscc76e9e2012-12-13 20:48:47 +0000431 gd->arch.csb_clk = csb_clk;
Mario Six9164bdd2019-01-21 09:17:25 +0100432#if defined(CONFIG_ARCH_MPC8308) || defined(CONFIG_ARCH_MPC831X) || \
Mario Six60b11232019-01-21 09:17:29 +0100433 defined(CONFIG_ARCH_MPC834X) || defined(CONFIG_ARCH_MPC837X)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000434 gd->arch.tsec1_clk = tsec1_clk;
435 gd->arch.tsec2_clk = tsec2_clk;
436 gd->arch.usbdr_clk = usbdr_clk;
Mario Sixb2e701c2019-01-21 09:17:24 +0100437#elif defined(CONFIG_ARCH_MPC8309)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000438 gd->arch.usbdr_clk = usbdr_clk;
Dave Liua46daea2006-11-03 19:33:44 -0600439#endif
Mario Six0344f5e2019-01-21 09:17:27 +0100440#if defined(CONFIG_ARCH_MPC834X)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000441 gd->arch.usbmph_clk = usbmph_clk;
Scott Woodc036fc92007-04-16 14:34:19 -0500442#endif
Rini van Zettena2496172010-04-15 16:03:05 +0200443#if defined(CONFIG_FSL_ESDHC)
Simon Glass9e247d12012-12-13 20:49:05 +0000444 gd->arch.sdhc_clk = sdhc_clk;
Dave Liu5245ff52007-09-18 12:36:11 +0800445#endif
Simon Glasscc76e9e2012-12-13 20:48:47 +0000446 gd->arch.core_clk = core_clk;
Simon Glassc2baaec2012-12-13 20:48:49 +0000447 gd->arch.i2c1_clk = i2c1_clk;
Mario Sixbe07e552019-01-21 09:17:26 +0100448#if !defined(CONFIG_ARCH_MPC832X)
Simon Glassc2baaec2012-12-13 20:48:49 +0000449 gd->arch.i2c2_clk = i2c2_clk;
Dave Liue740c462006-12-07 21:13:15 +0800450#endif
Mario Sixb2e701c2019-01-21 09:17:24 +0100451#if !defined(CONFIG_ARCH_MPC8309)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000452 gd->arch.enc_clk = enc_clk;
Gerlando Falautofe201cb2012-10-10 22:13:08 +0000453#endif
Simon Glasscc76e9e2012-12-13 20:48:47 +0000454 gd->arch.lbiu_clk = lbiu_clk;
455 gd->arch.lclk_clk = lclk_clk;
Kim Phillipsc02cf1e2008-03-28 10:18:40 -0500456 gd->mem_clk = mem_clk;
Mario Six84eb4312019-01-21 09:17:28 +0100457#if defined(CONFIG_ARCH_MPC8360)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000458 gd->arch.mem_sec_clk = mem_sec_clk;
Dave Liue740c462006-12-07 21:13:15 +0800459#endif
Gerlando Falauto77cf2832012-10-10 22:13:06 +0000460#if defined(CONFIG_QE)
Simon Glass8518b172012-12-13 20:48:50 +0000461 gd->arch.qe_clk = qe_clk;
Simon Glass34a194f2012-12-13 20:48:44 +0000462 gd->arch.brg_clk = brg_clk;
Dave Liua46daea2006-11-03 19:33:44 -0600463#endif
Mario Six9164bdd2019-01-21 09:17:25 +0100464#if defined(CONFIG_ARCH_MPC8308) || defined(CONFIG_ARCH_MPC831X) || \
Mario Six60b11232019-01-21 09:17:29 +0100465 defined(CONFIG_ARCH_MPC837X)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000466 gd->arch.pciexp1_clk = pciexp1_clk;
467 gd->arch.pciexp2_clk = pciexp2_clk;
Dave Liue0cfec82007-09-18 12:36:58 +0800468#endif
Tom Rinid9e6ef52021-05-14 21:34:27 -0400469#if defined(CONFIG_ARCH_MPC837X)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000470 gd->arch.sata_clk = sata_clk;
Dave Liu5245ff52007-09-18 12:36:11 +0800471#endif
Kim Phillipscd9fd702007-08-15 22:30:19 -0500472 gd->pci_clk = pci_sync_in;
Simon Glasscc76e9e2012-12-13 20:48:47 +0000473 gd->cpu_clk = gd->arch.core_clk;
474 gd->bus_clk = gd->arch.csb_clk;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500475 return 0;
Dave Liua46daea2006-11-03 19:33:44 -0600476
Eran Liberty9095d4a2005-07-28 10:08:46 -0500477}
478
479/********************************************
480 * get_bus_freq
481 * return system bus freq in Hz
482 *********************************************/
Kim Phillipsbae24792006-11-02 19:47:11 -0600483ulong get_bus_freq(ulong dummy)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500484{
Simon Glasscc76e9e2012-12-13 20:48:47 +0000485 return gd->arch.csb_clk;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500486}
487
York Sune12ce982011-08-26 11:32:44 -0700488/********************************************
489 * get_ddr_freq
490 * return ddr bus freq in Hz
491 *********************************************/
492ulong get_ddr_freq(ulong dummy)
493{
494 return gd->mem_clk;
495}
496
Mario Six2fc52272019-01-21 09:18:05 +0100497int get_serial_clock(void)
498{
499 return get_bus_freq(0);
500}
501
Simon Glassed38aef2020-05-10 11:40:03 -0600502static int do_clocks(struct cmd_tbl *cmdtp, int flag, int argc,
503 char *const argv[])
Eran Liberty9095d4a2005-07-28 10:08:46 -0500504{
Wolfgang Denk20591042008-10-19 02:35:49 +0200505 char buf[32];
506
Eran Liberty9095d4a2005-07-28 10:08:46 -0500507 printf("Clock configuration:\n");
Simon Glasscc76e9e2012-12-13 20:48:47 +0000508 printf(" Core: %-4s MHz\n",
509 strmhz(buf, gd->arch.core_clk));
510 printf(" Coherent System Bus: %-4s MHz\n",
511 strmhz(buf, gd->arch.csb_clk));
Gerlando Falauto77cf2832012-10-10 22:13:06 +0000512#if defined(CONFIG_QE)
Simon Glass8518b172012-12-13 20:48:50 +0000513 printf(" QE: %-4s MHz\n",
514 strmhz(buf, gd->arch.qe_clk));
Simon Glass34a194f2012-12-13 20:48:44 +0000515 printf(" BRG: %-4s MHz\n",
516 strmhz(buf, gd->arch.brg_clk));
Dave Liua46daea2006-11-03 19:33:44 -0600517#endif
Simon Glasscc76e9e2012-12-13 20:48:47 +0000518 printf(" Local Bus Controller:%-4s MHz\n",
519 strmhz(buf, gd->arch.lbiu_clk));
520 printf(" Local Bus: %-4s MHz\n",
521 strmhz(buf, gd->arch.lclk_clk));
Wolfgang Denk20591042008-10-19 02:35:49 +0200522 printf(" DDR: %-4s MHz\n", strmhz(buf, gd->mem_clk));
Mario Six84eb4312019-01-21 09:17:28 +0100523#if defined(CONFIG_ARCH_MPC8360)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000524 printf(" DDR Secondary: %-4s MHz\n",
525 strmhz(buf, gd->arch.mem_sec_clk));
Dave Liua46daea2006-11-03 19:33:44 -0600526#endif
Mario Sixb2e701c2019-01-21 09:17:24 +0100527#if !defined(CONFIG_ARCH_MPC8309)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000528 printf(" SEC: %-4s MHz\n",
529 strmhz(buf, gd->arch.enc_clk));
Gerlando Falautofe201cb2012-10-10 22:13:08 +0000530#endif
Simon Glassc2baaec2012-12-13 20:48:49 +0000531 printf(" I2C1: %-4s MHz\n",
532 strmhz(buf, gd->arch.i2c1_clk));
Mario Sixbe07e552019-01-21 09:17:26 +0100533#if !defined(CONFIG_ARCH_MPC832X)
Simon Glassc2baaec2012-12-13 20:48:49 +0000534 printf(" I2C2: %-4s MHz\n",
535 strmhz(buf, gd->arch.i2c2_clk));
Dave Liue740c462006-12-07 21:13:15 +0800536#endif
Rini van Zettena2496172010-04-15 16:03:05 +0200537#if defined(CONFIG_FSL_ESDHC)
Simon Glass9e247d12012-12-13 20:49:05 +0000538 printf(" SDHC: %-4s MHz\n",
539 strmhz(buf, gd->arch.sdhc_clk));
Dave Liu5245ff52007-09-18 12:36:11 +0800540#endif
Mario Six9164bdd2019-01-21 09:17:25 +0100541#if defined(CONFIG_ARCH_MPC8308) || defined(CONFIG_ARCH_MPC831X) || \
Mario Six60b11232019-01-21 09:17:29 +0100542 defined(CONFIG_ARCH_MPC834X) || defined(CONFIG_ARCH_MPC837X)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000543 printf(" TSEC1: %-4s MHz\n",
544 strmhz(buf, gd->arch.tsec1_clk));
545 printf(" TSEC2: %-4s MHz\n",
546 strmhz(buf, gd->arch.tsec2_clk));
547 printf(" USB DR: %-4s MHz\n",
548 strmhz(buf, gd->arch.usbdr_clk));
Mario Sixb2e701c2019-01-21 09:17:24 +0100549#elif defined(CONFIG_ARCH_MPC8309)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000550 printf(" USB DR: %-4s MHz\n",
551 strmhz(buf, gd->arch.usbdr_clk));
Dave Liua46daea2006-11-03 19:33:44 -0600552#endif
Mario Six0344f5e2019-01-21 09:17:27 +0100553#if defined(CONFIG_ARCH_MPC834X)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000554 printf(" USB MPH: %-4s MHz\n",
555 strmhz(buf, gd->arch.usbmph_clk));
Scott Woodc036fc92007-04-16 14:34:19 -0500556#endif
Mario Six9164bdd2019-01-21 09:17:25 +0100557#if defined(CONFIG_ARCH_MPC8308) || defined(CONFIG_ARCH_MPC831X) || \
Mario Six60b11232019-01-21 09:17:29 +0100558 defined(CONFIG_ARCH_MPC837X)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000559 printf(" PCIEXP1: %-4s MHz\n",
560 strmhz(buf, gd->arch.pciexp1_clk));
561 printf(" PCIEXP2: %-4s MHz\n",
562 strmhz(buf, gd->arch.pciexp2_clk));
Dave Liue0cfec82007-09-18 12:36:58 +0800563#endif
Tom Rinid9e6ef52021-05-14 21:34:27 -0400564#if defined(CONFIG_ARCH_MPC837X)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000565 printf(" SATA: %-4s MHz\n",
566 strmhz(buf, gd->arch.sata_clk));
Dave Liu5245ff52007-09-18 12:36:11 +0800567#endif
Jon Loeligerebc72242005-08-01 13:20:47 -0500568 return 0;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500569}
Kim Phillipsd82b0772007-04-30 15:26:21 -0500570
571U_BOOT_CMD(clocks, 1, 0, do_clocks,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600572 "print clock configuration",
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200573 " clocks"
Kim Phillipsd82b0772007-04-30 15:26:21 -0500574);
Mario Six7cab1472018-08-06 10:23:36 +0200575
576#endif