Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2004 Freescale Semiconductor. |
| 3 | * Jeff Brown (jeffrey@freescale.com) |
| 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 | |
| 32 | unsigned long get_board_sys_clk(ulong dummy); |
| 33 | unsigned long get_sysclk_from_px_regs(void); |
| 34 | |
| 35 | |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame^] | 36 | void get_sys_info (sys_info_t *sysInfo) |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 37 | { |
| 38 | volatile immap_t *immap = (immap_t *)CFG_IMMR; |
| 39 | volatile ccsr_gur_t *gur = &immap->im_gur; |
| 40 | uint plat_ratio, e600_ratio; |
| 41 | |
| 42 | plat_ratio = (gur->porpllsr) & 0x0000003e; |
| 43 | plat_ratio >>= 1; |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame^] | 44 | |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 45 | switch(plat_ratio) { |
| 46 | case 0x0: |
| 47 | sysInfo->freqSystemBus = 16 * CONFIG_SYS_CLK_FREQ; |
| 48 | break; |
| 49 | case 0x02: |
| 50 | case 0x03: |
| 51 | case 0x04: |
| 52 | case 0x05: |
| 53 | case 0x06: |
| 54 | case 0x08: |
| 55 | case 0x09: |
| 56 | case 0x0a: |
| 57 | case 0x0c: |
| 58 | case 0x10: |
| 59 | sysInfo->freqSystemBus = plat_ratio * CONFIG_SYS_CLK_FREQ; |
| 60 | break; |
| 61 | default: |
| 62 | sysInfo->freqSystemBus = 0; |
| 63 | break; |
| 64 | } |
| 65 | |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame^] | 66 | #if 0 |
| 67 | printf("assigned system bus freq = %d for plat ratio 0x%08lx\n", |
| 68 | sysInfo->freqSystemBus, plat_ratio); |
| 69 | #endif |
| 70 | |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 71 | e600_ratio = (gur->porpllsr) & 0x003f0000; |
| 72 | e600_ratio >>= 16; |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame^] | 73 | |
| 74 | switch (e600_ratio) { |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 75 | case 0x10: |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame^] | 76 | sysInfo->freqProcessor = 2 * sysInfo->freqSystemBus; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 77 | break; |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame^] | 78 | case 0x19: |
| 79 | sysInfo->freqProcessor = 5 * sysInfo->freqSystemBus/2; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 80 | break; |
| 81 | case 0x20: |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame^] | 82 | sysInfo->freqProcessor = 3 * sysInfo->freqSystemBus; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 83 | break; |
| 84 | case 0x39: |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame^] | 85 | sysInfo->freqProcessor = 7 * sysInfo->freqSystemBus/2; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 86 | break; |
| 87 | case 0x28: |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame^] | 88 | sysInfo->freqProcessor = 4 * sysInfo->freqSystemBus; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 89 | break; |
| 90 | case 0x1d: |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame^] | 91 | sysInfo->freqProcessor = 9 * sysInfo->freqSystemBus/2; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 92 | break; |
| 93 | default: |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame^] | 94 | /* JB - Emulator workaround until real cop is plugged in */ |
| 95 | /* sysInfo->freqProcessor = 3 * sysInfo->freqSystemBus; */ |
| 96 | sysInfo->freqProcessor = e600_ratio + sysInfo->freqSystemBus; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 97 | break; |
| 98 | } |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame^] | 99 | #if 0 |
| 100 | printf("assigned processor freq = %d for e600 ratio 0x%08lx\n", |
| 101 | sysInfo->freqProcessor, e600_ratio); |
| 102 | #endif |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 106 | /* |
| 107 | * Measure CPU clock speed (core clock GCLK1, GCLK2) |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 108 | * (Approx. GCLK frequency in Hz) |
| 109 | */ |
| 110 | |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame^] | 111 | int get_clocks(void) |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 112 | { |
| 113 | DECLARE_GLOBAL_DATA_PTR; |
| 114 | sys_info_t sys_info; |
| 115 | |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame^] | 116 | get_sys_info(&sys_info); |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 117 | gd->cpu_clk = sys_info.freqProcessor; |
| 118 | gd->bus_clk = sys_info.freqSystemBus; |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame^] | 119 | |
| 120 | if (gd->cpu_clk != 0) |
| 121 | return 0; |
| 122 | else |
| 123 | return 1; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 124 | } |
| 125 | |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame^] | 126 | |
| 127 | /* |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 128 | * get_bus_freq |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame^] | 129 | * Return system bus freq in Hz |
| 130 | */ |
| 131 | ulong get_bus_freq(ulong dummy) |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 132 | { |
| 133 | ulong val; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 134 | sys_info_t sys_info; |
| 135 | |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame^] | 136 | get_sys_info(&sys_info); |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 137 | val = sys_info.freqSystemBus; |
| 138 | |
| 139 | return val; |
| 140 | } |
| 141 | |
| 142 | unsigned long get_sysclk_from_px_regs() |
| 143 | { |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame^] | 144 | ulong val; |
| 145 | u8 vclkh, vclkl; |
| 146 | |
| 147 | vclkh = in8(PIXIS_BASE + PIXIS_VCLKH); |
| 148 | vclkl = in8(PIXIS_BASE + PIXIS_VCLKL); |
| 149 | |
| 150 | if ((vclkh == 0x84) && (vclkl == 0x07)) { |
| 151 | val = 33000000; |
| 152 | } |
| 153 | if ((vclkh == 0x3F) && (vclkl == 0x20)) { |
| 154 | val = 40000000; |
| 155 | } |
| 156 | if ((vclkh == 0x3F) && (vclkl == 0x2A)) { |
| 157 | val = 50000000; |
| 158 | } |
| 159 | if ((vclkh == 0x24) && (vclkl == 0x04)) { |
| 160 | val = 66000000; |
| 161 | } |
| 162 | if ((vclkh == 0x3F) && (vclkl == 0x4B)) { |
| 163 | val = 83000000; |
| 164 | } |
| 165 | if ((vclkh == 0x3F) && (vclkl == 0x5C)) { |
| 166 | val = 100000000; |
| 167 | } |
| 168 | if ((vclkh == 0xDF) && (vclkl == 0x3B)) { |
| 169 | val = 134000000; |
| 170 | } |
| 171 | if ((vclkh == 0xDF) && (vclkl == 0x4B)) { |
| 172 | val = 166000000; |
| 173 | } |
| 174 | |
| 175 | return val; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 176 | } |
| 177 | |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame^] | 178 | |
| 179 | /* |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 180 | * get_board_sys_clk |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame^] | 181 | * Reads the FPGA on board for CONFIG_SYS_CLK_FREQ |
| 182 | */ |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 183 | |
| 184 | unsigned long get_board_sys_clk(ulong dummy) |
| 185 | { |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame^] | 186 | u8 i, go_bit, rd_clks; |
| 187 | ulong val; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 188 | |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame^] | 189 | go_bit = in8(PIXIS_BASE + PIXIS_VCTL); |
| 190 | go_bit &= 0x01; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 191 | |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame^] | 192 | rd_clks = in8(PIXIS_BASE + PIXIS_VCFGEN0); |
| 193 | rd_clks &= 0x1C; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 194 | |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame^] | 195 | /* |
| 196 | * Only if both go bit and the SCLK bit in VCFGEN0 are set |
| 197 | * should we be using the AUX register. Remember, we also set the |
| 198 | * GO bit to boot from the alternate bank on the on-board flash |
| 199 | */ |
| 200 | |
| 201 | if (go_bit) { |
| 202 | if (rd_clks == 0x1c) |
| 203 | i = in8(PIXIS_BASE + PIXIS_AUX); |
| 204 | else |
| 205 | i = in8(PIXIS_BASE + PIXIS_SPD); |
| 206 | } else { |
| 207 | i = in8(PIXIS_BASE + PIXIS_SPD); |
| 208 | } |
| 209 | |
| 210 | i &= 0x07; |
| 211 | |
| 212 | switch (i) { |
| 213 | case 0: |
| 214 | val = 33000000; |
| 215 | break; |
| 216 | case 1: |
| 217 | val = 40000000; |
| 218 | break; |
| 219 | case 2: |
| 220 | val = 50000000; |
| 221 | break; |
| 222 | case 3: |
| 223 | val = 66000000; |
| 224 | break; |
| 225 | case 4: |
| 226 | val = 83000000; |
| 227 | break; |
| 228 | case 5: |
| 229 | val = 100000000; |
| 230 | break; |
| 231 | case 6: |
| 232 | val = 134000000; |
| 233 | break; |
| 234 | case 7: |
| 235 | val = 166000000; |
| 236 | break; |
| 237 | } |
| 238 | |
| 239 | return val; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 240 | } |