Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2004 Freescale Semiconductor. |
Jon Loeliger | 8827a73 | 2006-05-31 13:55:35 -0500 | [diff] [blame] | 3 | * Jeff Brown |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 4 | * Srikanth Srinivasan (srikanth.srinivasan@freescale.com) |
| 5 | * |
| 6 | * (C) Copyright 2000-2002 |
| 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 <mpc86xx.h> |
| 30 | #include <asm/processor.h> |
| 31 | |
Wolfgang Denk | d112a2c | 2007-09-15 20:48:41 +0200 | [diff] [blame] | 32 | DECLARE_GLOBAL_DATA_PTR; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 33 | |
Jon Loeliger | a129544 | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 34 | void get_sys_info(sys_info_t *sysInfo) |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 35 | { |
Jon Loeliger | a129544 | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 36 | volatile immap_t *immap = (immap_t *) CFG_IMMR; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 37 | volatile ccsr_gur_t *gur = &immap->im_gur; |
| 38 | uint plat_ratio, e600_ratio; |
| 39 | |
Jon Loeliger | 8827a73 | 2006-05-31 13:55:35 -0500 | [diff] [blame] | 40 | plat_ratio = (gur->porpllsr) & 0x0000003e; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 41 | plat_ratio >>= 1; |
Jon Loeliger | 465b9d8 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 42 | |
Jon Loeliger | a129544 | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 43 | switch (plat_ratio) { |
Jon Loeliger | 8827a73 | 2006-05-31 13:55:35 -0500 | [diff] [blame] | 44 | case 0x0: |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 45 | sysInfo->freqSystemBus = 16 * CONFIG_SYS_CLK_FREQ; |
| 46 | break; |
| 47 | case 0x02: |
| 48 | case 0x03: |
| 49 | case 0x04: |
| 50 | case 0x05: |
| 51 | case 0x06: |
| 52 | case 0x08: |
| 53 | case 0x09: |
| 54 | case 0x0a: |
| 55 | case 0x0c: |
Jon Loeliger | 8827a73 | 2006-05-31 13:55:35 -0500 | [diff] [blame] | 56 | case 0x10: |
| 57 | sysInfo->freqSystemBus = plat_ratio * CONFIG_SYS_CLK_FREQ; |
| 58 | break; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 59 | default: |
Jon Loeliger | a129544 | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 60 | sysInfo->freqSystemBus = 0; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 61 | break; |
| 62 | } |
| 63 | |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 64 | e600_ratio = (gur->porpllsr) & 0x003f0000; |
| 65 | e600_ratio >>= 16; |
Jon Loeliger | 465b9d8 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 66 | |
| 67 | switch (e600_ratio) { |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 68 | case 0x10: |
Jon Loeliger | 465b9d8 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 69 | sysInfo->freqProcessor = 2 * sysInfo->freqSystemBus; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 70 | break; |
Jon Loeliger | 8827a73 | 2006-05-31 13:55:35 -0500 | [diff] [blame] | 71 | case 0x19: |
Jon Loeliger | a129544 | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 72 | sysInfo->freqProcessor = 5 * sysInfo->freqSystemBus / 2; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 73 | break; |
| 74 | case 0x20: |
Jon Loeliger | 465b9d8 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 75 | sysInfo->freqProcessor = 3 * sysInfo->freqSystemBus; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 76 | break; |
Jon Loeliger | 8827a73 | 2006-05-31 13:55:35 -0500 | [diff] [blame] | 77 | case 0x39: |
Jon Loeliger | a129544 | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 78 | sysInfo->freqProcessor = 7 * sysInfo->freqSystemBus / 2; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 79 | break; |
| 80 | case 0x28: |
Jon Loeliger | 465b9d8 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 81 | sysInfo->freqProcessor = 4 * sysInfo->freqSystemBus; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 82 | break; |
| 83 | case 0x1d: |
Jon Loeliger | a129544 | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 84 | sysInfo->freqProcessor = 9 * sysInfo->freqSystemBus / 2; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 85 | break; |
Jon Loeliger | 8827a73 | 2006-05-31 13:55:35 -0500 | [diff] [blame] | 86 | default: |
Jon Loeliger | 465b9d8 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 87 | sysInfo->freqProcessor = e600_ratio + sysInfo->freqSystemBus; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 88 | break; |
| 89 | } |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 93 | /* |
| 94 | * Measure CPU clock speed (core clock GCLK1, GCLK2) |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 95 | * (Approx. GCLK frequency in Hz) |
| 96 | */ |
| 97 | |
Jon Loeliger | 465b9d8 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 98 | int get_clocks(void) |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 99 | { |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 100 | sys_info_t sys_info; |
| 101 | |
Jon Loeliger | 465b9d8 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 102 | get_sys_info(&sys_info); |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 103 | gd->cpu_clk = sys_info.freqProcessor; |
| 104 | gd->bus_clk = sys_info.freqSystemBus; |
Jon Loeliger | 465b9d8 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 105 | |
| 106 | if (gd->cpu_clk != 0) |
| 107 | return 0; |
| 108 | else |
| 109 | return 1; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 110 | } |
| 111 | |
Jon Loeliger | 465b9d8 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 112 | |
| 113 | /* |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 114 | * get_bus_freq |
Jon Loeliger | 465b9d8 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 115 | * Return system bus freq in Hz |
| 116 | */ |
Jon Loeliger | 8827a73 | 2006-05-31 13:55:35 -0500 | [diff] [blame] | 117 | |
Jon Loeliger | 465b9d8 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 118 | ulong get_bus_freq(ulong dummy) |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 119 | { |
| 120 | ulong val; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 121 | sys_info_t sys_info; |
| 122 | |
Jon Loeliger | 465b9d8 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 123 | get_sys_info(&sys_info); |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 124 | val = sys_info.freqSystemBus; |
| 125 | |
| 126 | return val; |
| 127 | } |