blob: bf30616548e93812947f4a8c09d4c9c335bd621d [file] [log] [blame]
Eran Liberty9095d4a2005-07-28 10:08:46 -05001/*
2 * (C) Copyright 2000-2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
Dave Liua46daea2006-11-03 19:33:44 -06005 * Copyright (C) 2004-2006 Freescale Semiconductor, Inc.
Eran Liberty9095d4a2005-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 Liberty9095d4a2005-07-28 10:08:46 -050024 */
25
26#include <common.h>
27#include <mpc83xx.h>
Kim Phillipsd82b0772007-04-30 15:26:21 -050028#include <command.h>
Eran Liberty9095d4a2005-07-28 10:08:46 -050029#include <asm/processor.h>
30
Wolfgang Denk6405a152006-03-31 18:32:53 +020031DECLARE_GLOBAL_DATA_PTR;
32
Eran Liberty9095d4a2005-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 Phillipsbae24792006-11-02 19:47:11 -060052 mult_t vco_divider;
Eran Liberty9095d4a2005-07-28 10:08:46 -050053} corecnf_t;
54
55corecnf_t corecnf_tab[] = {
Kim Phillipsbae24792006-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 Liberty9095d4a2005-07-28 10:08:46 -050084};
85
86/* ----------------------------------------------------------------- */
87
88/*
89 *
90 */
Kim Phillipsbae24792006-11-02 19:47:11 -060091int get_clocks(void)
Eran Liberty9095d4a2005-07-28 10:08:46 -050092{
Timur Tabi386a2802006-11-03 12:00:28 -060093 volatile immap_t *im = (immap_t *) CFG_IMMR;
Eran Liberty9095d4a2005-07-28 10:08:46 -050094 u32 pci_sync_in;
Kim Phillipsbae24792006-11-02 19:47:11 -060095 u8 spmf;
96 u8 clkin_div;
Eran Liberty9095d4a2005-07-28 10:08:46 -050097 u32 sccr;
98 u32 corecnf_tab_index;
Kim Phillipsbae24792006-11-02 19:47:11 -060099 u8 corepll;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500100 u32 lcrr;
Jon Loeligerebc72242005-08-01 13:20:47 -0500101
Eran Liberty9095d4a2005-07-28 10:08:46 -0500102 u32 csb_clk;
Scott Woodc036fc92007-04-16 14:34:19 -0500103#if defined(CONFIG_MPC834X) || defined(CONFIG_MPC831X)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500104 u32 tsec1_clk;
105 u32 tsec2_clk;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500106 u32 usbdr_clk;
Dave Liua46daea2006-11-03 19:33:44 -0600107#endif
Scott Woodc036fc92007-04-16 14:34:19 -0500108#ifdef CONFIG_MPC834X
109 u32 usbmph_clk;
110#endif
Dave Liua46daea2006-11-03 19:33:44 -0600111 u32 core_clk;
112 u32 i2c1_clk;
Dave Liue740c462006-12-07 21:13:15 +0800113#if !defined(CONFIG_MPC832X)
Dave Liua46daea2006-11-03 19:33:44 -0600114 u32 i2c2_clk;
Dave Liue740c462006-12-07 21:13:15 +0800115#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500116 u32 enc_clk;
117 u32 lbiu_clk;
118 u32 lclk_clk;
119 u32 ddr_clk;
Dave Liue740c462006-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 Liua46daea2006-11-03 19:33:44 -0600124 u32 qepmf;
125 u32 qepdf;
Dave Liua46daea2006-11-03 19:33:44 -0600126 u32 qe_clk;
127 u32 brg_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) {
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 Liberty9095d4a2005-07-28 10:08:46 -0500147 }
Marian Balakowicz513b4a12005-10-11 19:09:42 +0200148
Dave Liu0b6bc772006-12-07 21:11:58 +0800149 spmf = ((im->reset.rcwl & HRCWL_SPMF) >> HRCWL_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
Scott Woodc036fc92007-04-16 14:34:19 -0500154#if defined(CONFIG_MPC834X) || defined(CONFIG_MPC831X)
Eran Liberty9095d4a2005-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 Loeligerebc72242005-08-01 13:20:47 -0500172
Scott Woodc036fc92007-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 Liberty9095d4a2005-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 Loeligerebc72242005-08-01 13:20:47 -0500210
Dave Liua46daea2006-11-03 19:33:44 -0600211 i2c1_clk = tsec2_clk;
Jon Loeligerebc72242005-08-01 13:20:47 -0500212
Eran Liberty9095d4a2005-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 Phillipsbae24792006-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 Liberty9095d4a2005-07-28 10:08:46 -0500236 return -9;
237 }
Scott Woodc036fc92007-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 Liua46daea2006-11-03 19:33:44 -0600245#endif
Scott Woodc036fc92007-04-16 14:34:19 -0500246
247#if !defined(CONFIG_MPC834X)
Dave Liua46daea2006-11-03 19:33:44 -0600248 i2c1_clk = csb_clk;
249#endif
Dave Liue740c462006-12-07 21:13:15 +0800250#if !defined(CONFIG_MPC832X)
Kim Phillipsbae24792006-11-02 19:47:11 -0600251 i2c2_clk = csb_clk; /* i2c-2 clk is equal to csb clk */
Dave Liue740c462006-12-07 21:13:15 +0800252#endif
Jon Loeligerebc72242005-08-01 13:20:47 -0500253
Dave Liua46daea2006-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 Liue740c462006-12-07 21:13:15 +0800271
Kim Phillipsbae24792006-11-02 19:47:11 -0600272 lbiu_clk = csb_clk *
Dave Liu0b6bc772006-12-07 21:11:58 +0800273 (1 + ((im->reset.rcwl & HRCWL_LBIUCM) >> HRCWL_LBIUCM_SHIFT));
Eran Liberty9095d4a2005-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 Liue740c462006-12-07 21:13:15 +0800285
Kim Phillipsbae24792006-11-02 19:47:11 -0600286 ddr_clk = csb_clk *
Dave Liu0b6bc772006-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 Liue740c462006-12-07 21:13:15 +0800289#if defined(CONFIG_MPC8360)
Kim Phillipsbae24792006-11-02 19:47:11 -0600290 ddr_sec_clk = csb_clk * (1 +
Dave Liu0b6bc772006-12-07 21:11:58 +0800291 ((im->reset.rcwl & HRCWL_LBIUCM) >> HRCWL_LBIUCM_SHIFT));
Dave Liua46daea2006-11-03 19:33:44 -0600292#endif
Dave Liua46daea2006-11-03 19:33:44 -0600293
Eran Liberty9095d4a2005-07-28 10:08:46 -0500294 corecnf_tab_index = ((corepll & 0x1F) << 2) | ((corepll & 0x60) >> 5);
Kim Phillipsbae24792006-11-02 19:47:11 -0600295 if (corecnf_tab_index > (sizeof(corecnf_tab) / sizeof(corecnf_t))) {
Eran Liberty9095d4a2005-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 Phillipsbae24792006-11-02 19:47:11 -0600312 core_clk = (5 * csb_clk) / 2;
Eran Liberty9095d4a2005-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 Loeligerebc72242005-08-01 13:20:47 -0500321
Dave Liue740c462006-12-07 21:13:15 +0800322#if defined(CONFIG_MPC8360) || defined(CONFIG_MPC832X)
Dave Liu0b6bc772006-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 Phillipsbae24792006-11-02 19:47:11 -0600325 qe_clk = (pci_sync_in * qepmf) / (1 + qepdf);
Dave Liua46daea2006-11-03 19:33:44 -0600326 brg_clk = qe_clk / 2;
327#endif
Jon Loeligerebc72242005-08-01 13:20:47 -0500328
Kim Phillipsbae24792006-11-02 19:47:11 -0600329 gd->csb_clk = csb_clk;
Scott Woodc036fc92007-04-16 14:34:19 -0500330#if defined(CONFIG_MPC834X) || defined(CONFIG_MPC831X)
Kim Phillipsbae24792006-11-02 19:47:11 -0600331 gd->tsec1_clk = tsec1_clk;
332 gd->tsec2_clk = tsec2_clk;
Kim Phillipsbae24792006-11-02 19:47:11 -0600333 gd->usbdr_clk = usbdr_clk;
Dave Liua46daea2006-11-03 19:33:44 -0600334#endif
Scott Woodc036fc92007-04-16 14:34:19 -0500335#if defined(CONFIG_MPC834X)
336 gd->usbmph_clk = usbmph_clk;
337#endif
Kim Phillipsbae24792006-11-02 19:47:11 -0600338 gd->core_clk = core_clk;
339 gd->i2c1_clk = i2c1_clk;
Dave Liue740c462006-12-07 21:13:15 +0800340#if !defined(CONFIG_MPC832X)
Kim Phillipsbae24792006-11-02 19:47:11 -0600341 gd->i2c2_clk = i2c2_clk;
Dave Liue740c462006-12-07 21:13:15 +0800342#endif
Kim Phillipsbae24792006-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 Liue740c462006-12-07 21:13:15 +0800347#if defined(CONFIG_MPC8360)
Dave Liua46daea2006-11-03 19:33:44 -0600348 gd->ddr_sec_clk = ddr_sec_clk;
Dave Liue740c462006-12-07 21:13:15 +0800349#endif
350#if defined(CONFIG_MPC8360) || defined(CONFIG_MPC832X)
Kim Phillipsbae24792006-11-02 19:47:11 -0600351 gd->qe_clk = qe_clk;
352 gd->brg_clk = brg_clk;
Dave Liua46daea2006-11-03 19:33:44 -0600353#endif
Kim Phillipsbae24792006-11-02 19:47:11 -0600354 gd->cpu_clk = gd->core_clk;
355 gd->bus_clk = gd->csb_clk;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500356 return 0;
Dave Liua46daea2006-11-03 19:33:44 -0600357
Eran Liberty9095d4a2005-07-28 10:08:46 -0500358}
359
360/********************************************
361 * get_bus_freq
362 * return system bus freq in Hz
363 *********************************************/
Kim Phillipsbae24792006-11-02 19:47:11 -0600364ulong get_bus_freq(ulong dummy)
Eran Liberty9095d4a2005-07-28 10:08:46 -0500365{
Eran Liberty9095d4a2005-07-28 10:08:46 -0500366 return gd->csb_clk;
367}
368
Kim Phillipsd82b0772007-04-30 15:26:21 -0500369int do_clocks (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
Eran Liberty9095d4a2005-07-28 10:08:46 -0500370{
Eran Liberty9095d4a2005-07-28 10:08:46 -0500371 printf("Clock configuration:\n");
Kim Phillipsbae24792006-11-02 19:47:11 -0600372 printf(" Core: %4d MHz\n", gd->core_clk / 1000000);
Kim Phillipsd82b0772007-04-30 15:26:21 -0500373 printf(" Coherent System Bus: %4d MHz\n", gd->csb_clk / 1000000);
Dave Liue740c462006-12-07 21:13:15 +0800374#if defined(CONFIG_MPC8360) || defined(CONFIG_MPC832X)
Kim Phillipsbae24792006-11-02 19:47:11 -0600375 printf(" QE: %4d MHz\n", gd->qe_clk / 1000000);
Dave Liue740c462006-12-07 21:13:15 +0800376 printf(" BRG: %4d MHz\n", gd->brg_clk / 1000000);
Dave Liua46daea2006-11-03 19:33:44 -0600377#endif
Kim Phillipsbae24792006-11-02 19:47:11 -0600378 printf(" Local Bus Controller:%4d MHz\n", gd->lbiu_clk / 1000000);
379 printf(" Local Bus: %4d MHz\n", gd->lclk_clk / 1000000);
380 printf(" DDR: %4d MHz\n", gd->ddr_clk / 1000000);
Dave Liue740c462006-12-07 21:13:15 +0800381#if defined(CONFIG_MPC8360)
Kim Phillipsbae24792006-11-02 19:47:11 -0600382 printf(" DDR Secondary: %4d MHz\n", gd->ddr_sec_clk / 1000000);
Dave Liua46daea2006-11-03 19:33:44 -0600383#endif
Kim Phillipsbae24792006-11-02 19:47:11 -0600384 printf(" SEC: %4d MHz\n", gd->enc_clk / 1000000);
385 printf(" I2C1: %4d MHz\n", gd->i2c1_clk / 1000000);
Dave Liue740c462006-12-07 21:13:15 +0800386#if !defined(CONFIG_MPC832X)
Kim Phillipsbae24792006-11-02 19:47:11 -0600387 printf(" I2C2: %4d MHz\n", gd->i2c2_clk / 1000000);
Dave Liue740c462006-12-07 21:13:15 +0800388#endif
Scott Woodc036fc92007-04-16 14:34:19 -0500389#if defined(CONFIG_MPC834X) || defined(CONFIG_MPC831X)
Kim Phillipsbae24792006-11-02 19:47:11 -0600390 printf(" TSEC1: %4d MHz\n", gd->tsec1_clk / 1000000);
391 printf(" TSEC2: %4d MHz\n", gd->tsec2_clk / 1000000);
Kim Phillipsbae24792006-11-02 19:47:11 -0600392 printf(" USB DR: %4d MHz\n", gd->usbdr_clk / 1000000);
Dave Liua46daea2006-11-03 19:33:44 -0600393#endif
Scott Woodc036fc92007-04-16 14:34:19 -0500394#if defined(CONFIG_MPC834X)
395 printf(" USB MPH: %4d MHz\n", gd->usbmph_clk / 1000000);
396#endif
Jon Loeligerebc72242005-08-01 13:20:47 -0500397 return 0;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500398}
Kim Phillipsd82b0772007-04-30 15:26:21 -0500399
400U_BOOT_CMD(clocks, 1, 0, do_clocks,
401 "clocks - print clock configuration\n",
402 " clocks\n"
403);