2 * (C) Copyright 2000-2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * Copyright 2004 Freescale Semiconductor, Inc.
7 * See file CREDITS for list of people who contributed to this
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.
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.
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,
27 * 20050101: Eran Liberty (liberty@freescale.com)
28 * Initial file creating (porting from 85XX & 8260)
33 #include <asm/processor.h>
35 DECLARE_GLOBAL_DATA_PTR;
37 /* ----------------------------------------------------------------- */
55 mult_t core_csb_ratio;
59 corecnf_t corecnf_tab[] = {
60 { _byp, _byp}, /* 0x00 */
61 { _byp, _byp}, /* 0x01 */
62 { _byp, _byp}, /* 0x02 */
63 { _byp, _byp}, /* 0x03 */
64 { _byp, _byp}, /* 0x04 */
65 { _byp, _byp}, /* 0x05 */
66 { _byp, _byp}, /* 0x06 */
67 { _byp, _byp}, /* 0x07 */
68 { _1x, _x2}, /* 0x08 */
69 { _1x, _x4}, /* 0x09 */
70 { _1x, _x8}, /* 0x0A */
71 { _1x, _x8}, /* 0x0B */
72 {_1_5x, _x2}, /* 0x0C */
73 {_1_5x, _x4}, /* 0x0D */
74 {_1_5x, _x8}, /* 0x0E */
75 {_1_5x, _x8}, /* 0x0F */
76 { _2x, _x2}, /* 0x10 */
77 { _2x, _x4}, /* 0x11 */
78 { _2x, _x8}, /* 0x12 */
79 { _2x, _x8}, /* 0x13 */
80 {_2_5x, _x2}, /* 0x14 */
81 {_2_5x, _x4}, /* 0x15 */
82 {_2_5x, _x8}, /* 0x16 */
83 {_2_5x, _x8}, /* 0x17 */
84 { _3x, _x2}, /* 0x18 */
85 { _3x, _x4}, /* 0x19 */
86 { _3x, _x8}, /* 0x1A */
87 { _3x, _x8}, /* 0x1B */
90 /* ----------------------------------------------------------------- */
97 volatile immap_t *im = (immap_t *)CFG_IMMRBAR;
102 u32 corecnf_tab_index;
118 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im)
121 #ifndef CFG_HRCW_HIGH
122 # error "CFG_HRCW_HIGH must be defined in board config file"
123 #endif /* CFG_HCWD_HIGH */
125 #if (CFG_HRCW_HIGH & HRCWH_PCI_HOST)
127 # ifndef CONFIG_83XX_CLKIN
128 # error "In PCI Host Mode, CONFIG_83XX_CLKIN must be defined in board config file"
129 # endif /* CONFIG_83XX_CLKIN */
130 # ifdef CONFIG_83XX_PCICLK
131 # warning "In PCI Host Mode, CONFIG_83XX_PCICLK in board config file is igonred"
132 # endif /* CONFIG_83XX_PCICLK */
135 if (!(im->reset.rcwh & RCWH_PCIHOST)) {
136 /* though RCWH_PCIHOST is defined in CFG_HRCW_HIGH
137 * the im->reset.rcwhr PCI Host Mode is disabled
138 * FIXME: findout if there is a way to issue some warning */
141 if (im->clk.spmr & SPMR_CKID) {
142 /* PCI Clock is half CONFIG_83XX_CLKIN */
143 pci_sync_in = CONFIG_83XX_CLKIN / 2;
146 pci_sync_in = CONFIG_83XX_CLKIN;
149 #else /* (CFG_HRCW_HIGH & HRCWH_PCI_HOST) */
151 # ifdef CONFIG_83XX_CLKIN
152 # warning "In PCI Agent Mode, CONFIG_83XX_CLKIN in board config file is igonred"
153 # endif /* CONFIG_83XX_CLKIN */
154 # ifndef CONFIG_83XX_PCICLK
155 # error "In PCI Agent Mode, CONFIG_83XX_PCICLK must be defined in board config file"
156 # endif /* CONFIG_83XX_PCICLK */
159 if (im->reset.rcwh & RCWH_PCIHOST) {
160 /* though RCWH_PCIHOST is not defined in CFG_HRCW_HIGH
161 * the im->reset.rcwhr PCI Host Mode is enabled */
164 pci_sync_in = CONFIG_83XX_PCICLK;
166 #endif /* (CFG_HRCW_HIGH | RCWH_PCIHOST) */
168 /* we have up to date pci_sync_in */
169 spmf = ((im->reset.rcwl & RCWL_SPMF) >> RCWL_SPMF_SHIFT);
170 clkin_div = ((im->clk.spmr & SPMR_CKID) >> SPMR_CKID_SHIFT);
172 if ((im->reset.rcwl & RCWL_LBIUCM) || (im->reset.rcwl & RCWL_DDRCM)) {
173 csb_clk = (pci_sync_in * spmf * (1 + clkin_div)) / 2;
176 csb_clk = pci_sync_in * spmf * (1 + clkin_div);
180 switch ((sccr & SCCR_TSEC1CM) >> SCCR_TSEC1CM_SHIFT) {
188 tsec1_clk = csb_clk / 2;
191 tsec1_clk = csb_clk / 3;
194 /* unkown SCCR_TSEC1CM value */
198 switch ((sccr & SCCR_TSEC2CM) >> SCCR_TSEC2CM_SHIFT) {
206 tsec2_clk = csb_clk / 2;
209 tsec2_clk = csb_clk / 3;
212 /* unkown SCCR_TSEC2CM value */
217 switch ((sccr & SCCR_ENCCM) >> SCCR_ENCCM_SHIFT) {
225 enc_clk = csb_clk / 2;
228 enc_clk = csb_clk / 3;
231 /* unkown SCCR_ENCCM value */
235 switch ((sccr & SCCR_USBMPHCM) >> SCCR_USBMPHCM_SHIFT) {
240 usbmph_clk = csb_clk;
243 usbmph_clk = csb_clk / 2;
246 usbmph_clk = csb_clk / 3;
249 /* unkown SCCR_USBMPHCM value */
253 switch ((sccr & SCCR_USBDRCM) >> SCCR_USBDRCM_SHIFT) {
261 usbdr_clk = csb_clk / 2;
264 usbdr_clk = csb_clk / 3;
267 /* unkown SCCR_USBDRCM value */
273 && usbmph_clk != usbdr_clk ) {
274 /* if USB MPH clock is not disabled and USB DR clock is not disabled than USB MPH & USB DR must have the same rate */
278 lbiu_clk = csb_clk * (1 + ((im->reset.rcwl & RCWL_LBIUCM) >> RCWL_LBIUCM_SHIFT));
279 lcrr = (im->lbus.lcrr & LCRR_CLKDIV) >> LCRR_CLKDIV_SHIFT;
284 lclk_clk = lbiu_clk / lcrr;
291 ddr_clk = csb_clk * (1 + ((im->reset.rcwl & RCWL_DDRCM) >> RCWL_DDRCM_SHIFT));
293 corepll = (im->reset.rcwl & RCWL_COREPLL) >> RCWL_COREPLL_SHIFT;
294 corecnf_tab_index = ((corepll & 0x1F) << 2) | ((corepll & 0x60) >> 5);
295 if (corecnf_tab_index > (sizeof(corecnf_tab)/sizeof(corecnf_t)) ) {
296 /* corecnf_tab_index is too high, possibly worng value */
299 switch (corecnf_tab[corecnf_tab_index].core_csb_ratio) {
306 core_clk = (3 * csb_clk) / 2;
309 core_clk = 2 * csb_clk;
312 core_clk = ( 5 * csb_clk) / 2;
315 core_clk = 3 * csb_clk;
318 /* unkown core to csb ratio */
322 gd->csb_clk = csb_clk ;
323 gd->tsec1_clk = tsec1_clk ;
324 gd->tsec2_clk = tsec2_clk ;
325 gd->core_clk = core_clk ;
326 gd->usbmph_clk = usbmph_clk;
327 gd->usbdr_clk = usbdr_clk ;
328 gd->i2c_clk = i2c_clk ;
329 gd->enc_clk = enc_clk ;
330 gd->lbiu_clk = lbiu_clk ;
331 gd->lclk_clk = lclk_clk ;
332 gd->ddr_clk = ddr_clk ;
333 gd->pci_clk = pci_sync_in;
335 gd->cpu_clk = gd->core_clk;
336 gd->bus_clk = gd->lbiu_clk;
340 /********************************************
342 * return system bus freq in Hz
343 *********************************************/
344 ulong get_bus_freq (ulong dummy)
349 int print_clock_conf (void)
351 printf("Clock configuration:\n");
352 printf(" Coherent System Bus: %4d MHz\n",gd->csb_clk/1000000);
353 printf(" Core: %4d MHz\n",gd->core_clk/1000000);
354 debug(" Local Bus Controller:%4d MHz\n",gd->lbiu_clk/1000000);
355 printf(" Local Bus: %4d MHz\n",gd->lclk_clk/1000000);
356 debug(" DDR: %4d MHz\n",gd->ddr_clk/1000000);
357 debug(" I2C: %4d MHz\n",gd->i2c_clk/1000000);
358 debug(" TSEC1: %4d MHz\n",gd->tsec1_clk/1000000);
359 debug(" TSEC2: %4d MHz\n",gd->tsec2_clk/1000000);
360 debug(" USB MPH: %4d MHz\n",gd->usbmph_clk/1000000);
361 debug(" USB DR: %4d MHz\n",gd->usbdr_clk/1000000);