blob: cba57fadb996f70ad48792969312c92a5d4f234f [file] [log] [blame]
Eran Libertyf046ccd2005-07-28 10:08:46 -05001/*
2 * (C) Copyright 2000-2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
Dave Liu5f820432006-11-03 19:33:44 -06005 * Copyright (C) 2004-2006 Freescale Semiconductor, Inc.
Eran Libertyf046ccd2005-07-28 10:08:46 -05006 *
7 * See file CREDITS for list of people who contributed to this
8 * project.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 * MA 02111-1307 USA
Eran Libertyf046ccd2005-07-28 10:08:46 -050024 */
25
26#include <common.h>
27#include <mpc83xx.h>
Kim Phillips54b2d432007-04-30 15:26:21 -050028#include <command.h>
Eran Libertyf046ccd2005-07-28 10:08:46 -050029#include <asm/processor.h>
30
Wolfgang Denkd87080b2006-03-31 18:32:53 +020031DECLARE_GLOBAL_DATA_PTR;
32
Eran Libertyf046ccd2005-07-28 10:08:46 -050033/* ----------------------------------------------------------------- */
34
35typedef enum {
36 _unk,
37 _off,
38 _byp,
39 _x8,
40 _x4,
41 _x2,
42 _x1,
43 _1x,
44 _1_5x,
45 _2x,
46 _2_5x,
47 _3x
48} mult_t;
49
50typedef struct {
51 mult_t core_csb_ratio;
Kim Phillipsf7fb2e72006-11-02 19:47:11 -060052 mult_t vco_divider;
Eran Libertyf046ccd2005-07-28 10:08:46 -050053} corecnf_t;
54
55corecnf_t corecnf_tab[] = {
Kim Phillipsf7fb2e72006-11-02 19:47:11 -060056 {_byp, _byp}, /* 0x00 */
57 {_byp, _byp}, /* 0x01 */
58 {_byp, _byp}, /* 0x02 */
59 {_byp, _byp}, /* 0x03 */
60 {_byp, _byp}, /* 0x04 */
61 {_byp, _byp}, /* 0x05 */
62 {_byp, _byp}, /* 0x06 */
63 {_byp, _byp}, /* 0x07 */
64 {_1x, _x2}, /* 0x08 */
65 {_1x, _x4}, /* 0x09 */
66 {_1x, _x8}, /* 0x0A */
67 {_1x, _x8}, /* 0x0B */
68 {_1_5x, _x2}, /* 0x0C */
69 {_1_5x, _x4}, /* 0x0D */
70 {_1_5x, _x8}, /* 0x0E */
71 {_1_5x, _x8}, /* 0x0F */
72 {_2x, _x2}, /* 0x10 */
73 {_2x, _x4}, /* 0x11 */
74 {_2x, _x8}, /* 0x12 */
75 {_2x, _x8}, /* 0x13 */
76 {_2_5x, _x2}, /* 0x14 */
77 {_2_5x, _x4}, /* 0x15 */
78 {_2_5x, _x8}, /* 0x16 */
79 {_2_5x, _x8}, /* 0x17 */
80 {_3x, _x2}, /* 0x18 */
81 {_3x, _x4}, /* 0x19 */
82 {_3x, _x8}, /* 0x1A */
83 {_3x, _x8}, /* 0x1B */
Eran Libertyf046ccd2005-07-28 10:08:46 -050084};
85
86/* ----------------------------------------------------------------- */
87
88/*
89 *
90 */
Kim Phillipsf7fb2e72006-11-02 19:47:11 -060091int get_clocks(void)
Eran Libertyf046ccd2005-07-28 10:08:46 -050092{
Timur Tabid239d742006-11-03 12:00:28 -060093 volatile immap_t *im = (immap_t *) CFG_IMMR;
Eran Libertyf046ccd2005-07-28 10:08:46 -050094 u32 pci_sync_in;
Kim Phillipsf7fb2e72006-11-02 19:47:11 -060095 u8 spmf;
96 u8 clkin_div;
Eran Libertyf046ccd2005-07-28 10:08:46 -050097 u32 sccr;
98 u32 corecnf_tab_index;
Kim Phillipsf7fb2e72006-11-02 19:47:11 -060099 u8 corepll;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500100 u32 lcrr;
Jon Loeligerde1d0a62005-08-01 13:20:47 -0500101
Eran Libertyf046ccd2005-07-28 10:08:46 -0500102 u32 csb_clk;
Scott Wood7c98e512007-04-16 14:34:19 -0500103#if defined(CONFIG_MPC834X) || defined(CONFIG_MPC831X)
Eran Libertyf046ccd2005-07-28 10:08:46 -0500104 u32 tsec1_clk;
105 u32 tsec2_clk;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500106 u32 usbdr_clk;
Dave Liu5f820432006-11-03 19:33:44 -0600107#endif
Scott Wood7c98e512007-04-16 14:34:19 -0500108#ifdef CONFIG_MPC834X
109 u32 usbmph_clk;
110#endif
Dave Liu5f820432006-11-03 19:33:44 -0600111 u32 core_clk;
112 u32 i2c1_clk;
Dave Liu24c3aca2006-12-07 21:13:15 +0800113#if !defined(CONFIG_MPC832X)
Dave Liu5f820432006-11-03 19:33:44 -0600114 u32 i2c2_clk;
Dave Liu24c3aca2006-12-07 21:13:15 +0800115#endif
Eran Libertyf046ccd2005-07-28 10:08:46 -0500116 u32 enc_clk;
117 u32 lbiu_clk;
118 u32 lclk_clk;
119 u32 ddr_clk;
Dave Liu24c3aca2006-12-07 21:13:15 +0800120#if defined(CONFIG_MPC8360)
121 u32 ddr_sec_clk;
122#endif
123#if defined(CONFIG_MPC8360) || defined(CONFIG_MPC832X)
Dave Liu5f820432006-11-03 19:33:44 -0600124 u32 qepmf;
125 u32 qepdf;
Dave Liu5f820432006-11-03 19:33:44 -0600126 u32 qe_clk;
127 u32 brg_clk;
128#endif
Jon Loeligerde1d0a62005-08-01 13:20:47 -0500129
Kim Phillipsf7fb2e72006-11-02 19:47:11 -0600130 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
Eran Libertyf046ccd2005-07-28 10:08:46 -0500131 return -1;
Jon Loeligerde1d0a62005-08-01 13:20:47 -0500132
Eran Libertyf046ccd2005-07-28 10:08:46 -0500133 clkin_div = ((im->clk.spmr & SPMR_CKID) >> SPMR_CKID_SHIFT);
Jon Loeligerde1d0a62005-08-01 13:20:47 -0500134
Dave Liu5f820432006-11-03 19:33:44 -0600135 if (im->reset.rcwh & HRCWH_PCI_HOST) {
136#if defined(CONFIG_83XX_CLKIN)
137 pci_sync_in = CONFIG_83XX_CLKIN / (1 + clkin_div);
138#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 Libertyf046ccd2005-07-28 10:08:46 -0500147 }
Jon Loeligerde1d0a62005-08-01 13:20:47 -0500148
Dave Liue0803132006-12-07 21:11:58 +0800149 spmf = ((im->reset.rcwl & HRCWL_SPMF) >> HRCWL_SPMF_SHIFT);
Dave Liu5f820432006-11-03 19:33:44 -0600150 csb_clk = pci_sync_in * (1 + clkin_div) * spmf;
151
Eran Libertyf046ccd2005-07-28 10:08:46 -0500152 sccr = im->clk.sccr;
Dave Liu5f820432006-11-03 19:33:44 -0600153
Scott Wood7c98e512007-04-16 14:34:19 -0500154#if defined(CONFIG_MPC834X) || defined(CONFIG_MPC831X)
Eran Libertyf046ccd2005-07-28 10:08:46 -0500155 switch ((sccr & SCCR_TSEC1CM) >> SCCR_TSEC1CM_SHIFT) {
156 case 0:
157 tsec1_clk = 0;
158 break;
159 case 1:
160 tsec1_clk = csb_clk;
161 break;
162 case 2:
163 tsec1_clk = csb_clk / 2;
164 break;
165 case 3:
166 tsec1_clk = csb_clk / 3;
167 break;
168 default:
169 /* unkown SCCR_TSEC1CM value */
170 return -4;
171 }
Jon Loeligerde1d0a62005-08-01 13:20:47 -0500172
Scott Wood7c98e512007-04-16 14:34:19 -0500173 switch ((sccr & SCCR_USBDRCM) >> SCCR_USBDRCM_SHIFT) {
174 case 0:
175 usbdr_clk = 0;
176 break;
177 case 1:
178 usbdr_clk = csb_clk;
179 break;
180 case 2:
181 usbdr_clk = csb_clk / 2;
182 break;
183 case 3:
184 usbdr_clk = csb_clk / 3;
185 break;
186 default:
187 /* unkown SCCR_USBDRCM value */
188 return -8;
189 }
190#endif
191
192#if defined(CONFIG_MPC834X)
Eran Libertyf046ccd2005-07-28 10:08:46 -0500193 switch ((sccr & SCCR_TSEC2CM) >> SCCR_TSEC2CM_SHIFT) {
194 case 0:
195 tsec2_clk = 0;
196 break;
197 case 1:
198 tsec2_clk = csb_clk;
199 break;
200 case 2:
201 tsec2_clk = csb_clk / 2;
202 break;
203 case 3:
204 tsec2_clk = csb_clk / 3;
205 break;
206 default:
207 /* unkown SCCR_TSEC2CM value */
208 return -5;
209 }
Jon Loeligerde1d0a62005-08-01 13:20:47 -0500210
Dave Liu5f820432006-11-03 19:33:44 -0600211 i2c1_clk = tsec2_clk;
Jon Loeligerde1d0a62005-08-01 13:20:47 -0500212
Eran Libertyf046ccd2005-07-28 10:08:46 -0500213 switch ((sccr & SCCR_USBMPHCM) >> SCCR_USBMPHCM_SHIFT) {
214 case 0:
215 usbmph_clk = 0;
216 break;
217 case 1:
218 usbmph_clk = csb_clk;
219 break;
220 case 2:
221 usbmph_clk = csb_clk / 2;
222 break;
223 case 3:
224 usbmph_clk = csb_clk / 3;
225 break;
226 default:
227 /* unkown SCCR_USBMPHCM value */
228 return -7;
229 }
230
Kim Phillipsf7fb2e72006-11-02 19:47:11 -0600231 if (usbmph_clk != 0 && usbdr_clk != 0 && usbmph_clk != usbdr_clk) {
232 /* if USB MPH clock is not disabled and
233 * USB DR clock is not disabled then
234 * USB MPH & USB DR must have the same rate
235 */
Eran Libertyf046ccd2005-07-28 10:08:46 -0500236 return -9;
237 }
Scott Wood7c98e512007-04-16 14:34:19 -0500238#elif defined(CONFIG_MPC831X)
239 tsec2_clk = tsec1_clk;
240
241 if (!(sccr & SCCR_TSEC1ON))
242 tsec1_clk = 0;
243 if (!(sccr & SCCR_TSEC2ON))
244 tsec2_clk = 0;
Dave Liu5f820432006-11-03 19:33:44 -0600245#endif
Scott Wood7c98e512007-04-16 14:34:19 -0500246
247#if !defined(CONFIG_MPC834X)
Dave Liu5f820432006-11-03 19:33:44 -0600248 i2c1_clk = csb_clk;
249#endif
Dave Liu24c3aca2006-12-07 21:13:15 +0800250#if !defined(CONFIG_MPC832X)
Kim Phillipsf7fb2e72006-11-02 19:47:11 -0600251 i2c2_clk = csb_clk; /* i2c-2 clk is equal to csb clk */
Dave Liu24c3aca2006-12-07 21:13:15 +0800252#endif
Jon Loeligerde1d0a62005-08-01 13:20:47 -0500253
Dave Liu5f820432006-11-03 19:33:44 -0600254 switch ((sccr & SCCR_ENCCM) >> SCCR_ENCCM_SHIFT) {
255 case 0:
256 enc_clk = 0;
257 break;
258 case 1:
259 enc_clk = csb_clk;
260 break;
261 case 2:
262 enc_clk = csb_clk / 2;
263 break;
264 case 3:
265 enc_clk = csb_clk / 3;
266 break;
267 default:
268 /* unkown SCCR_ENCCM value */
269 return -6;
270 }
Dave Liu24c3aca2006-12-07 21:13:15 +0800271
Kim Phillipsf7fb2e72006-11-02 19:47:11 -0600272 lbiu_clk = csb_clk *
Dave Liue0803132006-12-07 21:11:58 +0800273 (1 + ((im->reset.rcwl & HRCWL_LBIUCM) >> HRCWL_LBIUCM_SHIFT));
Eran Libertyf046ccd2005-07-28 10:08:46 -0500274 lcrr = (im->lbus.lcrr & LCRR_CLKDIV) >> LCRR_CLKDIV_SHIFT;
275 switch (lcrr) {
276 case 2:
277 case 4:
278 case 8:
279 lclk_clk = lbiu_clk / lcrr;
280 break;
281 default:
282 /* unknown lcrr */
283 return -10;
284 }
Dave Liu24c3aca2006-12-07 21:13:15 +0800285
Kim Phillipsf7fb2e72006-11-02 19:47:11 -0600286 ddr_clk = csb_clk *
Dave Liue0803132006-12-07 21:11:58 +0800287 (1 + ((im->reset.rcwl & HRCWL_DDRCM) >> HRCWL_DDRCM_SHIFT));
288 corepll = (im->reset.rcwl & HRCWL_COREPLL) >> HRCWL_COREPLL_SHIFT;
Dave Liu24c3aca2006-12-07 21:13:15 +0800289#if defined(CONFIG_MPC8360)
Kim Phillipsf7fb2e72006-11-02 19:47:11 -0600290 ddr_sec_clk = csb_clk * (1 +
Dave Liue0803132006-12-07 21:11:58 +0800291 ((im->reset.rcwl & HRCWL_LBIUCM) >> HRCWL_LBIUCM_SHIFT));
Dave Liu5f820432006-11-03 19:33:44 -0600292#endif
Dave Liu5f820432006-11-03 19:33:44 -0600293
Eran Libertyf046ccd2005-07-28 10:08:46 -0500294 corecnf_tab_index = ((corepll & 0x1F) << 2) | ((corepll & 0x60) >> 5);
Kim Phillipsf7fb2e72006-11-02 19:47:11 -0600295 if (corecnf_tab_index > (sizeof(corecnf_tab) / sizeof(corecnf_t))) {
Eran Libertyf046ccd2005-07-28 10:08:46 -0500296 /* corecnf_tab_index is too high, possibly worng value */
297 return -11;
298 }
299 switch (corecnf_tab[corecnf_tab_index].core_csb_ratio) {
300 case _byp:
301 case _x1:
302 case _1x:
303 core_clk = csb_clk;
304 break;
305 case _1_5x:
306 core_clk = (3 * csb_clk) / 2;
307 break;
308 case _2x:
309 core_clk = 2 * csb_clk;
310 break;
311 case _2_5x:
Kim Phillipsf7fb2e72006-11-02 19:47:11 -0600312 core_clk = (5 * csb_clk) / 2;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500313 break;
314 case _3x:
315 core_clk = 3 * csb_clk;
316 break;
317 default:
318 /* unkown core to csb ratio */
319 return -12;
320 }
Jon Loeligerde1d0a62005-08-01 13:20:47 -0500321
Dave Liu24c3aca2006-12-07 21:13:15 +0800322#if defined(CONFIG_MPC8360) || defined(CONFIG_MPC832X)
Dave Liue0803132006-12-07 21:11:58 +0800323 qepmf = (im->reset.rcwl & HRCWL_CEPMF) >> HRCWL_CEPMF_SHIFT;
324 qepdf = (im->reset.rcwl & HRCWL_CEPDF) >> HRCWL_CEPDF_SHIFT;
Kim Phillipsf7fb2e72006-11-02 19:47:11 -0600325 qe_clk = (pci_sync_in * qepmf) / (1 + qepdf);
Dave Liu5f820432006-11-03 19:33:44 -0600326 brg_clk = qe_clk / 2;
327#endif
Jon Loeligerde1d0a62005-08-01 13:20:47 -0500328
Kim Phillipsf7fb2e72006-11-02 19:47:11 -0600329 gd->csb_clk = csb_clk;
Scott Wood7c98e512007-04-16 14:34:19 -0500330#if defined(CONFIG_MPC834X) || defined(CONFIG_MPC831X)
Kim Phillipsf7fb2e72006-11-02 19:47:11 -0600331 gd->tsec1_clk = tsec1_clk;
332 gd->tsec2_clk = tsec2_clk;
Kim Phillipsf7fb2e72006-11-02 19:47:11 -0600333 gd->usbdr_clk = usbdr_clk;
Dave Liu5f820432006-11-03 19:33:44 -0600334#endif
Scott Wood7c98e512007-04-16 14:34:19 -0500335#if defined(CONFIG_MPC834X)
336 gd->usbmph_clk = usbmph_clk;
337#endif
Kim Phillipsf7fb2e72006-11-02 19:47:11 -0600338 gd->core_clk = core_clk;
339 gd->i2c1_clk = i2c1_clk;
Dave Liu24c3aca2006-12-07 21:13:15 +0800340#if !defined(CONFIG_MPC832X)
Kim Phillipsf7fb2e72006-11-02 19:47:11 -0600341 gd->i2c2_clk = i2c2_clk;
Dave Liu24c3aca2006-12-07 21:13:15 +0800342#endif
Kim Phillipsf7fb2e72006-11-02 19:47:11 -0600343 gd->enc_clk = enc_clk;
344 gd->lbiu_clk = lbiu_clk;
345 gd->lclk_clk = lclk_clk;
346 gd->ddr_clk = ddr_clk;
Dave Liu24c3aca2006-12-07 21:13:15 +0800347#if defined(CONFIG_MPC8360)
Dave Liu5f820432006-11-03 19:33:44 -0600348 gd->ddr_sec_clk = ddr_sec_clk;
Dave Liu24c3aca2006-12-07 21:13:15 +0800349#endif
350#if defined(CONFIG_MPC8360) || defined(CONFIG_MPC832X)
Kim Phillipsf7fb2e72006-11-02 19:47:11 -0600351 gd->qe_clk = qe_clk;
352 gd->brg_clk = brg_clk;
Dave Liu5f820432006-11-03 19:33:44 -0600353#endif
Kim Phillips8f9e0e92007-08-15 22:30:19 -0500354 gd->pci_clk = pci_sync_in;
Kim Phillipsf7fb2e72006-11-02 19:47:11 -0600355 gd->cpu_clk = gd->core_clk;
356 gd->bus_clk = gd->csb_clk;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500357 return 0;
Dave Liu5f820432006-11-03 19:33:44 -0600358
Eran Libertyf046ccd2005-07-28 10:08:46 -0500359}
360
361/********************************************
362 * get_bus_freq
363 * return system bus freq in Hz
364 *********************************************/
Kim Phillipsf7fb2e72006-11-02 19:47:11 -0600365ulong get_bus_freq(ulong dummy)
Eran Libertyf046ccd2005-07-28 10:08:46 -0500366{
Eran Libertyf046ccd2005-07-28 10:08:46 -0500367 return gd->csb_clk;
368}
369
Kim Phillips54b2d432007-04-30 15:26:21 -0500370int do_clocks (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
Eran Libertyf046ccd2005-07-28 10:08:46 -0500371{
Eran Libertyf046ccd2005-07-28 10:08:46 -0500372 printf("Clock configuration:\n");
Kim Phillipsf7fb2e72006-11-02 19:47:11 -0600373 printf(" Core: %4d MHz\n", gd->core_clk / 1000000);
Kim Phillips54b2d432007-04-30 15:26:21 -0500374 printf(" Coherent System Bus: %4d MHz\n", gd->csb_clk / 1000000);
Dave Liu24c3aca2006-12-07 21:13:15 +0800375#if defined(CONFIG_MPC8360) || defined(CONFIG_MPC832X)
Kim Phillipsf7fb2e72006-11-02 19:47:11 -0600376 printf(" QE: %4d MHz\n", gd->qe_clk / 1000000);
Dave Liu24c3aca2006-12-07 21:13:15 +0800377 printf(" BRG: %4d MHz\n", gd->brg_clk / 1000000);
Dave Liu5f820432006-11-03 19:33:44 -0600378#endif
Kim Phillipsf7fb2e72006-11-02 19:47:11 -0600379 printf(" Local Bus Controller:%4d MHz\n", gd->lbiu_clk / 1000000);
380 printf(" Local Bus: %4d MHz\n", gd->lclk_clk / 1000000);
381 printf(" DDR: %4d MHz\n", gd->ddr_clk / 1000000);
Dave Liu24c3aca2006-12-07 21:13:15 +0800382#if defined(CONFIG_MPC8360)
Kim Phillipsf7fb2e72006-11-02 19:47:11 -0600383 printf(" DDR Secondary: %4d MHz\n", gd->ddr_sec_clk / 1000000);
Dave Liu5f820432006-11-03 19:33:44 -0600384#endif
Kim Phillipsf7fb2e72006-11-02 19:47:11 -0600385 printf(" SEC: %4d MHz\n", gd->enc_clk / 1000000);
386 printf(" I2C1: %4d MHz\n", gd->i2c1_clk / 1000000);
Dave Liu24c3aca2006-12-07 21:13:15 +0800387#if !defined(CONFIG_MPC832X)
Kim Phillipsf7fb2e72006-11-02 19:47:11 -0600388 printf(" I2C2: %4d MHz\n", gd->i2c2_clk / 1000000);
Dave Liu24c3aca2006-12-07 21:13:15 +0800389#endif
Scott Wood7c98e512007-04-16 14:34:19 -0500390#if defined(CONFIG_MPC834X) || defined(CONFIG_MPC831X)
Kim Phillipsf7fb2e72006-11-02 19:47:11 -0600391 printf(" TSEC1: %4d MHz\n", gd->tsec1_clk / 1000000);
392 printf(" TSEC2: %4d MHz\n", gd->tsec2_clk / 1000000);
Kim Phillipsf7fb2e72006-11-02 19:47:11 -0600393 printf(" USB DR: %4d MHz\n", gd->usbdr_clk / 1000000);
Dave Liu5f820432006-11-03 19:33:44 -0600394#endif
Scott Wood7c98e512007-04-16 14:34:19 -0500395#if defined(CONFIG_MPC834X)
396 printf(" USB MPH: %4d MHz\n", gd->usbmph_clk / 1000000);
397#endif
Jon Loeligerde1d0a62005-08-01 13:20:47 -0500398 return 0;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500399}
Kim Phillips54b2d432007-04-30 15:26:21 -0500400
401U_BOOT_CMD(clocks, 1, 0, do_clocks,
402 "clocks - print clock configuration\n",
403 " clocks\n"
404);