blob: b7a87fec2f5b44867c1d409754e2a859af3f6e58 [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;
Dave Liua46daea2006-11-03 19:33:44 -060096#endif
Mario Six0344f5e2019-01-21 09:17:27 +010097#ifdef CONFIG_ARCH_MPC834X
Scott Woodc036fc92007-04-16 14:34:19 -050098 u32 usbmph_clk;
99#endif
Dave Liua46daea2006-11-03 19:33:44 -0600100 u32 core_clk;
101 u32 i2c1_clk;
Mario Sixbe07e552019-01-21 09:17:26 +0100102#if !defined(CONFIG_ARCH_MPC832X)
Dave Liua46daea2006-11-03 19:33:44 -0600103 u32 i2c2_clk;
Dave Liue740c462006-12-07 21:13:15 +0800104#endif
Rini van Zettena2496172010-04-15 16:03:05 +0200105#if defined(CONFIG_FSL_ESDHC)
Dave Liu5245ff52007-09-18 12:36:11 +0800106 u32 sdhc_clk;
107#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500108 u32 enc_clk;
109 u32 lbiu_clk;
110 u32 lclk_clk;
Kim Phillipsc02cf1e2008-03-28 10:18:40 -0500111 u32 mem_clk;
Mario Six84eb4312019-01-21 09:17:28 +0100112#if defined(CONFIG_ARCH_MPC8360)
Kim Phillipsc02cf1e2008-03-28 10:18:40 -0500113 u32 mem_sec_clk;
Dave Liue740c462006-12-07 21:13:15 +0800114#endif
Gerlando Falauto77cf2832012-10-10 22:13:06 +0000115#if defined(CONFIG_QE)
Dave Liua46daea2006-11-03 19:33:44 -0600116 u32 qepmf;
117 u32 qepdf;
Dave Liua46daea2006-11-03 19:33:44 -0600118 u32 qe_clk;
119 u32 brg_clk;
120#endif
Mario Six9164bdd2019-01-21 09:17:25 +0100121#if defined(CONFIG_ARCH_MPC8308) || defined(CONFIG_ARCH_MPC831X) || \
Mario Six60b11232019-01-21 09:17:29 +0100122 defined(CONFIG_ARCH_MPC837X)
Dave Liu5245ff52007-09-18 12:36:11 +0800123 u32 pciexp1_clk;
124 u32 pciexp2_clk;
Dave Liue0cfec82007-09-18 12:36:58 +0800125#endif
Tom Rinid9e6ef52021-05-14 21:34:27 -0400126#if defined(CONFIG_ARCH_MPC837X)
Dave Liu5245ff52007-09-18 12:36:11 +0800127 u32 sata_clk;
128#endif
Jon Loeligerebc72242005-08-01 13:20:47 -0500129
Kim Phillipsbae24792006-11-02 19:47:11 -0600130 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500131 return -1;
Jon Loeligerebc72242005-08-01 13:20:47 -0500132
Dave Liua46daea2006-11-03 19:33:44 -0600133 clkin_div = ((im->clk.spmr & SPMR_CKID) >> SPMR_CKID_SHIFT);
Marian Balakowicz513b4a12005-10-11 19:09:42 +0200134
Dave Liua46daea2006-11-03 19:33:44 -0600135 if (im->reset.rcwh & HRCWH_PCI_HOST) {
Tom Rini8c70baa2021-12-14 13:36:40 -0500136#if CONFIG_SYS_CLK_FREQ != 0
137 pci_sync_in = get_board_sys_clk() / (1 + clkin_div);
Dave Liua46daea2006-11-03 19:33:44 -0600138#else
139 pci_sync_in = 0xDEADBEEF;
140#endif
141 } else {
142#if defined(CONFIG_83XX_PCICLK)
143 pci_sync_in = CONFIG_83XX_PCICLK;
144#else
145 pci_sync_in = 0xDEADBEEF;
146#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500147 }
Marian Balakowicz513b4a12005-10-11 19:09:42 +0200148
Joakim Tjernlundf2af1bb2011-01-27 16:30:54 +0100149 spmf = (im->clk.spmr & SPMR_SPMF) >> SPMR_SPMF_SHIFT;
Dave Liua46daea2006-11-03 19:33:44 -0600150 csb_clk = pci_sync_in * (1 + clkin_div) * spmf;
Jon Loeligerebc72242005-08-01 13:20:47 -0500151
Eran Liberty9095d4a2005-07-28 10:08:46 -0500152 sccr = im->clk.sccr;
Dave Liua46daea2006-11-03 19:33:44 -0600153
Mario Six9164bdd2019-01-21 09:17:25 +0100154#if defined(CONFIG_ARCH_MPC8308) || defined(CONFIG_ARCH_MPC831X) || \
Mario Six60b11232019-01-21 09:17:29 +0100155 defined(CONFIG_ARCH_MPC834X) || defined(CONFIG_ARCH_MPC837X)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500156 switch ((sccr & SCCR_TSEC1CM) >> SCCR_TSEC1CM_SHIFT) {
157 case 0:
158 tsec1_clk = 0;
159 break;
160 case 1:
161 tsec1_clk = csb_clk;
162 break;
163 case 2:
164 tsec1_clk = csb_clk / 2;
165 break;
166 case 3:
167 tsec1_clk = csb_clk / 3;
168 break;
169 default:
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500170 /* unknown SCCR_TSEC1CM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800171 return -2;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500172 }
Gerlando Falauto74735552012-10-10 22:13:07 +0000173#endif
Jon Loeligerebc72242005-08-01 13:20:47 -0500174
Mario Six9164bdd2019-01-21 09:17:25 +0100175#if defined(CONFIG_ARCH_MPC830X) || defined(CONFIG_ARCH_MPC831X) || \
Mario Six60b11232019-01-21 09:17:29 +0100176 defined(CONFIG_ARCH_MPC834X) || defined(CONFIG_ARCH_MPC837X)
Scott Woodc036fc92007-04-16 14:34:19 -0500177 switch ((sccr & SCCR_USBDRCM) >> SCCR_USBDRCM_SHIFT) {
178 case 0:
179 usbdr_clk = 0;
180 break;
181 case 1:
182 usbdr_clk = csb_clk;
183 break;
184 case 2:
185 usbdr_clk = csb_clk / 2;
186 break;
187 case 3:
188 usbdr_clk = csb_clk / 3;
189 break;
190 default:
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500191 /* unknown SCCR_USBDRCM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800192 return -3;
Scott Woodc036fc92007-04-16 14:34:19 -0500193 }
194#endif
195
Tom Rinid9e6ef52021-05-14 21:34:27 -0400196#if defined(CONFIG_ARCH_MPC8308) || defined(CONFIG_ARCH_MPC834X) || \
197 defined(CONFIG_ARCH_MPC837X)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500198 switch ((sccr & SCCR_TSEC2CM) >> SCCR_TSEC2CM_SHIFT) {
199 case 0:
200 tsec2_clk = 0;
201 break;
202 case 1:
203 tsec2_clk = csb_clk;
204 break;
205 case 2:
206 tsec2_clk = csb_clk / 2;
207 break;
208 case 3:
209 tsec2_clk = csb_clk / 3;
210 break;
211 default:
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500212 /* unknown SCCR_TSEC2CM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800213 return -4;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500214 }
Mario Six9164bdd2019-01-21 09:17:25 +0100215#elif defined(CONFIG_ARCH_MPC8313)
Dave Liu5245ff52007-09-18 12:36:11 +0800216 tsec2_clk = tsec1_clk;
Jon Loeligerebc72242005-08-01 13:20:47 -0500217
Dave Liu5245ff52007-09-18 12:36:11 +0800218 if (!(sccr & SCCR_TSEC1ON))
219 tsec1_clk = 0;
220 if (!(sccr & SCCR_TSEC2ON))
221 tsec2_clk = 0;
222#endif
Jon Loeligerebc72242005-08-01 13:20:47 -0500223
Mario Six0344f5e2019-01-21 09:17:27 +0100224#if defined(CONFIG_ARCH_MPC834X)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500225 switch ((sccr & SCCR_USBMPHCM) >> SCCR_USBMPHCM_SHIFT) {
226 case 0:
227 usbmph_clk = 0;
228 break;
229 case 1:
230 usbmph_clk = csb_clk;
231 break;
232 case 2:
233 usbmph_clk = csb_clk / 2;
234 break;
235 case 3:
236 usbmph_clk = csb_clk / 3;
237 break;
238 default:
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500239 /* unknown SCCR_USBMPHCM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800240 return -5;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500241 }
242
Kim Phillipsbae24792006-11-02 19:47:11 -0600243 if (usbmph_clk != 0 && usbdr_clk != 0 && usbmph_clk != usbdr_clk) {
244 /* if USB MPH clock is not disabled and
245 * USB DR clock is not disabled then
246 * USB MPH & USB DR must have the same rate
247 */
Dave Liu5245ff52007-09-18 12:36:11 +0800248 return -6;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500249 }
Dave Liu5245ff52007-09-18 12:36:11 +0800250#endif
251 switch ((sccr & SCCR_ENCCM) >> SCCR_ENCCM_SHIFT) {
252 case 0:
253 enc_clk = 0;
254 break;
255 case 1:
256 enc_clk = csb_clk;
257 break;
258 case 2:
259 enc_clk = csb_clk / 2;
260 break;
261 case 3:
262 enc_clk = csb_clk / 3;
263 break;
264 default:
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500265 /* unknown SCCR_ENCCM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800266 return -7;
267 }
Scott Woodc036fc92007-04-16 14:34:19 -0500268
Rini van Zettena2496172010-04-15 16:03:05 +0200269#if defined(CONFIG_FSL_ESDHC)
Dave Liu5245ff52007-09-18 12:36:11 +0800270 switch ((sccr & SCCR_SDHCCM) >> SCCR_SDHCCM_SHIFT) {
271 case 0:
272 sdhc_clk = 0;
273 break;
274 case 1:
275 sdhc_clk = csb_clk;
276 break;
277 case 2:
278 sdhc_clk = csb_clk / 2;
279 break;
280 case 3:
281 sdhc_clk = csb_clk / 3;
282 break;
283 default:
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500284 /* unknown SCCR_SDHCCM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800285 return -8;
286 }
Dave Liua46daea2006-11-03 19:33:44 -0600287#endif
Scott Woodc036fc92007-04-16 14:34:19 -0500288
Mario Six0344f5e2019-01-21 09:17:27 +0100289#if defined(CONFIG_ARCH_MPC834X)
Dave Liu5245ff52007-09-18 12:36:11 +0800290 i2c1_clk = tsec2_clk;
Mario Six84eb4312019-01-21 09:17:28 +0100291#elif defined(CONFIG_ARCH_MPC8360)
Dave Liua46daea2006-11-03 19:33:44 -0600292 i2c1_clk = csb_clk;
Mario Sixbe07e552019-01-21 09:17:26 +0100293#elif defined(CONFIG_ARCH_MPC832X)
Dave Liu5245ff52007-09-18 12:36:11 +0800294 i2c1_clk = enc_clk;
Mario Six9164bdd2019-01-21 09:17:25 +0100295#elif defined(CONFIG_ARCH_MPC8308) || defined(CONFIG_ARCH_MPC831X)
Dave Liu5245ff52007-09-18 12:36:11 +0800296 i2c1_clk = enc_clk;
Rini van Zettena2496172010-04-15 16:03:05 +0200297#elif defined(CONFIG_FSL_ESDHC)
Dave Liu5245ff52007-09-18 12:36:11 +0800298 i2c1_clk = sdhc_clk;
Mario Six60b11232019-01-21 09:17:29 +0100299#elif defined(CONFIG_ARCH_MPC837X)
Andre Schwarza76cc612011-04-14 14:57:40 +0200300 i2c1_clk = enc_clk;
Dave Liua46daea2006-11-03 19:33:44 -0600301#endif
Mario Sixbe07e552019-01-21 09:17:26 +0100302#if !defined(CONFIG_ARCH_MPC832X)
Dave Liu5245ff52007-09-18 12:36:11 +0800303 i2c2_clk = csb_clk; /* i2c-2 clk is equal to csb clk */
Dave Liue740c462006-12-07 21:13:15 +0800304#endif
Jon Loeligerebc72242005-08-01 13:20:47 -0500305
Mario Six9164bdd2019-01-21 09:17:25 +0100306#if defined(CONFIG_ARCH_MPC8308) || defined(CONFIG_ARCH_MPC831X) || \
Mario Six60b11232019-01-21 09:17:29 +0100307 defined(CONFIG_ARCH_MPC837X)
Dave Liu5245ff52007-09-18 12:36:11 +0800308 switch ((sccr & SCCR_PCIEXP1CM) >> SCCR_PCIEXP1CM_SHIFT) {
Dave Liua46daea2006-11-03 19:33:44 -0600309 case 0:
Dave Liu5245ff52007-09-18 12:36:11 +0800310 pciexp1_clk = 0;
Dave Liua46daea2006-11-03 19:33:44 -0600311 break;
312 case 1:
Dave Liu5245ff52007-09-18 12:36:11 +0800313 pciexp1_clk = csb_clk;
Dave Liua46daea2006-11-03 19:33:44 -0600314 break;
315 case 2:
Dave Liu5245ff52007-09-18 12:36:11 +0800316 pciexp1_clk = csb_clk / 2;
Dave Liua46daea2006-11-03 19:33:44 -0600317 break;
318 case 3:
Dave Liu5245ff52007-09-18 12:36:11 +0800319 pciexp1_clk = csb_clk / 3;
Dave Liua46daea2006-11-03 19:33:44 -0600320 break;
321 default:
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500322 /* unknown SCCR_PCIEXP1CM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800323 return -9;
Dave Liua46daea2006-11-03 19:33:44 -0600324 }
Dave Liue740c462006-12-07 21:13:15 +0800325
Dave Liu5245ff52007-09-18 12:36:11 +0800326 switch ((sccr & SCCR_PCIEXP2CM) >> SCCR_PCIEXP2CM_SHIFT) {
327 case 0:
328 pciexp2_clk = 0;
329 break;
330 case 1:
331 pciexp2_clk = csb_clk;
332 break;
333 case 2:
334 pciexp2_clk = csb_clk / 2;
335 break;
336 case 3:
337 pciexp2_clk = csb_clk / 3;
338 break;
339 default:
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500340 /* unknown SCCR_PCIEXP2CM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800341 return -10;
342 }
343#endif
344
Tom Rinid9e6ef52021-05-14 21:34:27 -0400345#if defined(CONFIG_ARCH_MPC837X)
Dave Liub7896ad2008-01-17 18:23:19 +0800346 switch ((sccr & SCCR_SATA1CM) >> SCCR_SATA1CM_SHIFT) {
347 case 0:
Dave Liu5245ff52007-09-18 12:36:11 +0800348 sata_clk = 0;
349 break;
Dave Liub7896ad2008-01-17 18:23:19 +0800350 case 1:
Dave Liu5245ff52007-09-18 12:36:11 +0800351 sata_clk = csb_clk;
352 break;
Dave Liub7896ad2008-01-17 18:23:19 +0800353 case 2:
Dave Liu5245ff52007-09-18 12:36:11 +0800354 sata_clk = csb_clk / 2;
355 break;
Dave Liub7896ad2008-01-17 18:23:19 +0800356 case 3:
Dave Liu5245ff52007-09-18 12:36:11 +0800357 sata_clk = csb_clk / 3;
358 break;
359 default:
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500360 /* unknown SCCR_SATA1CM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800361 return -11;
362 }
363#endif
364
Kim Phillipsbae24792006-11-02 19:47:11 -0600365 lbiu_clk = csb_clk *
Joakim Tjernlundf2af1bb2011-01-27 16:30:54 +0100366 (1 + ((im->clk.spmr & SPMR_LBIUCM) >> SPMR_LBIUCM_SHIFT));
Becky Bruce0d4cee12010-06-17 11:37:20 -0500367 lcrr = (im->im_lbc.lcrr & LCRR_CLKDIV) >> LCRR_CLKDIV_SHIFT;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500368 switch (lcrr) {
369 case 2:
370 case 4:
371 case 8:
372 lclk_clk = lbiu_clk / lcrr;
373 break;
374 default:
375 /* unknown lcrr */
Dave Liu5245ff52007-09-18 12:36:11 +0800376 return -12;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500377 }
Dave Liue740c462006-12-07 21:13:15 +0800378
Kim Phillipsc02cf1e2008-03-28 10:18:40 -0500379 mem_clk = csb_clk *
Joakim Tjernlundf2af1bb2011-01-27 16:30:54 +0100380 (1 + ((im->clk.spmr & SPMR_DDRCM) >> SPMR_DDRCM_SHIFT));
381 corepll = (im->clk.spmr & SPMR_COREPLL) >> SPMR_COREPLL_SHIFT;
382
Mario Six84eb4312019-01-21 09:17:28 +0100383#if defined(CONFIG_ARCH_MPC8360)
Kim Phillipsc02cf1e2008-03-28 10:18:40 -0500384 mem_sec_clk = csb_clk * (1 +
Joakim Tjernlundf2af1bb2011-01-27 16:30:54 +0100385 ((im->clk.spmr & SPMR_LBIUCM) >> SPMR_LBIUCM_SHIFT));
Dave Liua46daea2006-11-03 19:33:44 -0600386#endif
Dave Liua46daea2006-11-03 19:33:44 -0600387
Eran Liberty9095d4a2005-07-28 10:08:46 -0500388 corecnf_tab_index = ((corepll & 0x1F) << 2) | ((corepll & 0x60) >> 5);
Robert P. J. Day0c911592016-05-23 06:49:21 -0400389 if (corecnf_tab_index > (ARRAY_SIZE(corecnf_tab))) {
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500390 /* corecnf_tab_index is too high, possibly wrong value */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500391 return -11;
392 }
393 switch (corecnf_tab[corecnf_tab_index].core_csb_ratio) {
394 case _byp:
395 case _x1:
396 case _1x:
397 core_clk = csb_clk;
398 break;
399 case _1_5x:
400 core_clk = (3 * csb_clk) / 2;
401 break;
402 case _2x:
403 core_clk = 2 * csb_clk;
404 break;
405 case _2_5x:
Kim Phillipsbae24792006-11-02 19:47:11 -0600406 core_clk = (5 * csb_clk) / 2;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500407 break;
408 case _3x:
409 core_clk = 3 * csb_clk;
410 break;
411 default:
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500412 /* unknown core to csb ratio */
Dave Liu5245ff52007-09-18 12:36:11 +0800413 return -13;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500414 }
Jon Loeligerebc72242005-08-01 13:20:47 -0500415
Gerlando Falauto77cf2832012-10-10 22:13:06 +0000416#if defined(CONFIG_QE)
Joakim Tjernlundf2af1bb2011-01-27 16:30:54 +0100417 qepmf = (im->clk.spmr & SPMR_CEPMF) >> SPMR_CEPMF_SHIFT;
418 qepdf = (im->clk.spmr & SPMR_CEPDF) >> SPMR_CEPDF_SHIFT;
Kim Phillipsbae24792006-11-02 19:47:11 -0600419 qe_clk = (pci_sync_in * qepmf) / (1 + qepdf);
Dave Liua46daea2006-11-03 19:33:44 -0600420 brg_clk = qe_clk / 2;
421#endif
Jon Loeligerebc72242005-08-01 13:20:47 -0500422
Simon Glasscc76e9e2012-12-13 20:48:47 +0000423 gd->arch.csb_clk = csb_clk;
Mario Six9164bdd2019-01-21 09:17:25 +0100424#if defined(CONFIG_ARCH_MPC8308) || defined(CONFIG_ARCH_MPC831X) || \
Mario Six60b11232019-01-21 09:17:29 +0100425 defined(CONFIG_ARCH_MPC834X) || defined(CONFIG_ARCH_MPC837X)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000426 gd->arch.tsec1_clk = tsec1_clk;
427 gd->arch.tsec2_clk = tsec2_clk;
428 gd->arch.usbdr_clk = usbdr_clk;
Dave Liua46daea2006-11-03 19:33:44 -0600429#endif
Mario Six0344f5e2019-01-21 09:17:27 +0100430#if defined(CONFIG_ARCH_MPC834X)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000431 gd->arch.usbmph_clk = usbmph_clk;
Scott Woodc036fc92007-04-16 14:34:19 -0500432#endif
Rini van Zettena2496172010-04-15 16:03:05 +0200433#if defined(CONFIG_FSL_ESDHC)
Simon Glass9e247d12012-12-13 20:49:05 +0000434 gd->arch.sdhc_clk = sdhc_clk;
Dave Liu5245ff52007-09-18 12:36:11 +0800435#endif
Simon Glasscc76e9e2012-12-13 20:48:47 +0000436 gd->arch.core_clk = core_clk;
Simon Glassc2baaec2012-12-13 20:48:49 +0000437 gd->arch.i2c1_clk = i2c1_clk;
Mario Sixbe07e552019-01-21 09:17:26 +0100438#if !defined(CONFIG_ARCH_MPC832X)
Simon Glassc2baaec2012-12-13 20:48:49 +0000439 gd->arch.i2c2_clk = i2c2_clk;
Dave Liue740c462006-12-07 21:13:15 +0800440#endif
Simon Glasscc76e9e2012-12-13 20:48:47 +0000441 gd->arch.enc_clk = enc_clk;
Simon Glasscc76e9e2012-12-13 20:48:47 +0000442 gd->arch.lbiu_clk = lbiu_clk;
443 gd->arch.lclk_clk = lclk_clk;
Kim Phillipsc02cf1e2008-03-28 10:18:40 -0500444 gd->mem_clk = mem_clk;
Mario Six84eb4312019-01-21 09:17:28 +0100445#if defined(CONFIG_ARCH_MPC8360)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000446 gd->arch.mem_sec_clk = mem_sec_clk;
Dave Liue740c462006-12-07 21:13:15 +0800447#endif
Gerlando Falauto77cf2832012-10-10 22:13:06 +0000448#if defined(CONFIG_QE)
Simon Glass8518b172012-12-13 20:48:50 +0000449 gd->arch.qe_clk = qe_clk;
Simon Glass34a194f2012-12-13 20:48:44 +0000450 gd->arch.brg_clk = brg_clk;
Dave Liua46daea2006-11-03 19:33:44 -0600451#endif
Mario Six9164bdd2019-01-21 09:17:25 +0100452#if defined(CONFIG_ARCH_MPC8308) || defined(CONFIG_ARCH_MPC831X) || \
Mario Six60b11232019-01-21 09:17:29 +0100453 defined(CONFIG_ARCH_MPC837X)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000454 gd->arch.pciexp1_clk = pciexp1_clk;
455 gd->arch.pciexp2_clk = pciexp2_clk;
Dave Liue0cfec82007-09-18 12:36:58 +0800456#endif
Tom Rinid9e6ef52021-05-14 21:34:27 -0400457#if defined(CONFIG_ARCH_MPC837X)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000458 gd->arch.sata_clk = sata_clk;
Dave Liu5245ff52007-09-18 12:36:11 +0800459#endif
Kim Phillipscd9fd702007-08-15 22:30:19 -0500460 gd->pci_clk = pci_sync_in;
Simon Glasscc76e9e2012-12-13 20:48:47 +0000461 gd->cpu_clk = gd->arch.core_clk;
462 gd->bus_clk = gd->arch.csb_clk;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500463 return 0;
Dave Liua46daea2006-11-03 19:33:44 -0600464
Eran Liberty9095d4a2005-07-28 10:08:46 -0500465}
466
467/********************************************
468 * get_bus_freq
469 * return system bus freq in Hz
470 *********************************************/
Kim Phillipsbae24792006-11-02 19:47:11 -0600471ulong get_bus_freq(ulong dummy)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500472{
Simon Glasscc76e9e2012-12-13 20:48:47 +0000473 return gd->arch.csb_clk;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500474}
475
York Sune12ce982011-08-26 11:32:44 -0700476/********************************************
477 * get_ddr_freq
478 * return ddr bus freq in Hz
479 *********************************************/
480ulong get_ddr_freq(ulong dummy)
481{
482 return gd->mem_clk;
483}
484
Mario Six2fc52272019-01-21 09:18:05 +0100485int get_serial_clock(void)
486{
487 return get_bus_freq(0);
488}
489
Simon Glassed38aef2020-05-10 11:40:03 -0600490static int do_clocks(struct cmd_tbl *cmdtp, int flag, int argc,
491 char *const argv[])
Eran Liberty9095d4a2005-07-28 10:08:46 -0500492{
Wolfgang Denk20591042008-10-19 02:35:49 +0200493 char buf[32];
494
Eran Liberty9095d4a2005-07-28 10:08:46 -0500495 printf("Clock configuration:\n");
Simon Glasscc76e9e2012-12-13 20:48:47 +0000496 printf(" Core: %-4s MHz\n",
497 strmhz(buf, gd->arch.core_clk));
498 printf(" Coherent System Bus: %-4s MHz\n",
499 strmhz(buf, gd->arch.csb_clk));
Gerlando Falauto77cf2832012-10-10 22:13:06 +0000500#if defined(CONFIG_QE)
Simon Glass8518b172012-12-13 20:48:50 +0000501 printf(" QE: %-4s MHz\n",
502 strmhz(buf, gd->arch.qe_clk));
Simon Glass34a194f2012-12-13 20:48:44 +0000503 printf(" BRG: %-4s MHz\n",
504 strmhz(buf, gd->arch.brg_clk));
Dave Liua46daea2006-11-03 19:33:44 -0600505#endif
Simon Glasscc76e9e2012-12-13 20:48:47 +0000506 printf(" Local Bus Controller:%-4s MHz\n",
507 strmhz(buf, gd->arch.lbiu_clk));
508 printf(" Local Bus: %-4s MHz\n",
509 strmhz(buf, gd->arch.lclk_clk));
Wolfgang Denk20591042008-10-19 02:35:49 +0200510 printf(" DDR: %-4s MHz\n", strmhz(buf, gd->mem_clk));
Mario Six84eb4312019-01-21 09:17:28 +0100511#if defined(CONFIG_ARCH_MPC8360)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000512 printf(" DDR Secondary: %-4s MHz\n",
513 strmhz(buf, gd->arch.mem_sec_clk));
Dave Liua46daea2006-11-03 19:33:44 -0600514#endif
Simon Glasscc76e9e2012-12-13 20:48:47 +0000515 printf(" SEC: %-4s MHz\n",
516 strmhz(buf, gd->arch.enc_clk));
Simon Glassc2baaec2012-12-13 20:48:49 +0000517 printf(" I2C1: %-4s MHz\n",
518 strmhz(buf, gd->arch.i2c1_clk));
Mario Sixbe07e552019-01-21 09:17:26 +0100519#if !defined(CONFIG_ARCH_MPC832X)
Simon Glassc2baaec2012-12-13 20:48:49 +0000520 printf(" I2C2: %-4s MHz\n",
521 strmhz(buf, gd->arch.i2c2_clk));
Dave Liue740c462006-12-07 21:13:15 +0800522#endif
Rini van Zettena2496172010-04-15 16:03:05 +0200523#if defined(CONFIG_FSL_ESDHC)
Simon Glass9e247d12012-12-13 20:49:05 +0000524 printf(" SDHC: %-4s MHz\n",
525 strmhz(buf, gd->arch.sdhc_clk));
Dave Liu5245ff52007-09-18 12:36:11 +0800526#endif
Mario Six9164bdd2019-01-21 09:17:25 +0100527#if defined(CONFIG_ARCH_MPC8308) || defined(CONFIG_ARCH_MPC831X) || \
Mario Six60b11232019-01-21 09:17:29 +0100528 defined(CONFIG_ARCH_MPC834X) || defined(CONFIG_ARCH_MPC837X)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000529 printf(" TSEC1: %-4s MHz\n",
530 strmhz(buf, gd->arch.tsec1_clk));
531 printf(" TSEC2: %-4s MHz\n",
532 strmhz(buf, gd->arch.tsec2_clk));
533 printf(" USB DR: %-4s MHz\n",
534 strmhz(buf, gd->arch.usbdr_clk));
Dave Liua46daea2006-11-03 19:33:44 -0600535#endif
Mario Six0344f5e2019-01-21 09:17:27 +0100536#if defined(CONFIG_ARCH_MPC834X)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000537 printf(" USB MPH: %-4s MHz\n",
538 strmhz(buf, gd->arch.usbmph_clk));
Scott Woodc036fc92007-04-16 14:34:19 -0500539#endif
Mario Six9164bdd2019-01-21 09:17:25 +0100540#if defined(CONFIG_ARCH_MPC8308) || defined(CONFIG_ARCH_MPC831X) || \
Mario Six60b11232019-01-21 09:17:29 +0100541 defined(CONFIG_ARCH_MPC837X)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000542 printf(" PCIEXP1: %-4s MHz\n",
543 strmhz(buf, gd->arch.pciexp1_clk));
544 printf(" PCIEXP2: %-4s MHz\n",
545 strmhz(buf, gd->arch.pciexp2_clk));
Dave Liue0cfec82007-09-18 12:36:58 +0800546#endif
Tom Rinid9e6ef52021-05-14 21:34:27 -0400547#if defined(CONFIG_ARCH_MPC837X)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000548 printf(" SATA: %-4s MHz\n",
549 strmhz(buf, gd->arch.sata_clk));
Dave Liu5245ff52007-09-18 12:36:11 +0800550#endif
Jon Loeligerebc72242005-08-01 13:20:47 -0500551 return 0;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500552}
Kim Phillipsd82b0772007-04-30 15:26:21 -0500553
554U_BOOT_CMD(clocks, 1, 0, do_clocks,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600555 "print clock configuration",
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200556 " clocks"
Kim Phillipsd82b0772007-04-30 15:26:21 -0500557);
Mario Six7cab1472018-08-06 10:23:36 +0200558
559#endif