wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1 | /* |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 2 | * Copyright 2004 Freescale Semiconductor. |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 3 | * (C) Copyright 2003 Motorola Inc. |
| 4 | * Xianghua Xiao, (X.Xiao@motorola.com) |
| 5 | * |
| 6 | * (C) Copyright 2000 |
| 7 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 8 | * |
| 9 | * See file CREDITS for list of people who contributed to this |
| 10 | * project. |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License as |
| 14 | * published by the Free Software Foundation; either version 2 of |
| 15 | * the License, or (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 25 | * MA 02111-1307 USA |
| 26 | */ |
| 27 | |
| 28 | #include <common.h> |
| 29 | #include <ppc_asm.tmpl> |
| 30 | #include <asm/processor.h> |
| 31 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 32 | DECLARE_GLOBAL_DATA_PTR; |
| 33 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 34 | /* --------------------------------------------------------------- */ |
| 35 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 36 | void get_sys_info (sys_info_t * sysInfo) |
| 37 | { |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 38 | volatile immap_t *immap = (immap_t *)CFG_IMMR; |
| 39 | volatile ccsr_gur_t *gur = &immap->im_gur; |
Andy Fleming | 66ed6cc | 2007-04-23 02:37:47 -0500 | [diff] [blame] | 40 | uint plat_ratio,e500_ratio,half_freqSystemBus; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 41 | |
| 42 | plat_ratio = (gur->porpllsr) & 0x0000003e; |
| 43 | plat_ratio >>= 1; |
Andy Fleming | 66ed6cc | 2007-04-23 02:37:47 -0500 | [diff] [blame] | 44 | sysInfo->freqSystemBus = plat_ratio * CONFIG_SYS_CLK_FREQ; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 45 | e500_ratio = (gur->porpllsr) & 0x003f0000; |
| 46 | e500_ratio >>= 16; |
Andy Fleming | 66ed6cc | 2007-04-23 02:37:47 -0500 | [diff] [blame] | 47 | |
| 48 | /* Divide before multiply to avoid integer |
| 49 | * overflow for processor speeds above 2GHz */ |
| 50 | half_freqSystemBus = sysInfo->freqSystemBus/2; |
| 51 | sysInfo->freqProcessor = e500_ratio*half_freqSystemBus; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Andy Fleming | 66ed6cc | 2007-04-23 02:37:47 -0500 | [diff] [blame] | 54 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 55 | int get_clocks (void) |
| 56 | { |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 57 | sys_info_t sys_info; |
Jon Loeliger | 9c4c5ae | 2005-07-23 10:37:35 -0500 | [diff] [blame] | 58 | #if defined(CONFIG_CPM2) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 59 | volatile immap_t *immap = (immap_t *) CFG_IMMR; |
| 60 | uint sccr, dfbrg; |
| 61 | |
| 62 | /* set VCO = 4 * BRG */ |
| 63 | immap->im_cpm.im_cpm_intctl.sccr &= 0xfffffffc; |
| 64 | sccr = immap->im_cpm.im_cpm_intctl.sccr; |
| 65 | dfbrg = (sccr & SCCR_DFBRG_MSK) >> SCCR_DFBRG_SHIFT; |
| 66 | #endif |
| 67 | get_sys_info (&sys_info); |
| 68 | gd->cpu_clk = sys_info.freqProcessor; |
| 69 | gd->bus_clk = sys_info.freqSystemBus; |
Jon Loeliger | 9c4c5ae | 2005-07-23 10:37:35 -0500 | [diff] [blame] | 70 | #if defined(CONFIG_CPM2) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 71 | gd->vco_out = 2*sys_info.freqSystemBus; |
| 72 | gd->cpm_clk = gd->vco_out / 2; |
| 73 | gd->scc_clk = gd->vco_out / 4; |
| 74 | gd->brg_clk = gd->vco_out / (1 << (2 * (dfbrg + 1))); |
| 75 | #endif |
| 76 | |
| 77 | if(gd->cpu_clk != 0) return (0); |
| 78 | else return (1); |
| 79 | } |
| 80 | |
| 81 | |
| 82 | /******************************************** |
| 83 | * get_bus_freq |
| 84 | * return system bus freq in Hz |
| 85 | *********************************************/ |
| 86 | ulong get_bus_freq (ulong dummy) |
| 87 | { |
| 88 | ulong val; |
| 89 | |
| 90 | sys_info_t sys_info; |
| 91 | |
| 92 | get_sys_info (&sys_info); |
| 93 | val = sys_info.freqSystemBus; |
| 94 | |
| 95 | return val; |
| 96 | } |