wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1 | /* |
Poonam Aggrwal | 18bacc2 | 2009-07-31 12:07:45 +0530 | [diff] [blame] | 2 | * Copyright 2004,2007-2009 Freescale Semiconductor, Inc. |
wdenk | 42d1f03 | 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 | |
Andy Fleming | 75b9d4a | 2008-08-31 16:33:26 -0500 | [diff] [blame] | 28 | #include <config.h> |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 29 | #include <common.h> |
| 30 | #include <watchdog.h> |
| 31 | #include <command.h> |
Andy Fleming | 80522dc | 2008-10-30 16:51:33 -0500 | [diff] [blame] | 32 | #include <fsl_esdhc.h> |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 33 | #include <asm/cache.h> |
Sergei Poselenov | 740280e | 2008-06-06 15:42:40 +0200 | [diff] [blame] | 34 | #include <asm/io.h> |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 35 | |
James Yang | 591933c | 2008-02-08 16:44:53 -0600 | [diff] [blame] | 36 | DECLARE_GLOBAL_DATA_PTR; |
| 37 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 38 | int checkcpu (void) |
| 39 | { |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 40 | sys_info_t sysinfo; |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 41 | uint pvr, svr; |
Jon Loeliger | d9b94f2 | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 42 | uint fam; |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 43 | uint ver; |
| 44 | uint major, minor; |
Kumar Gala | 4dbdb76 | 2008-06-10 16:53:46 -0500 | [diff] [blame] | 45 | struct cpu_type *cpu; |
Wolfgang Denk | 08ef89e | 2008-10-19 02:35:49 +0200 | [diff] [blame] | 46 | char buf1[32], buf2[32]; |
Kumar Gala | ee1e35b | 2008-05-29 01:21:24 -0500 | [diff] [blame] | 47 | #ifdef CONFIG_DDR_CLK_FREQ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 48 | volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); |
Jason Jin | c039111 | 2008-09-27 14:40:57 +0800 | [diff] [blame] | 49 | u32 ddr_ratio = ((gur->porpllsr) & MPC85xx_PORPLLSR_DDR_RATIO) |
| 50 | >> MPC85xx_PORPLLSR_DDR_RATIO_SHIFT; |
Kumar Gala | ee1e35b | 2008-05-29 01:21:24 -0500 | [diff] [blame] | 51 | #else |
| 52 | u32 ddr_ratio = 0; |
| 53 | #endif |
Haiying Wang | 2fc7eb0 | 2009-01-15 11:58:35 -0500 | [diff] [blame] | 54 | int i; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 55 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 56 | svr = get_svr(); |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 57 | major = SVR_MAJ(svr); |
Kumar Gala | ef50d6c | 2008-08-12 11:14:19 -0500 | [diff] [blame] | 58 | #ifdef CONFIG_MPC8536 |
| 59 | major &= 0x7; /* the msb of this nibble is a mfg code */ |
| 60 | #endif |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 61 | minor = SVR_MIN(svr); |
| 62 | |
Poonam Aggrwal | 0e87098 | 2009-07-31 12:08:14 +0530 | [diff] [blame] | 63 | if (cpu_numcores() > 1) { |
| 64 | volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC85xx_PIC_ADDR); |
| 65 | printf("CPU%d: ", pic->whoami); |
| 66 | } else { |
| 67 | puts("CPU: "); |
| 68 | } |
Andy Fleming | 1ced121 | 2008-02-06 01:19:40 -0600 | [diff] [blame] | 69 | |
Poonam Aggrwal | 0e87098 | 2009-07-31 12:08:14 +0530 | [diff] [blame] | 70 | cpu = gd->cpu; |
| 71 | |
| 72 | if (cpu->name) { |
Kumar Gala | 4dbdb76 | 2008-06-10 16:53:46 -0500 | [diff] [blame] | 73 | puts(cpu->name); |
Kim Phillips | 06b4186 | 2008-06-17 17:45:22 -0500 | [diff] [blame] | 74 | if (IS_E_PROCESSOR(svr)) |
Kumar Gala | 4dbdb76 | 2008-06-10 16:53:46 -0500 | [diff] [blame] | 75 | puts("E"); |
| 76 | } else { |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 77 | puts("Unknown"); |
Kumar Gala | 4dbdb76 | 2008-06-10 16:53:46 -0500 | [diff] [blame] | 78 | } |
Andy Fleming | 1ced121 | 2008-02-06 01:19:40 -0600 | [diff] [blame] | 79 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 80 | printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 81 | |
wdenk | 6c9e789 | 2005-03-15 22:56:53 +0000 | [diff] [blame] | 82 | pvr = get_pvr(); |
Jon Loeliger | d9b94f2 | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 83 | fam = PVR_FAM(pvr); |
wdenk | 6c9e789 | 2005-03-15 22:56:53 +0000 | [diff] [blame] | 84 | ver = PVR_VER(pvr); |
| 85 | major = PVR_MAJ(pvr); |
| 86 | minor = PVR_MIN(pvr); |
| 87 | |
| 88 | printf("Core: "); |
Jon Loeliger | d9b94f2 | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 89 | switch (fam) { |
| 90 | case PVR_FAM(PVR_85xx): |
wdenk | 6c9e789 | 2005-03-15 22:56:53 +0000 | [diff] [blame] | 91 | puts("E500"); |
| 92 | break; |
| 93 | default: |
| 94 | puts("Unknown"); |
| 95 | break; |
| 96 | } |
Kumar Gala | 0f060c3 | 2008-10-23 01:47:38 -0500 | [diff] [blame] | 97 | |
| 98 | if (PVR_MEM(pvr) == 0x03) |
| 99 | puts("MC"); |
| 100 | |
wdenk | 6c9e789 | 2005-03-15 22:56:53 +0000 | [diff] [blame] | 101 | printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr); |
| 102 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 103 | get_sys_info(&sysinfo); |
| 104 | |
Kumar Gala | b29dee3 | 2009-02-04 09:35:57 -0600 | [diff] [blame] | 105 | puts("Clock Configuration:"); |
Poonam Aggrwal | 0e87098 | 2009-07-31 12:08:14 +0530 | [diff] [blame] | 106 | for (i = 0; i < cpu_numcores(); i++) { |
Wolfgang Denk | 1bba30e | 2009-02-19 00:41:08 +0100 | [diff] [blame] | 107 | if (!(i & 3)) |
| 108 | printf ("\n "); |
Haiying Wang | 2fc7eb0 | 2009-01-15 11:58:35 -0500 | [diff] [blame] | 109 | printf("CPU%d:%-4s MHz, ", |
| 110 | i,strmhz(buf1, sysinfo.freqProcessor[i])); |
Kumar Gala | b29dee3 | 2009-02-04 09:35:57 -0600 | [diff] [blame] | 111 | } |
| 112 | printf("\n CCB:%-4s MHz,\n", strmhz(buf1, sysinfo.freqSystemBus)); |
Kumar Gala | ee1e35b | 2008-05-29 01:21:24 -0500 | [diff] [blame] | 113 | |
Kumar Gala | d435793 | 2007-12-07 04:59:26 -0600 | [diff] [blame] | 114 | switch (ddr_ratio) { |
| 115 | case 0x0: |
Wolfgang Denk | 08ef89e | 2008-10-19 02:35:49 +0200 | [diff] [blame] | 116 | printf(" DDR:%-4s MHz (%s MT/s data rate), ", |
| 117 | strmhz(buf1, sysinfo.freqDDRBus/2), |
| 118 | strmhz(buf2, sysinfo.freqDDRBus)); |
Kumar Gala | d435793 | 2007-12-07 04:59:26 -0600 | [diff] [blame] | 119 | break; |
| 120 | case 0x7: |
Wolfgang Denk | 08ef89e | 2008-10-19 02:35:49 +0200 | [diff] [blame] | 121 | printf(" DDR:%-4s MHz (%s MT/s data rate) (Synchronous), ", |
| 122 | strmhz(buf1, sysinfo.freqDDRBus/2), |
| 123 | strmhz(buf2, sysinfo.freqDDRBus)); |
Kumar Gala | d435793 | 2007-12-07 04:59:26 -0600 | [diff] [blame] | 124 | break; |
| 125 | default: |
Wolfgang Denk | 08ef89e | 2008-10-19 02:35:49 +0200 | [diff] [blame] | 126 | printf(" DDR:%-4s MHz (%s MT/s data rate) (Asynchronous), ", |
| 127 | strmhz(buf1, sysinfo.freqDDRBus/2), |
| 128 | strmhz(buf2, sysinfo.freqDDRBus)); |
Kumar Gala | d435793 | 2007-12-07 04:59:26 -0600 | [diff] [blame] | 129 | break; |
| 130 | } |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 131 | |
Trent Piepho | ada591d | 2008-12-03 15:16:37 -0800 | [diff] [blame] | 132 | if (sysinfo.freqLocalBus > LCRR_CLKDIV) |
| 133 | printf("LBC:%-4s MHz\n", strmhz(buf1, sysinfo.freqLocalBus)); |
| 134 | else |
| 135 | printf("LBC: unknown (LCRR[CLKDIV] = 0x%02lx)\n", |
| 136 | sysinfo.freqLocalBus); |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 137 | |
Andy Fleming | 1ced121 | 2008-02-06 01:19:40 -0600 | [diff] [blame] | 138 | #ifdef CONFIG_CPM2 |
Wolfgang Denk | 08ef89e | 2008-10-19 02:35:49 +0200 | [diff] [blame] | 139 | printf("CPM: %s MHz\n", strmhz(buf1, sysinfo.freqSystemBus)); |
Andy Fleming | 1ced121 | 2008-02-06 01:19:40 -0600 | [diff] [blame] | 140 | #endif |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 141 | |
Haiying Wang | b3d7f20 | 2009-05-20 12:30:29 -0400 | [diff] [blame] | 142 | #ifdef CONFIG_QE |
| 143 | printf(" QE:%-4s MHz\n", strmhz(buf1, sysinfo.freqQE)); |
| 144 | #endif |
| 145 | |
wdenk | 6c9e789 | 2005-03-15 22:56:53 +0000 | [diff] [blame] | 146 | puts("L1: D-cache 32 kB enabled\n I-cache 32 kB enabled\n"); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 147 | |
| 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | |
| 152 | /* ------------------------------------------------------------------------- */ |
| 153 | |
| 154 | int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]) |
| 155 | { |
Zang Roy-r61911 | 96629cb | 2006-12-05 16:42:30 +0800 | [diff] [blame] | 156 | uint pvr; |
| 157 | uint ver; |
Sergei Poselenov | 793670c | 2008-05-08 14:17:08 +0200 | [diff] [blame] | 158 | unsigned long val, msr; |
| 159 | |
Zang Roy-r61911 | 96629cb | 2006-12-05 16:42:30 +0800 | [diff] [blame] | 160 | pvr = get_pvr(); |
| 161 | ver = PVR_VER(pvr); |
Sergei Poselenov | 793670c | 2008-05-08 14:17:08 +0200 | [diff] [blame] | 162 | |
Zang Roy-r61911 | 96629cb | 2006-12-05 16:42:30 +0800 | [diff] [blame] | 163 | if (ver & 1){ |
| 164 | /* e500 v2 core has reset control register */ |
| 165 | volatile unsigned int * rstcr; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 166 | rstcr = (volatile unsigned int *)(CONFIG_SYS_IMMR + 0xE00B0); |
Wolfgang Denk | 2f15278 | 2007-05-05 18:23:11 +0200 | [diff] [blame] | 167 | *rstcr = 0x2; /* HRESET_REQ */ |
Sergei Poselenov | 793670c | 2008-05-08 14:17:08 +0200 | [diff] [blame] | 168 | udelay(100); |
| 169 | } |
| 170 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 171 | /* |
Sergei Poselenov | 793670c | 2008-05-08 14:17:08 +0200 | [diff] [blame] | 172 | * Fallthrough if the code above failed |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 173 | * Initiate hard reset in debug control register DBCR0 |
| 174 | * Make sure MSR[DE] = 1 |
| 175 | */ |
urwithsughosh@gmail.com | df90968 | 2007-09-24 13:32:13 -0400 | [diff] [blame] | 176 | |
Sergei Poselenov | 793670c | 2008-05-08 14:17:08 +0200 | [diff] [blame] | 177 | msr = mfmsr (); |
| 178 | msr |= MSR_DE; |
| 179 | mtmsr (msr); |
urwithsughosh@gmail.com | df90968 | 2007-09-24 13:32:13 -0400 | [diff] [blame] | 180 | |
Sergei Poselenov | 793670c | 2008-05-08 14:17:08 +0200 | [diff] [blame] | 181 | val = mfspr(DBCR0); |
| 182 | val |= 0x70000000; |
| 183 | mtspr(DBCR0,val); |
| 184 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 185 | return 1; |
| 186 | } |
| 187 | |
| 188 | |
| 189 | /* |
| 190 | * Get timebase clock frequency |
| 191 | */ |
| 192 | unsigned long get_tbclk (void) |
| 193 | { |
James Yang | 591933c | 2008-02-08 16:44:53 -0600 | [diff] [blame] | 194 | return (gd->bus_clk + 4UL)/8UL; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | |
| 198 | #if defined(CONFIG_WATCHDOG) |
| 199 | void |
| 200 | watchdog_reset(void) |
| 201 | { |
| 202 | int re_enable = disable_interrupts(); |
| 203 | reset_85xx_watchdog(); |
| 204 | if (re_enable) enable_interrupts(); |
| 205 | } |
| 206 | |
| 207 | void |
| 208 | reset_85xx_watchdog(void) |
| 209 | { |
| 210 | /* |
| 211 | * Clear TSR(WIS) bit by writing 1 |
| 212 | */ |
| 213 | unsigned long val; |
Andy Fleming | 03b81b4 | 2007-04-23 01:44:44 -0500 | [diff] [blame] | 214 | val = mfspr(SPRN_TSR); |
| 215 | val |= TSR_WIS; |
| 216 | mtspr(SPRN_TSR, val); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 217 | } |
| 218 | #endif /* CONFIG_WATCHDOG */ |
| 219 | |
Sergei Poselenov | 740280e | 2008-06-06 15:42:40 +0200 | [diff] [blame] | 220 | /* |
Sergei Poselenov | 59f6305 | 2008-08-15 15:42:11 +0200 | [diff] [blame] | 221 | * Configures a UPM. The function requires the respective MxMR to be set |
| 222 | * before calling this function. "size" is the number or entries, not a sizeof. |
Sergei Poselenov | 740280e | 2008-06-06 15:42:40 +0200 | [diff] [blame] | 223 | */ |
| 224 | void upmconfig (uint upm, uint * table, uint size) |
| 225 | { |
| 226 | int i, mdr, mad, old_mad = 0; |
| 227 | volatile u32 *mxmr; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 228 | volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR); |
Sergei Poselenov | 740280e | 2008-06-06 15:42:40 +0200 | [diff] [blame] | 229 | volatile u32 *brp,*orp; |
| 230 | volatile u8* dummy = NULL; |
| 231 | int upmmask; |
| 232 | |
| 233 | switch (upm) { |
| 234 | case UPMA: |
| 235 | mxmr = &lbc->mamr; |
| 236 | upmmask = BR_MS_UPMA; |
| 237 | break; |
| 238 | case UPMB: |
| 239 | mxmr = &lbc->mbmr; |
| 240 | upmmask = BR_MS_UPMB; |
| 241 | break; |
| 242 | case UPMC: |
| 243 | mxmr = &lbc->mcmr; |
| 244 | upmmask = BR_MS_UPMC; |
| 245 | break; |
| 246 | default: |
| 247 | printf("%s: Bad UPM index %d to configure\n", __FUNCTION__, upm); |
| 248 | hang(); |
| 249 | } |
| 250 | |
| 251 | /* Find the address for the dummy write transaction */ |
| 252 | for (brp = &lbc->br0, orp = &lbc->or0, i = 0; i < 8; |
| 253 | i++, brp += 2, orp += 2) { |
Wolfgang Denk | e093a24 | 2008-06-28 23:34:37 +0200 | [diff] [blame] | 254 | |
Sergei Poselenov | 740280e | 2008-06-06 15:42:40 +0200 | [diff] [blame] | 255 | /* Look for a valid BR with selected UPM */ |
Sergei Poselenov | 59f6305 | 2008-08-15 15:42:11 +0200 | [diff] [blame] | 256 | if ((in_be32(brp) & (BR_V | BR_MSEL)) == (BR_V | upmmask)) { |
| 257 | dummy = (volatile u8*)(in_be32(brp) & BR_BA); |
Sergei Poselenov | 740280e | 2008-06-06 15:42:40 +0200 | [diff] [blame] | 258 | break; |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | if (i == 8) { |
| 263 | printf("Error: %s() could not find matching BR\n", __FUNCTION__); |
| 264 | hang(); |
| 265 | } |
| 266 | |
| 267 | for (i = 0; i < size; i++) { |
| 268 | /* 1 */ |
Sergei Poselenov | 59f6305 | 2008-08-15 15:42:11 +0200 | [diff] [blame] | 269 | out_be32(mxmr, (in_be32(mxmr) & 0x4fffffc0) | MxMR_OP_WARR | i); |
Sergei Poselenov | 740280e | 2008-06-06 15:42:40 +0200 | [diff] [blame] | 270 | /* 2 */ |
| 271 | out_be32(&lbc->mdr, table[i]); |
| 272 | /* 3 */ |
| 273 | mdr = in_be32(&lbc->mdr); |
| 274 | /* 4 */ |
| 275 | *(volatile u8 *)dummy = 0; |
| 276 | /* 5 */ |
| 277 | do { |
Sergei Poselenov | 59f6305 | 2008-08-15 15:42:11 +0200 | [diff] [blame] | 278 | mad = in_be32(mxmr) & MxMR_MAD_MSK; |
Sergei Poselenov | 740280e | 2008-06-06 15:42:40 +0200 | [diff] [blame] | 279 | } while (mad <= old_mad && !(!mad && i == (size-1))); |
| 280 | old_mad = mad; |
| 281 | } |
Sergei Poselenov | 59f6305 | 2008-08-15 15:42:11 +0200 | [diff] [blame] | 282 | out_be32(mxmr, (in_be32(mxmr) & 0x4fffffc0) | MxMR_OP_NORM); |
Sergei Poselenov | 740280e | 2008-06-06 15:42:40 +0200 | [diff] [blame] | 283 | } |
Ben Warren | dd35479 | 2008-06-23 22:57:27 -0700 | [diff] [blame] | 284 | |
Andy Fleming | 80522dc | 2008-10-30 16:51:33 -0500 | [diff] [blame] | 285 | /* |
| 286 | * Initializes on-chip MMC controllers. |
| 287 | * to override, implement board_mmc_init() |
| 288 | */ |
| 289 | int cpu_mmc_init(bd_t *bis) |
| 290 | { |
| 291 | #ifdef CONFIG_FSL_ESDHC |
| 292 | return fsl_esdhc_mmc_init(bis); |
| 293 | #else |
| 294 | return 0; |
| 295 | #endif |
| 296 | } |