wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1 | /* |
Andy Fleming | f574097 | 2008-02-06 01:19:40 -0600 | [diff] [blame] | 2 | * Copyright 2004,2007,2008 Freescale Semiconductor, Inc. |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 3 | * (C) Copyright 2002, 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 <watchdog.h> |
| 30 | #include <command.h> |
| 31 | #include <asm/cache.h> |
| 32 | |
James Yang | 957b191 | 2008-02-08 16:44:53 -0600 | [diff] [blame] | 33 | DECLARE_GLOBAL_DATA_PTR; |
| 34 | |
Andy Fleming | f574097 | 2008-02-06 01:19:40 -0600 | [diff] [blame] | 35 | struct cpu_type { |
| 36 | char name[15]; |
| 37 | u32 soc_ver; |
| 38 | }; |
| 39 | |
| 40 | #define CPU_TYPE_ENTRY(x) {#x, SVR_##x} |
| 41 | |
| 42 | struct cpu_type cpu_type_list [] = { |
| 43 | CPU_TYPE_ENTRY(8533), |
| 44 | CPU_TYPE_ENTRY(8533_E), |
| 45 | CPU_TYPE_ENTRY(8540), |
| 46 | CPU_TYPE_ENTRY(8541), |
| 47 | CPU_TYPE_ENTRY(8541_E), |
| 48 | CPU_TYPE_ENTRY(8543), |
| 49 | CPU_TYPE_ENTRY(8543_E), |
| 50 | CPU_TYPE_ENTRY(8544), |
| 51 | CPU_TYPE_ENTRY(8544_E), |
| 52 | CPU_TYPE_ENTRY(8545), |
| 53 | CPU_TYPE_ENTRY(8545_E), |
| 54 | CPU_TYPE_ENTRY(8547_E), |
| 55 | CPU_TYPE_ENTRY(8548), |
| 56 | CPU_TYPE_ENTRY(8548_E), |
| 57 | CPU_TYPE_ENTRY(8555), |
| 58 | CPU_TYPE_ENTRY(8555_E), |
| 59 | CPU_TYPE_ENTRY(8560), |
| 60 | CPU_TYPE_ENTRY(8567), |
| 61 | CPU_TYPE_ENTRY(8567_E), |
| 62 | CPU_TYPE_ENTRY(8568), |
| 63 | CPU_TYPE_ENTRY(8568_E), |
| 64 | CPU_TYPE_ENTRY(8572), |
| 65 | CPU_TYPE_ENTRY(8572_E), |
| 66 | }; |
| 67 | |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 68 | int checkcpu (void) |
| 69 | { |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 70 | sys_info_t sysinfo; |
| 71 | uint lcrr; /* local bus clock ratio register */ |
| 72 | uint clkdiv; /* clock divider portion of lcrr */ |
| 73 | uint pvr, svr; |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 74 | uint fam; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 75 | uint ver; |
| 76 | uint major, minor; |
Andy Fleming | f574097 | 2008-02-06 01:19:40 -0600 | [diff] [blame] | 77 | int i; |
Kumar Gala | 54b6810 | 2008-05-29 01:21:24 -0500 | [diff] [blame^] | 78 | #ifdef CONFIG_DDR_CLK_FREQ |
Kumar Gala | 07db170 | 2007-12-07 04:59:26 -0600 | [diff] [blame] | 79 | volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR); |
Kumar Gala | 54b6810 | 2008-05-29 01:21:24 -0500 | [diff] [blame^] | 80 | u32 ddr_ratio = ((gur->porpllsr) & 0x00003e00) >> 9; |
| 81 | #else |
| 82 | u32 ddr_ratio = 0; |
| 83 | #endif |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 84 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 85 | svr = get_svr(); |
Andy Fleming | f574097 | 2008-02-06 01:19:40 -0600 | [diff] [blame] | 86 | ver = SVR_SOC_VER(svr); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 87 | major = SVR_MAJ(svr); |
| 88 | minor = SVR_MIN(svr); |
| 89 | |
wdenk | 3f3262b | 2005-03-15 22:56:53 +0000 | [diff] [blame] | 90 | puts("CPU: "); |
Andy Fleming | f574097 | 2008-02-06 01:19:40 -0600 | [diff] [blame] | 91 | |
| 92 | for (i = 0; i < ARRAY_SIZE(cpu_type_list); i++) |
| 93 | if (cpu_type_list[i].soc_ver == ver) { |
| 94 | puts(cpu_type_list[i].name); |
| 95 | break; |
| 96 | } |
| 97 | |
| 98 | if (i == ARRAY_SIZE(cpu_type_list)) |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 99 | puts("Unknown"); |
Andy Fleming | f574097 | 2008-02-06 01:19:40 -0600 | [diff] [blame] | 100 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 101 | printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 102 | |
wdenk | 3f3262b | 2005-03-15 22:56:53 +0000 | [diff] [blame] | 103 | pvr = get_pvr(); |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 104 | fam = PVR_FAM(pvr); |
wdenk | 3f3262b | 2005-03-15 22:56:53 +0000 | [diff] [blame] | 105 | ver = PVR_VER(pvr); |
| 106 | major = PVR_MAJ(pvr); |
| 107 | minor = PVR_MIN(pvr); |
| 108 | |
| 109 | printf("Core: "); |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 110 | switch (fam) { |
| 111 | case PVR_FAM(PVR_85xx): |
wdenk | 3f3262b | 2005-03-15 22:56:53 +0000 | [diff] [blame] | 112 | puts("E500"); |
| 113 | break; |
| 114 | default: |
| 115 | puts("Unknown"); |
| 116 | break; |
| 117 | } |
| 118 | printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr); |
| 119 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 120 | get_sys_info(&sysinfo); |
| 121 | |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 122 | puts("Clock Configuration:\n"); |
Kumar Gala | 93d5ffb | 2008-04-21 09:28:36 -0500 | [diff] [blame] | 123 | printf(" CPU:%4lu MHz, ", DIV_ROUND_UP(sysinfo.freqProcessor,1000000)); |
| 124 | printf("CCB:%4lu MHz,\n", DIV_ROUND_UP(sysinfo.freqSystemBus,1000000)); |
Kumar Gala | 54b6810 | 2008-05-29 01:21:24 -0500 | [diff] [blame^] | 125 | |
Kumar Gala | 07db170 | 2007-12-07 04:59:26 -0600 | [diff] [blame] | 126 | switch (ddr_ratio) { |
| 127 | case 0x0: |
James Yang | 5dab484 | 2008-02-08 16:46:27 -0600 | [diff] [blame] | 128 | printf(" DDR:%4lu MHz (%lu MT/s data rate), ", |
Kumar Gala | 93d5ffb | 2008-04-21 09:28:36 -0500 | [diff] [blame] | 129 | DIV_ROUND_UP(sysinfo.freqDDRBus,2000000), DIV_ROUND_UP(sysinfo.freqDDRBus,1000000)); |
Kumar Gala | 07db170 | 2007-12-07 04:59:26 -0600 | [diff] [blame] | 130 | break; |
| 131 | case 0x7: |
James Yang | 5dab484 | 2008-02-08 16:46:27 -0600 | [diff] [blame] | 132 | printf(" DDR:%4lu MHz (%lu MT/s data rate) (Synchronous), ", |
Kumar Gala | 93d5ffb | 2008-04-21 09:28:36 -0500 | [diff] [blame] | 133 | DIV_ROUND_UP(sysinfo.freqDDRBus, 2000000), DIV_ROUND_UP(sysinfo.freqDDRBus, 1000000)); |
Kumar Gala | 07db170 | 2007-12-07 04:59:26 -0600 | [diff] [blame] | 134 | break; |
| 135 | default: |
James Yang | 5dab484 | 2008-02-08 16:46:27 -0600 | [diff] [blame] | 136 | printf(" DDR:%4lu MHz (%lu MT/s data rate) (Asynchronous), ", |
Kumar Gala | 93d5ffb | 2008-04-21 09:28:36 -0500 | [diff] [blame] | 137 | DIV_ROUND_UP(sysinfo.freqDDRBus, 2000000), DIV_ROUND_UP(sysinfo.freqDDRBus,1000000)); |
Kumar Gala | 07db170 | 2007-12-07 04:59:26 -0600 | [diff] [blame] | 138 | break; |
| 139 | } |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 140 | |
| 141 | #if defined(CFG_LBC_LCRR) |
| 142 | lcrr = CFG_LBC_LCRR; |
| 143 | #else |
| 144 | { |
Kumar Gala | 0a7a097 | 2007-11-29 02:10:09 -0600 | [diff] [blame] | 145 | volatile ccsr_lbc_t *lbc = (void *)(CFG_MPC85xx_LBC_ADDR); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 146 | |
| 147 | lcrr = lbc->lcrr; |
| 148 | } |
| 149 | #endif |
| 150 | clkdiv = lcrr & 0x0f; |
| 151 | if (clkdiv == 2 || clkdiv == 4 || clkdiv == 8) { |
Andy Fleming | f631cca | 2007-04-23 01:32:22 -0500 | [diff] [blame] | 152 | #if defined(CONFIG_MPC8548) || defined(CONFIG_MPC8544) |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 153 | /* |
| 154 | * Yes, the entire PQ38 family use the same |
| 155 | * bit-representation for twice the clock divider values. |
| 156 | */ |
| 157 | clkdiv *= 2; |
| 158 | #endif |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 159 | printf("LBC:%4lu MHz\n", |
Kumar Gala | 93d5ffb | 2008-04-21 09:28:36 -0500 | [diff] [blame] | 160 | DIV_ROUND_UP(sysinfo.freqSystemBus, 1000000) / clkdiv); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 161 | } else { |
wdenk | 3f3262b | 2005-03-15 22:56:53 +0000 | [diff] [blame] | 162 | printf("LBC: unknown (lcrr: 0x%08x)\n", lcrr); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 163 | } |
| 164 | |
Andy Fleming | f574097 | 2008-02-06 01:19:40 -0600 | [diff] [blame] | 165 | #ifdef CONFIG_CPM2 |
| 166 | printf("CPM: %lu Mhz\n", sysinfo.freqSystemBus / 1000000); |
| 167 | #endif |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 168 | |
wdenk | 3f3262b | 2005-03-15 22:56:53 +0000 | [diff] [blame] | 169 | puts("L1: D-cache 32 kB enabled\n I-cache 32 kB enabled\n"); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 170 | |
| 171 | return 0; |
| 172 | } |
| 173 | |
| 174 | |
| 175 | /* ------------------------------------------------------------------------- */ |
| 176 | |
| 177 | int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]) |
| 178 | { |
Zang Roy-r61911 | 395478d | 2006-12-05 16:42:30 +0800 | [diff] [blame] | 179 | uint pvr; |
| 180 | uint ver; |
Sergei Poselenov | 2514742 | 2008-05-08 14:17:08 +0200 | [diff] [blame] | 181 | unsigned long val, msr; |
| 182 | |
Zang Roy-r61911 | 395478d | 2006-12-05 16:42:30 +0800 | [diff] [blame] | 183 | pvr = get_pvr(); |
| 184 | ver = PVR_VER(pvr); |
Sergei Poselenov | 2514742 | 2008-05-08 14:17:08 +0200 | [diff] [blame] | 185 | |
Zang Roy-r61911 | 395478d | 2006-12-05 16:42:30 +0800 | [diff] [blame] | 186 | if (ver & 1){ |
| 187 | /* e500 v2 core has reset control register */ |
| 188 | volatile unsigned int * rstcr; |
| 189 | rstcr = (volatile unsigned int *)(CFG_IMMR + 0xE00B0); |
Wolfgang Denk | 58c495b | 2007-05-05 18:23:11 +0200 | [diff] [blame] | 190 | *rstcr = 0x2; /* HRESET_REQ */ |
Sergei Poselenov | 2514742 | 2008-05-08 14:17:08 +0200 | [diff] [blame] | 191 | udelay(100); |
| 192 | } |
| 193 | |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 194 | /* |
Sergei Poselenov | 2514742 | 2008-05-08 14:17:08 +0200 | [diff] [blame] | 195 | * Fallthrough if the code above failed |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 196 | * Initiate hard reset in debug control register DBCR0 |
| 197 | * Make sure MSR[DE] = 1 |
| 198 | */ |
urwithsughosh@gmail.com | 06c2fb9 | 2007-09-24 13:32:13 -0400 | [diff] [blame] | 199 | |
Sergei Poselenov | 2514742 | 2008-05-08 14:17:08 +0200 | [diff] [blame] | 200 | msr = mfmsr (); |
| 201 | msr |= MSR_DE; |
| 202 | mtmsr (msr); |
urwithsughosh@gmail.com | 06c2fb9 | 2007-09-24 13:32:13 -0400 | [diff] [blame] | 203 | |
Sergei Poselenov | 2514742 | 2008-05-08 14:17:08 +0200 | [diff] [blame] | 204 | val = mfspr(DBCR0); |
| 205 | val |= 0x70000000; |
| 206 | mtspr(DBCR0,val); |
| 207 | |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 208 | return 1; |
| 209 | } |
| 210 | |
| 211 | |
| 212 | /* |
| 213 | * Get timebase clock frequency |
| 214 | */ |
| 215 | unsigned long get_tbclk (void) |
| 216 | { |
James Yang | 957b191 | 2008-02-08 16:44:53 -0600 | [diff] [blame] | 217 | return (gd->bus_clk + 4UL)/8UL; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | |
| 221 | #if defined(CONFIG_WATCHDOG) |
| 222 | void |
| 223 | watchdog_reset(void) |
| 224 | { |
| 225 | int re_enable = disable_interrupts(); |
| 226 | reset_85xx_watchdog(); |
| 227 | if (re_enable) enable_interrupts(); |
| 228 | } |
| 229 | |
| 230 | void |
| 231 | reset_85xx_watchdog(void) |
| 232 | { |
| 233 | /* |
| 234 | * Clear TSR(WIS) bit by writing 1 |
| 235 | */ |
| 236 | unsigned long val; |
Andy Fleming | eac342d | 2007-04-23 01:44:44 -0500 | [diff] [blame] | 237 | val = mfspr(SPRN_TSR); |
| 238 | val |= TSR_WIS; |
| 239 | mtspr(SPRN_TSR, val); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 240 | } |
| 241 | #endif /* CONFIG_WATCHDOG */ |
| 242 | |
| 243 | #if defined(CONFIG_DDR_ECC) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 244 | void dma_init(void) { |
Kumar Gala | 0a7a097 | 2007-11-29 02:10:09 -0600 | [diff] [blame] | 245 | volatile ccsr_dma_t *dma = (void *)(CFG_MPC85xx_DMA_ADDR); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 246 | |
| 247 | dma->satr0 = 0x02c40000; |
| 248 | dma->datr0 = 0x02c40000; |
Andy Fleming | eac342d | 2007-04-23 01:44:44 -0500 | [diff] [blame] | 249 | dma->sr0 = 0xfffffff; /* clear any errors */ |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 250 | asm("sync; isync; msync"); |
| 251 | return; |
| 252 | } |
| 253 | |
| 254 | uint dma_check(void) { |
Kumar Gala | 0a7a097 | 2007-11-29 02:10:09 -0600 | [diff] [blame] | 255 | volatile ccsr_dma_t *dma = (void *)(CFG_MPC85xx_DMA_ADDR); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 256 | volatile uint status = dma->sr0; |
| 257 | |
| 258 | /* While the channel is busy, spin */ |
| 259 | while((status & 4) == 4) { |
| 260 | status = dma->sr0; |
| 261 | } |
| 262 | |
Andy Fleming | eac342d | 2007-04-23 01:44:44 -0500 | [diff] [blame] | 263 | /* clear MR0[CS] channel start bit */ |
| 264 | dma->mr0 &= 0x00000001; |
| 265 | asm("sync;isync;msync"); |
| 266 | |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 267 | if (status != 0) { |
| 268 | printf ("DMA Error: status = %x\n", status); |
| 269 | } |
| 270 | return status; |
| 271 | } |
| 272 | |
| 273 | int dma_xfer(void *dest, uint count, void *src) { |
Kumar Gala | 0a7a097 | 2007-11-29 02:10:09 -0600 | [diff] [blame] | 274 | volatile ccsr_dma_t *dma = (void *)(CFG_MPC85xx_DMA_ADDR); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 275 | |
| 276 | dma->dar0 = (uint) dest; |
| 277 | dma->sar0 = (uint) src; |
| 278 | dma->bcr0 = count; |
| 279 | dma->mr0 = 0xf000004; |
| 280 | asm("sync;isync;msync"); |
| 281 | dma->mr0 = 0xf000005; |
| 282 | asm("sync;isync;msync"); |
| 283 | return dma_check(); |
| 284 | } |
| 285 | #endif |