blob: 58e197f12082583346b4b2d59609a7467a39248b [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
Mario Six9164bdd2019-01-21 09:17:25 +0100107#if defined(CONFIG_ARCH_MPC8315)
Dave Liue0cfec82007-09-18 12:36:58 +0800108 u32 tdm_clk;
109#endif
Rini van Zettena2496172010-04-15 16:03:05 +0200110#if defined(CONFIG_FSL_ESDHC)
Dave Liu5245ff52007-09-18 12:36:11 +0800111 u32 sdhc_clk;
112#endif
Mario Sixb2e701c2019-01-21 09:17:24 +0100113#if !defined(CONFIG_ARCH_MPC8309)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500114 u32 enc_clk;
Gerlando Falautofe201cb2012-10-10 22:13:08 +0000115#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500116 u32 lbiu_clk;
117 u32 lclk_clk;
Kim Phillipsc02cf1e2008-03-28 10:18:40 -0500118 u32 mem_clk;
Mario Six84eb4312019-01-21 09:17:28 +0100119#if defined(CONFIG_ARCH_MPC8360)
Kim Phillipsc02cf1e2008-03-28 10:18:40 -0500120 u32 mem_sec_clk;
Dave Liue740c462006-12-07 21:13:15 +0800121#endif
Gerlando Falauto77cf2832012-10-10 22:13:06 +0000122#if defined(CONFIG_QE)
Dave Liua46daea2006-11-03 19:33:44 -0600123 u32 qepmf;
124 u32 qepdf;
Dave Liua46daea2006-11-03 19:33:44 -0600125 u32 qe_clk;
126 u32 brg_clk;
127#endif
Mario Six9164bdd2019-01-21 09:17:25 +0100128#if defined(CONFIG_ARCH_MPC8308) || defined(CONFIG_ARCH_MPC831X) || \
Mario Six60b11232019-01-21 09:17:29 +0100129 defined(CONFIG_ARCH_MPC837X)
Dave Liu5245ff52007-09-18 12:36:11 +0800130 u32 pciexp1_clk;
131 u32 pciexp2_clk;
Dave Liue0cfec82007-09-18 12:36:58 +0800132#endif
Mario Six60b11232019-01-21 09:17:29 +0100133#if defined(CONFIG_ARCH_MPC837X) || defined(CONFIG_ARCH_MPC8315)
Dave Liu5245ff52007-09-18 12:36:11 +0800134 u32 sata_clk;
135#endif
Jon Loeligerebc72242005-08-01 13:20:47 -0500136
Kim Phillipsbae24792006-11-02 19:47:11 -0600137 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500138 return -1;
Jon Loeligerebc72242005-08-01 13:20:47 -0500139
Dave Liua46daea2006-11-03 19:33:44 -0600140 clkin_div = ((im->clk.spmr & SPMR_CKID) >> SPMR_CKID_SHIFT);
Marian Balakowicz513b4a12005-10-11 19:09:42 +0200141
Dave Liua46daea2006-11-03 19:33:44 -0600142 if (im->reset.rcwh & HRCWH_PCI_HOST) {
Mario Sixd10f3182019-01-21 09:17:53 +0100143#if defined(CONFIG_SYS_CLK_FREQ)
144 pci_sync_in = CONFIG_SYS_CLK_FREQ / (1 + clkin_div);
Dave Liua46daea2006-11-03 19:33:44 -0600145#else
146 pci_sync_in = 0xDEADBEEF;
147#endif
148 } else {
149#if defined(CONFIG_83XX_PCICLK)
150 pci_sync_in = CONFIG_83XX_PCICLK;
151#else
152 pci_sync_in = 0xDEADBEEF;
153#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500154 }
Marian Balakowicz513b4a12005-10-11 19:09:42 +0200155
Joakim Tjernlundf2af1bb2011-01-27 16:30:54 +0100156 spmf = (im->clk.spmr & SPMR_SPMF) >> SPMR_SPMF_SHIFT;
Dave Liua46daea2006-11-03 19:33:44 -0600157 csb_clk = pci_sync_in * (1 + clkin_div) * spmf;
Jon Loeligerebc72242005-08-01 13:20:47 -0500158
Eran Liberty9095d4a2005-07-28 10:08:46 -0500159 sccr = im->clk.sccr;
Dave Liua46daea2006-11-03 19:33:44 -0600160
Mario Six9164bdd2019-01-21 09:17:25 +0100161#if defined(CONFIG_ARCH_MPC8308) || defined(CONFIG_ARCH_MPC831X) || \
Mario Six60b11232019-01-21 09:17:29 +0100162 defined(CONFIG_ARCH_MPC834X) || defined(CONFIG_ARCH_MPC837X)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500163 switch ((sccr & SCCR_TSEC1CM) >> SCCR_TSEC1CM_SHIFT) {
164 case 0:
165 tsec1_clk = 0;
166 break;
167 case 1:
168 tsec1_clk = csb_clk;
169 break;
170 case 2:
171 tsec1_clk = csb_clk / 2;
172 break;
173 case 3:
174 tsec1_clk = csb_clk / 3;
175 break;
176 default:
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500177 /* unknown SCCR_TSEC1CM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800178 return -2;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500179 }
Gerlando Falauto74735552012-10-10 22:13:07 +0000180#endif
Jon Loeligerebc72242005-08-01 13:20:47 -0500181
Mario Six9164bdd2019-01-21 09:17:25 +0100182#if defined(CONFIG_ARCH_MPC830X) || defined(CONFIG_ARCH_MPC831X) || \
Mario Six60b11232019-01-21 09:17:29 +0100183 defined(CONFIG_ARCH_MPC834X) || defined(CONFIG_ARCH_MPC837X)
Scott Woodc036fc92007-04-16 14:34:19 -0500184 switch ((sccr & SCCR_USBDRCM) >> SCCR_USBDRCM_SHIFT) {
185 case 0:
186 usbdr_clk = 0;
187 break;
188 case 1:
189 usbdr_clk = csb_clk;
190 break;
191 case 2:
192 usbdr_clk = csb_clk / 2;
193 break;
194 case 3:
195 usbdr_clk = csb_clk / 3;
196 break;
197 default:
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500198 /* unknown SCCR_USBDRCM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800199 return -3;
Scott Woodc036fc92007-04-16 14:34:19 -0500200 }
201#endif
202
Mario Six9164bdd2019-01-21 09:17:25 +0100203#if defined(CONFIG_ARCH_MPC8308) || defined(CONFIG_ARCH_MPC8315) || \
Mario Six60b11232019-01-21 09:17:29 +0100204 defined(CONFIG_ARCH_MPC834X) || defined(CONFIG_ARCH_MPC837X)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500205 switch ((sccr & SCCR_TSEC2CM) >> SCCR_TSEC2CM_SHIFT) {
206 case 0:
207 tsec2_clk = 0;
208 break;
209 case 1:
210 tsec2_clk = csb_clk;
211 break;
212 case 2:
213 tsec2_clk = csb_clk / 2;
214 break;
215 case 3:
216 tsec2_clk = csb_clk / 3;
217 break;
218 default:
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500219 /* unknown SCCR_TSEC2CM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800220 return -4;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500221 }
Mario Six9164bdd2019-01-21 09:17:25 +0100222#elif defined(CONFIG_ARCH_MPC8313)
Dave Liu5245ff52007-09-18 12:36:11 +0800223 tsec2_clk = tsec1_clk;
Jon Loeligerebc72242005-08-01 13:20:47 -0500224
Dave Liu5245ff52007-09-18 12:36:11 +0800225 if (!(sccr & SCCR_TSEC1ON))
226 tsec1_clk = 0;
227 if (!(sccr & SCCR_TSEC2ON))
228 tsec2_clk = 0;
229#endif
Jon Loeligerebc72242005-08-01 13:20:47 -0500230
Mario Six0344f5e2019-01-21 09:17:27 +0100231#if defined(CONFIG_ARCH_MPC834X)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500232 switch ((sccr & SCCR_USBMPHCM) >> SCCR_USBMPHCM_SHIFT) {
233 case 0:
234 usbmph_clk = 0;
235 break;
236 case 1:
237 usbmph_clk = csb_clk;
238 break;
239 case 2:
240 usbmph_clk = csb_clk / 2;
241 break;
242 case 3:
243 usbmph_clk = csb_clk / 3;
244 break;
245 default:
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500246 /* unknown SCCR_USBMPHCM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800247 return -5;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500248 }
249
Kim Phillipsbae24792006-11-02 19:47:11 -0600250 if (usbmph_clk != 0 && usbdr_clk != 0 && usbmph_clk != usbdr_clk) {
251 /* if USB MPH clock is not disabled and
252 * USB DR clock is not disabled then
253 * USB MPH & USB DR must have the same rate
254 */
Dave Liu5245ff52007-09-18 12:36:11 +0800255 return -6;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500256 }
Dave Liu5245ff52007-09-18 12:36:11 +0800257#endif
Mario Sixb2e701c2019-01-21 09:17:24 +0100258#if !defined(CONFIG_ARCH_MPC8309)
Dave Liu5245ff52007-09-18 12:36:11 +0800259 switch ((sccr & SCCR_ENCCM) >> SCCR_ENCCM_SHIFT) {
260 case 0:
261 enc_clk = 0;
262 break;
263 case 1:
264 enc_clk = csb_clk;
265 break;
266 case 2:
267 enc_clk = csb_clk / 2;
268 break;
269 case 3:
270 enc_clk = csb_clk / 3;
271 break;
272 default:
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500273 /* unknown SCCR_ENCCM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800274 return -7;
275 }
Gerlando Falautofe201cb2012-10-10 22:13:08 +0000276#endif
Scott Woodc036fc92007-04-16 14:34:19 -0500277
Rini van Zettena2496172010-04-15 16:03:05 +0200278#if defined(CONFIG_FSL_ESDHC)
Dave Liu5245ff52007-09-18 12:36:11 +0800279 switch ((sccr & SCCR_SDHCCM) >> SCCR_SDHCCM_SHIFT) {
280 case 0:
281 sdhc_clk = 0;
282 break;
283 case 1:
284 sdhc_clk = csb_clk;
285 break;
286 case 2:
287 sdhc_clk = csb_clk / 2;
288 break;
289 case 3:
290 sdhc_clk = csb_clk / 3;
291 break;
292 default:
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500293 /* unknown SCCR_SDHCCM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800294 return -8;
295 }
Dave Liua46daea2006-11-03 19:33:44 -0600296#endif
Mario Six9164bdd2019-01-21 09:17:25 +0100297#if defined(CONFIG_ARCH_MPC8315)
Dave Liue0cfec82007-09-18 12:36:58 +0800298 switch ((sccr & SCCR_TDMCM) >> SCCR_TDMCM_SHIFT) {
299 case 0:
300 tdm_clk = 0;
301 break;
302 case 1:
303 tdm_clk = csb_clk;
304 break;
305 case 2:
306 tdm_clk = csb_clk / 2;
307 break;
308 case 3:
309 tdm_clk = csb_clk / 3;
310 break;
311 default:
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500312 /* unknown SCCR_TDMCM value */
Dave Liue0cfec82007-09-18 12:36:58 +0800313 return -8;
314 }
315#endif
Scott Woodc036fc92007-04-16 14:34:19 -0500316
Mario Six0344f5e2019-01-21 09:17:27 +0100317#if defined(CONFIG_ARCH_MPC834X)
Dave Liu5245ff52007-09-18 12:36:11 +0800318 i2c1_clk = tsec2_clk;
Mario Six84eb4312019-01-21 09:17:28 +0100319#elif defined(CONFIG_ARCH_MPC8360)
Dave Liua46daea2006-11-03 19:33:44 -0600320 i2c1_clk = csb_clk;
Mario Sixbe07e552019-01-21 09:17:26 +0100321#elif defined(CONFIG_ARCH_MPC832X)
Dave Liu5245ff52007-09-18 12:36:11 +0800322 i2c1_clk = enc_clk;
Mario Six9164bdd2019-01-21 09:17:25 +0100323#elif defined(CONFIG_ARCH_MPC8308) || defined(CONFIG_ARCH_MPC831X)
Dave Liu5245ff52007-09-18 12:36:11 +0800324 i2c1_clk = enc_clk;
Rini van Zettena2496172010-04-15 16:03:05 +0200325#elif defined(CONFIG_FSL_ESDHC)
Dave Liu5245ff52007-09-18 12:36:11 +0800326 i2c1_clk = sdhc_clk;
Mario Six60b11232019-01-21 09:17:29 +0100327#elif defined(CONFIG_ARCH_MPC837X)
Andre Schwarza76cc612011-04-14 14:57:40 +0200328 i2c1_clk = enc_clk;
Mario Sixb2e701c2019-01-21 09:17:24 +0100329#elif defined(CONFIG_ARCH_MPC8309)
Gerlando Falautofe201cb2012-10-10 22:13:08 +0000330 i2c1_clk = csb_clk;
Dave Liua46daea2006-11-03 19:33:44 -0600331#endif
Mario Sixbe07e552019-01-21 09:17:26 +0100332#if !defined(CONFIG_ARCH_MPC832X)
Dave Liu5245ff52007-09-18 12:36:11 +0800333 i2c2_clk = csb_clk; /* i2c-2 clk is equal to csb clk */
Dave Liue740c462006-12-07 21:13:15 +0800334#endif
Jon Loeligerebc72242005-08-01 13:20:47 -0500335
Mario Six9164bdd2019-01-21 09:17:25 +0100336#if defined(CONFIG_ARCH_MPC8308) || defined(CONFIG_ARCH_MPC831X) || \
Mario Six60b11232019-01-21 09:17:29 +0100337 defined(CONFIG_ARCH_MPC837X)
Dave Liu5245ff52007-09-18 12:36:11 +0800338 switch ((sccr & SCCR_PCIEXP1CM) >> SCCR_PCIEXP1CM_SHIFT) {
Dave Liua46daea2006-11-03 19:33:44 -0600339 case 0:
Dave Liu5245ff52007-09-18 12:36:11 +0800340 pciexp1_clk = 0;
Dave Liua46daea2006-11-03 19:33:44 -0600341 break;
342 case 1:
Dave Liu5245ff52007-09-18 12:36:11 +0800343 pciexp1_clk = csb_clk;
Dave Liua46daea2006-11-03 19:33:44 -0600344 break;
345 case 2:
Dave Liu5245ff52007-09-18 12:36:11 +0800346 pciexp1_clk = csb_clk / 2;
Dave Liua46daea2006-11-03 19:33:44 -0600347 break;
348 case 3:
Dave Liu5245ff52007-09-18 12:36:11 +0800349 pciexp1_clk = csb_clk / 3;
Dave Liua46daea2006-11-03 19:33:44 -0600350 break;
351 default:
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500352 /* unknown SCCR_PCIEXP1CM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800353 return -9;
Dave Liua46daea2006-11-03 19:33:44 -0600354 }
Dave Liue740c462006-12-07 21:13:15 +0800355
Dave Liu5245ff52007-09-18 12:36:11 +0800356 switch ((sccr & SCCR_PCIEXP2CM) >> SCCR_PCIEXP2CM_SHIFT) {
357 case 0:
358 pciexp2_clk = 0;
359 break;
360 case 1:
361 pciexp2_clk = csb_clk;
362 break;
363 case 2:
364 pciexp2_clk = csb_clk / 2;
365 break;
366 case 3:
367 pciexp2_clk = csb_clk / 3;
368 break;
369 default:
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500370 /* unknown SCCR_PCIEXP2CM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800371 return -10;
372 }
373#endif
374
Mario Six60b11232019-01-21 09:17:29 +0100375#if defined(CONFIG_ARCH_MPC837X) || defined(CONFIG_ARCH_MPC8315)
Dave Liub7896ad2008-01-17 18:23:19 +0800376 switch ((sccr & SCCR_SATA1CM) >> SCCR_SATA1CM_SHIFT) {
377 case 0:
Dave Liu5245ff52007-09-18 12:36:11 +0800378 sata_clk = 0;
379 break;
Dave Liub7896ad2008-01-17 18:23:19 +0800380 case 1:
Dave Liu5245ff52007-09-18 12:36:11 +0800381 sata_clk = csb_clk;
382 break;
Dave Liub7896ad2008-01-17 18:23:19 +0800383 case 2:
Dave Liu5245ff52007-09-18 12:36:11 +0800384 sata_clk = csb_clk / 2;
385 break;
Dave Liub7896ad2008-01-17 18:23:19 +0800386 case 3:
Dave Liu5245ff52007-09-18 12:36:11 +0800387 sata_clk = csb_clk / 3;
388 break;
389 default:
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500390 /* unknown SCCR_SATA1CM value */
Dave Liu5245ff52007-09-18 12:36:11 +0800391 return -11;
392 }
393#endif
394
Kim Phillipsbae24792006-11-02 19:47:11 -0600395 lbiu_clk = csb_clk *
Joakim Tjernlundf2af1bb2011-01-27 16:30:54 +0100396 (1 + ((im->clk.spmr & SPMR_LBIUCM) >> SPMR_LBIUCM_SHIFT));
Becky Bruce0d4cee12010-06-17 11:37:20 -0500397 lcrr = (im->im_lbc.lcrr & LCRR_CLKDIV) >> LCRR_CLKDIV_SHIFT;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500398 switch (lcrr) {
399 case 2:
400 case 4:
401 case 8:
402 lclk_clk = lbiu_clk / lcrr;
403 break;
404 default:
405 /* unknown lcrr */
Dave Liu5245ff52007-09-18 12:36:11 +0800406 return -12;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500407 }
Dave Liue740c462006-12-07 21:13:15 +0800408
Kim Phillipsc02cf1e2008-03-28 10:18:40 -0500409 mem_clk = csb_clk *
Joakim Tjernlundf2af1bb2011-01-27 16:30:54 +0100410 (1 + ((im->clk.spmr & SPMR_DDRCM) >> SPMR_DDRCM_SHIFT));
411 corepll = (im->clk.spmr & SPMR_COREPLL) >> SPMR_COREPLL_SHIFT;
412
Mario Six84eb4312019-01-21 09:17:28 +0100413#if defined(CONFIG_ARCH_MPC8360)
Kim Phillipsc02cf1e2008-03-28 10:18:40 -0500414 mem_sec_clk = csb_clk * (1 +
Joakim Tjernlundf2af1bb2011-01-27 16:30:54 +0100415 ((im->clk.spmr & SPMR_LBIUCM) >> SPMR_LBIUCM_SHIFT));
Dave Liua46daea2006-11-03 19:33:44 -0600416#endif
Dave Liua46daea2006-11-03 19:33:44 -0600417
Eran Liberty9095d4a2005-07-28 10:08:46 -0500418 corecnf_tab_index = ((corepll & 0x1F) << 2) | ((corepll & 0x60) >> 5);
Robert P. J. Day0c911592016-05-23 06:49:21 -0400419 if (corecnf_tab_index > (ARRAY_SIZE(corecnf_tab))) {
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500420 /* corecnf_tab_index is too high, possibly wrong value */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500421 return -11;
422 }
423 switch (corecnf_tab[corecnf_tab_index].core_csb_ratio) {
424 case _byp:
425 case _x1:
426 case _1x:
427 core_clk = csb_clk;
428 break;
429 case _1_5x:
430 core_clk = (3 * csb_clk) / 2;
431 break;
432 case _2x:
433 core_clk = 2 * csb_clk;
434 break;
435 case _2_5x:
Kim Phillipsbae24792006-11-02 19:47:11 -0600436 core_clk = (5 * csb_clk) / 2;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500437 break;
438 case _3x:
439 core_clk = 3 * csb_clk;
440 break;
441 default:
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500442 /* unknown core to csb ratio */
Dave Liu5245ff52007-09-18 12:36:11 +0800443 return -13;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500444 }
Jon Loeligerebc72242005-08-01 13:20:47 -0500445
Gerlando Falauto77cf2832012-10-10 22:13:06 +0000446#if defined(CONFIG_QE)
Joakim Tjernlundf2af1bb2011-01-27 16:30:54 +0100447 qepmf = (im->clk.spmr & SPMR_CEPMF) >> SPMR_CEPMF_SHIFT;
448 qepdf = (im->clk.spmr & SPMR_CEPDF) >> SPMR_CEPDF_SHIFT;
Kim Phillipsbae24792006-11-02 19:47:11 -0600449 qe_clk = (pci_sync_in * qepmf) / (1 + qepdf);
Dave Liua46daea2006-11-03 19:33:44 -0600450 brg_clk = qe_clk / 2;
451#endif
Jon Loeligerebc72242005-08-01 13:20:47 -0500452
Simon Glasscc76e9e2012-12-13 20:48:47 +0000453 gd->arch.csb_clk = csb_clk;
Mario Six9164bdd2019-01-21 09:17:25 +0100454#if defined(CONFIG_ARCH_MPC8308) || defined(CONFIG_ARCH_MPC831X) || \
Mario Six60b11232019-01-21 09:17:29 +0100455 defined(CONFIG_ARCH_MPC834X) || defined(CONFIG_ARCH_MPC837X)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000456 gd->arch.tsec1_clk = tsec1_clk;
457 gd->arch.tsec2_clk = tsec2_clk;
458 gd->arch.usbdr_clk = usbdr_clk;
Mario Sixb2e701c2019-01-21 09:17:24 +0100459#elif defined(CONFIG_ARCH_MPC8309)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000460 gd->arch.usbdr_clk = usbdr_clk;
Dave Liua46daea2006-11-03 19:33:44 -0600461#endif
Mario Six0344f5e2019-01-21 09:17:27 +0100462#if defined(CONFIG_ARCH_MPC834X)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000463 gd->arch.usbmph_clk = usbmph_clk;
Scott Woodc036fc92007-04-16 14:34:19 -0500464#endif
Mario Six9164bdd2019-01-21 09:17:25 +0100465#if defined(CONFIG_ARCH_MPC8315)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000466 gd->arch.tdm_clk = tdm_clk;
Dave Liue0cfec82007-09-18 12:36:58 +0800467#endif
Rini van Zettena2496172010-04-15 16:03:05 +0200468#if defined(CONFIG_FSL_ESDHC)
Simon Glass9e247d12012-12-13 20:49:05 +0000469 gd->arch.sdhc_clk = sdhc_clk;
Dave Liu5245ff52007-09-18 12:36:11 +0800470#endif
Simon Glasscc76e9e2012-12-13 20:48:47 +0000471 gd->arch.core_clk = core_clk;
Simon Glassc2baaec2012-12-13 20:48:49 +0000472 gd->arch.i2c1_clk = i2c1_clk;
Mario Sixbe07e552019-01-21 09:17:26 +0100473#if !defined(CONFIG_ARCH_MPC832X)
Simon Glassc2baaec2012-12-13 20:48:49 +0000474 gd->arch.i2c2_clk = i2c2_clk;
Dave Liue740c462006-12-07 21:13:15 +0800475#endif
Mario Sixb2e701c2019-01-21 09:17:24 +0100476#if !defined(CONFIG_ARCH_MPC8309)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000477 gd->arch.enc_clk = enc_clk;
Gerlando Falautofe201cb2012-10-10 22:13:08 +0000478#endif
Simon Glasscc76e9e2012-12-13 20:48:47 +0000479 gd->arch.lbiu_clk = lbiu_clk;
480 gd->arch.lclk_clk = lclk_clk;
Kim Phillipsc02cf1e2008-03-28 10:18:40 -0500481 gd->mem_clk = mem_clk;
Mario Six84eb4312019-01-21 09:17:28 +0100482#if defined(CONFIG_ARCH_MPC8360)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000483 gd->arch.mem_sec_clk = mem_sec_clk;
Dave Liue740c462006-12-07 21:13:15 +0800484#endif
Gerlando Falauto77cf2832012-10-10 22:13:06 +0000485#if defined(CONFIG_QE)
Simon Glass8518b172012-12-13 20:48:50 +0000486 gd->arch.qe_clk = qe_clk;
Simon Glass34a194f2012-12-13 20:48:44 +0000487 gd->arch.brg_clk = brg_clk;
Dave Liua46daea2006-11-03 19:33:44 -0600488#endif
Mario Six9164bdd2019-01-21 09:17:25 +0100489#if defined(CONFIG_ARCH_MPC8308) || defined(CONFIG_ARCH_MPC831X) || \
Mario Six60b11232019-01-21 09:17:29 +0100490 defined(CONFIG_ARCH_MPC837X)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000491 gd->arch.pciexp1_clk = pciexp1_clk;
492 gd->arch.pciexp2_clk = pciexp2_clk;
Dave Liue0cfec82007-09-18 12:36:58 +0800493#endif
Mario Six60b11232019-01-21 09:17:29 +0100494#if defined(CONFIG_ARCH_MPC837X) || defined(CONFIG_ARCH_MPC8315)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000495 gd->arch.sata_clk = sata_clk;
Dave Liu5245ff52007-09-18 12:36:11 +0800496#endif
Kim Phillipscd9fd702007-08-15 22:30:19 -0500497 gd->pci_clk = pci_sync_in;
Simon Glasscc76e9e2012-12-13 20:48:47 +0000498 gd->cpu_clk = gd->arch.core_clk;
499 gd->bus_clk = gd->arch.csb_clk;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500500 return 0;
Dave Liua46daea2006-11-03 19:33:44 -0600501
Eran Liberty9095d4a2005-07-28 10:08:46 -0500502}
503
504/********************************************
505 * get_bus_freq
506 * return system bus freq in Hz
507 *********************************************/
Kim Phillipsbae24792006-11-02 19:47:11 -0600508ulong get_bus_freq(ulong dummy)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500509{
Simon Glasscc76e9e2012-12-13 20:48:47 +0000510 return gd->arch.csb_clk;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500511}
512
York Sune12ce982011-08-26 11:32:44 -0700513/********************************************
514 * get_ddr_freq
515 * return ddr bus freq in Hz
516 *********************************************/
517ulong get_ddr_freq(ulong dummy)
518{
519 return gd->mem_clk;
520}
521
Mario Six2fc52272019-01-21 09:18:05 +0100522int get_serial_clock(void)
523{
524 return get_bus_freq(0);
525}
526
Simon Glassed38aef2020-05-10 11:40:03 -0600527static int do_clocks(struct cmd_tbl *cmdtp, int flag, int argc,
528 char *const argv[])
Eran Liberty9095d4a2005-07-28 10:08:46 -0500529{
Wolfgang Denk20591042008-10-19 02:35:49 +0200530 char buf[32];
531
Eran Liberty9095d4a2005-07-28 10:08:46 -0500532 printf("Clock configuration:\n");
Simon Glasscc76e9e2012-12-13 20:48:47 +0000533 printf(" Core: %-4s MHz\n",
534 strmhz(buf, gd->arch.core_clk));
535 printf(" Coherent System Bus: %-4s MHz\n",
536 strmhz(buf, gd->arch.csb_clk));
Gerlando Falauto77cf2832012-10-10 22:13:06 +0000537#if defined(CONFIG_QE)
Simon Glass8518b172012-12-13 20:48:50 +0000538 printf(" QE: %-4s MHz\n",
539 strmhz(buf, gd->arch.qe_clk));
Simon Glass34a194f2012-12-13 20:48:44 +0000540 printf(" BRG: %-4s MHz\n",
541 strmhz(buf, gd->arch.brg_clk));
Dave Liua46daea2006-11-03 19:33:44 -0600542#endif
Simon Glasscc76e9e2012-12-13 20:48:47 +0000543 printf(" Local Bus Controller:%-4s MHz\n",
544 strmhz(buf, gd->arch.lbiu_clk));
545 printf(" Local Bus: %-4s MHz\n",
546 strmhz(buf, gd->arch.lclk_clk));
Wolfgang Denk20591042008-10-19 02:35:49 +0200547 printf(" DDR: %-4s MHz\n", strmhz(buf, gd->mem_clk));
Mario Six84eb4312019-01-21 09:17:28 +0100548#if defined(CONFIG_ARCH_MPC8360)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000549 printf(" DDR Secondary: %-4s MHz\n",
550 strmhz(buf, gd->arch.mem_sec_clk));
Dave Liua46daea2006-11-03 19:33:44 -0600551#endif
Mario Sixb2e701c2019-01-21 09:17:24 +0100552#if !defined(CONFIG_ARCH_MPC8309)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000553 printf(" SEC: %-4s MHz\n",
554 strmhz(buf, gd->arch.enc_clk));
Gerlando Falautofe201cb2012-10-10 22:13:08 +0000555#endif
Simon Glassc2baaec2012-12-13 20:48:49 +0000556 printf(" I2C1: %-4s MHz\n",
557 strmhz(buf, gd->arch.i2c1_clk));
Mario Sixbe07e552019-01-21 09:17:26 +0100558#if !defined(CONFIG_ARCH_MPC832X)
Simon Glassc2baaec2012-12-13 20:48:49 +0000559 printf(" I2C2: %-4s MHz\n",
560 strmhz(buf, gd->arch.i2c2_clk));
Dave Liue740c462006-12-07 21:13:15 +0800561#endif
Mario Six9164bdd2019-01-21 09:17:25 +0100562#if defined(CONFIG_ARCH_MPC8315)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000563 printf(" TDM: %-4s MHz\n",
564 strmhz(buf, gd->arch.tdm_clk));
Dave Liue0cfec82007-09-18 12:36:58 +0800565#endif
Rini van Zettena2496172010-04-15 16:03:05 +0200566#if defined(CONFIG_FSL_ESDHC)
Simon Glass9e247d12012-12-13 20:49:05 +0000567 printf(" SDHC: %-4s MHz\n",
568 strmhz(buf, gd->arch.sdhc_clk));
Dave Liu5245ff52007-09-18 12:36:11 +0800569#endif
Mario Six9164bdd2019-01-21 09:17:25 +0100570#if defined(CONFIG_ARCH_MPC8308) || defined(CONFIG_ARCH_MPC831X) || \
Mario Six60b11232019-01-21 09:17:29 +0100571 defined(CONFIG_ARCH_MPC834X) || defined(CONFIG_ARCH_MPC837X)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000572 printf(" TSEC1: %-4s MHz\n",
573 strmhz(buf, gd->arch.tsec1_clk));
574 printf(" TSEC2: %-4s MHz\n",
575 strmhz(buf, gd->arch.tsec2_clk));
576 printf(" USB DR: %-4s MHz\n",
577 strmhz(buf, gd->arch.usbdr_clk));
Mario Sixb2e701c2019-01-21 09:17:24 +0100578#elif defined(CONFIG_ARCH_MPC8309)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000579 printf(" USB DR: %-4s MHz\n",
580 strmhz(buf, gd->arch.usbdr_clk));
Dave Liua46daea2006-11-03 19:33:44 -0600581#endif
Mario Six0344f5e2019-01-21 09:17:27 +0100582#if defined(CONFIG_ARCH_MPC834X)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000583 printf(" USB MPH: %-4s MHz\n",
584 strmhz(buf, gd->arch.usbmph_clk));
Scott Woodc036fc92007-04-16 14:34:19 -0500585#endif
Mario Six9164bdd2019-01-21 09:17:25 +0100586#if defined(CONFIG_ARCH_MPC8308) || defined(CONFIG_ARCH_MPC831X) || \
Mario Six60b11232019-01-21 09:17:29 +0100587 defined(CONFIG_ARCH_MPC837X)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000588 printf(" PCIEXP1: %-4s MHz\n",
589 strmhz(buf, gd->arch.pciexp1_clk));
590 printf(" PCIEXP2: %-4s MHz\n",
591 strmhz(buf, gd->arch.pciexp2_clk));
Dave Liue0cfec82007-09-18 12:36:58 +0800592#endif
Mario Six60b11232019-01-21 09:17:29 +0100593#if defined(CONFIG_ARCH_MPC837X) || defined(CONFIG_ARCH_MPC8315)
Simon Glasscc76e9e2012-12-13 20:48:47 +0000594 printf(" SATA: %-4s MHz\n",
595 strmhz(buf, gd->arch.sata_clk));
Dave Liu5245ff52007-09-18 12:36:11 +0800596#endif
Jon Loeligerebc72242005-08-01 13:20:47 -0500597 return 0;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500598}
Kim Phillipsd82b0772007-04-30 15:26:21 -0500599
600U_BOOT_CMD(clocks, 1, 0, do_clocks,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600601 "print clock configuration",
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200602 " clocks"
Kim Phillipsd82b0772007-04-30 15:26:21 -0500603);
Mario Six7cab1472018-08-06 10:23:36 +0200604
605#endif