wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 1 | /* |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 2 | * (C) Copyright 2000-2006 |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | /* |
wdenk | 8564acf | 2003-07-14 22:13:32 +0000 | [diff] [blame] | 25 | * CPU specific code for the MPC825x / MPC826x / MPC827x / MPC828x |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 26 | * |
| 27 | * written or collected and sometimes rewritten by |
| 28 | * Magnus Damm <damm@bitsmart.com> |
| 29 | * |
wdenk | 4532cb6 | 2003-04-27 22:52:51 +0000 | [diff] [blame] | 30 | * modified by |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 31 | * Wolfgang Denk <wd@denx.de> |
| 32 | * |
| 33 | * modified for 8260 by |
| 34 | * Murray Jensen <Murray.Jensen@cmst.csiro.au> |
| 35 | * |
| 36 | * added 8260 masks by |
| 37 | * Marius Groeger <mag@sysgo.de> |
wdenk | 8564acf | 2003-07-14 22:13:32 +0000 | [diff] [blame] | 38 | * |
wdenk | 04a85b3 | 2004-04-15 18:22:41 +0000 | [diff] [blame] | 39 | * added HiP7 (824x/827x/8280) processors support by |
wdenk | 8564acf | 2003-07-14 22:13:32 +0000 | [diff] [blame] | 40 | * Yuli Barcohen <yuli@arabellasw.com> |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 41 | */ |
| 42 | |
| 43 | #include <common.h> |
| 44 | #include <watchdog.h> |
| 45 | #include <command.h> |
| 46 | #include <mpc8260.h> |
| 47 | #include <asm/processor.h> |
| 48 | #include <asm/cpm_8260.h> |
| 49 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 50 | DECLARE_GLOBAL_DATA_PTR; |
| 51 | |
Heiko Schocher | fa23044 | 2006-12-21 17:17:02 +0100 | [diff] [blame] | 52 | #if defined(CONFIG_GET_CPU_STR_F) |
| 53 | extern int get_cpu_str_f (char *buf); |
| 54 | #endif |
| 55 | |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 56 | int checkcpu (void) |
| 57 | { |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 58 | volatile immap_t *immap = (immap_t *) CFG_IMMR; |
| 59 | ulong clock = gd->cpu_clk; |
| 60 | uint pvr = get_pvr (); |
| 61 | uint immr, rev, m, k; |
| 62 | char buf[32]; |
| 63 | |
| 64 | puts ("CPU: "); |
| 65 | |
wdenk | 8564acf | 2003-07-14 22:13:32 +0000 | [diff] [blame] | 66 | switch (pvr) { |
| 67 | case PVR_8260: |
| 68 | case PVR_8260_HIP3: |
| 69 | k = 3; |
| 70 | break; |
| 71 | case PVR_8260_HIP4: |
| 72 | k = 4; |
| 73 | break; |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 74 | case PVR_8260_HIP7R1: |
wdenk | e1599e8 | 2004-10-10 23:27:33 +0000 | [diff] [blame] | 75 | case PVR_8260_HIP7RA: |
wdenk | 8564acf | 2003-07-14 22:13:32 +0000 | [diff] [blame] | 76 | case PVR_8260_HIP7: |
| 77 | k = 7; |
| 78 | break; |
| 79 | default: |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 80 | return -1; /* whoops! not an MPC8260 */ |
wdenk | 8564acf | 2003-07-14 22:13:32 +0000 | [diff] [blame] | 81 | } |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 82 | rev = pvr & 0xff; |
| 83 | |
| 84 | immr = immap->im_memctl.memc_immr; |
| 85 | if ((immr & IMMR_ISB_MSK) != CFG_IMMR) |
| 86 | return -1; /* whoops! someone moved the IMMR */ |
| 87 | |
Heiko Schocher | fa23044 | 2006-12-21 17:17:02 +0100 | [diff] [blame] | 88 | #if defined(CONFIG_GET_CPU_STR_F) |
| 89 | get_cpu_str_f (buf); |
| 90 | printf ("%s (HiP%d Rev %02x, Mask ", buf, k, rev); |
| 91 | #else |
wdenk | 8564acf | 2003-07-14 22:13:32 +0000 | [diff] [blame] | 92 | printf (CPU_ID_STR " (HiP%d Rev %02x, Mask ", k, rev); |
Heiko Schocher | fa23044 | 2006-12-21 17:17:02 +0100 | [diff] [blame] | 93 | #endif |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 94 | |
| 95 | /* |
| 96 | * the bottom 16 bits of the immr are the Part Number and Mask Number |
| 97 | * (4-34); the 16 bits at PROFF_REVNUM (0x8af0) in dual port ram is the |
| 98 | * RISC Microcode Revision Number (13-10). |
| 99 | * For the 8260, Motorola doesn't include the Microcode Revision |
| 100 | * in the mask. |
| 101 | */ |
| 102 | m = immr & (IMMR_PARTNUM_MSK | IMMR_MASKNUM_MSK); |
| 103 | k = *((ushort *) & immap->im_dprambase[PROFF_REVNUM]); |
| 104 | |
| 105 | switch (m) { |
| 106 | case 0x0000: |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 107 | puts ("0.2 2J24M"); |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 108 | break; |
| 109 | case 0x0010: |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 110 | puts ("A.0 K22A"); |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 111 | break; |
| 112 | case 0x0011: |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 113 | puts ("A.1 1K22A-XC"); |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 114 | break; |
| 115 | case 0x0001: |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 116 | puts ("B.1 1K23A"); |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 117 | break; |
| 118 | case 0x0021: |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 119 | puts ("B.2 2K23A-XC"); |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 120 | break; |
| 121 | case 0x0023: |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 122 | puts ("B.3 3K23A"); |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 123 | break; |
| 124 | case 0x0024: |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 125 | puts ("C.2 6K23A"); |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 126 | break; |
| 127 | case 0x0060: |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 128 | puts ("A.0(A) 2K25A"); |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 129 | break; |
wdenk | 4532cb6 | 2003-04-27 22:52:51 +0000 | [diff] [blame] | 130 | case 0x0062: |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 131 | puts ("B.1 4K25A"); |
wdenk | 4532cb6 | 2003-04-27 22:52:51 +0000 | [diff] [blame] | 132 | break; |
wdenk | 54387ac | 2003-10-08 22:45:44 +0000 | [diff] [blame] | 133 | case 0x0064: |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 134 | puts ("C.0 5K25A"); |
wdenk | 54387ac | 2003-10-08 22:45:44 +0000 | [diff] [blame] | 135 | break; |
wdenk | 8564acf | 2003-07-14 22:13:32 +0000 | [diff] [blame] | 136 | case 0x0A00: |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 137 | puts ("0.0 0K49M"); |
wdenk | 8564acf | 2003-07-14 22:13:32 +0000 | [diff] [blame] | 138 | break; |
| 139 | case 0x0A01: |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 140 | puts ("0.1 1K49M"); |
wdenk | 8564acf | 2003-07-14 22:13:32 +0000 | [diff] [blame] | 141 | break; |
wdenk | e1599e8 | 2004-10-10 23:27:33 +0000 | [diff] [blame] | 142 | case 0x0A10: |
| 143 | puts ("1.0 1K49M"); |
| 144 | break; |
wdenk | 04a85b3 | 2004-04-15 18:22:41 +0000 | [diff] [blame] | 145 | case 0x0C00: |
wdenk | e1599e8 | 2004-10-10 23:27:33 +0000 | [diff] [blame] | 146 | puts ("0.0 0K50M"); |
| 147 | break; |
| 148 | case 0x0C10: |
Wolfgang Denk | d980a16 | 2005-08-06 02:03:03 +0200 | [diff] [blame] | 149 | puts ("1.0 1K50M"); |
wdenk | e1599e8 | 2004-10-10 23:27:33 +0000 | [diff] [blame] | 150 | break; |
wdenk | 04a85b3 | 2004-04-15 18:22:41 +0000 | [diff] [blame] | 151 | case 0x0D00: |
wdenk | e1599e8 | 2004-10-10 23:27:33 +0000 | [diff] [blame] | 152 | puts ("0.0 0K50M"); |
| 153 | break; |
| 154 | case 0x0D10: |
Wolfgang Denk | d980a16 | 2005-08-06 02:03:03 +0200 | [diff] [blame] | 155 | puts ("1.0 1K50M"); |
wdenk | 04a85b3 | 2004-04-15 18:22:41 +0000 | [diff] [blame] | 156 | break; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 157 | default: |
| 158 | printf ("unknown [immr=0x%04x,k=0x%04x]", m, k); |
| 159 | break; |
| 160 | } |
| 161 | |
| 162 | printf (") at %s MHz\n", strmhz (buf, clock)); |
| 163 | |
| 164 | return 0; |
| 165 | } |
| 166 | |
| 167 | /* ------------------------------------------------------------------------- */ |
| 168 | /* configures a UPM by writing into the UPM RAM array */ |
| 169 | /* uses bank 11 and a dummy physical address (=BRx_BA_MSK) */ |
| 170 | /* NOTE: the physical address chosen must not overlap into any other area */ |
| 171 | /* mapped by the memory controller because bank 11 has the lowest priority */ |
| 172 | |
| 173 | void upmconfig (uint upm, uint * table, uint size) |
| 174 | { |
| 175 | volatile immap_t *immap = (immap_t *) CFG_IMMR; |
| 176 | volatile memctl8260_t *memctl = &immap->im_memctl; |
| 177 | volatile uchar *dummy = (uchar *) BRx_BA_MSK; /* set all BA bits */ |
| 178 | uint i; |
| 179 | |
| 180 | /* first set up bank 11 to reference the correct UPM at a dummy address */ |
| 181 | |
| 182 | memctl->memc_or11 = ORxU_AM_MSK; /* set all AM bits */ |
| 183 | |
| 184 | switch (upm) { |
| 185 | |
| 186 | case UPMA: |
| 187 | memctl->memc_br11 = |
| 188 | ((uint)dummy & BRx_BA_MSK) | BRx_PS_32 | BRx_MS_UPMA | |
| 189 | BRx_V; |
| 190 | memctl->memc_mamr = MxMR_OP_WARR; |
| 191 | break; |
| 192 | |
| 193 | case UPMB: |
| 194 | memctl->memc_br11 = |
| 195 | ((uint)dummy & BRx_BA_MSK) | BRx_PS_32 | BRx_MS_UPMB | |
| 196 | BRx_V; |
| 197 | memctl->memc_mbmr = MxMR_OP_WARR; |
| 198 | break; |
| 199 | |
| 200 | case UPMC: |
| 201 | memctl->memc_br11 = |
| 202 | ((uint)dummy & BRx_BA_MSK) | BRx_PS_32 | BRx_MS_UPMC | |
| 203 | BRx_V; |
| 204 | memctl->memc_mcmr = MxMR_OP_WARR; |
| 205 | break; |
| 206 | |
| 207 | default: |
| 208 | panic ("upmconfig passed invalid UPM number (%u)\n", upm); |
| 209 | break; |
| 210 | |
| 211 | } |
| 212 | |
| 213 | /* |
| 214 | * at this point, the dummy address is set up to access the selected UPM, |
| 215 | * the MAD pointer is zero, and the MxMR OP is set for writing to RAM |
| 216 | * |
| 217 | * now we simply load the mdr with each word and poke the dummy address. |
| 218 | * the MAD is incremented on each access. |
| 219 | */ |
| 220 | |
| 221 | for (i = 0; i < size; i++) { |
| 222 | memctl->memc_mdr = table[i]; |
| 223 | *dummy = 0; |
| 224 | } |
| 225 | |
| 226 | /* now kill bank 11 */ |
| 227 | memctl->memc_br11 = 0; |
| 228 | } |
| 229 | |
| 230 | /* ------------------------------------------------------------------------- */ |
| 231 | |
wdenk | ba91e26 | 2005-05-30 23:55:42 +0000 | [diff] [blame] | 232 | #if !defined(CONFIG_HAVE_OWN_RESET) |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 233 | int |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 234 | do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 235 | { |
| 236 | ulong msr, addr; |
| 237 | |
| 238 | volatile immap_t *immap = (immap_t *) CFG_IMMR; |
| 239 | |
| 240 | immap->im_clkrst.car_rmr = RMR_CSRE; /* Checkstop Reset enable */ |
| 241 | |
| 242 | /* Interrupts and MMU off */ |
| 243 | __asm__ __volatile__ ("mfmsr %0":"=r" (msr):); |
| 244 | |
| 245 | msr &= ~(MSR_ME | MSR_EE | MSR_IR | MSR_DR); |
| 246 | __asm__ __volatile__ ("mtmsr %0"::"r" (msr)); |
| 247 | |
| 248 | /* |
| 249 | * Trying to execute the next instruction at a non-existing address |
| 250 | * should cause a machine check, resulting in reset |
| 251 | */ |
| 252 | #ifdef CFG_RESET_ADDRESS |
| 253 | addr = CFG_RESET_ADDRESS; |
| 254 | #else |
| 255 | /* |
| 256 | * note: when CFG_MONITOR_BASE points to a RAM address, CFG_MONITOR_BASE |
| 257 | * - sizeof (ulong) is usually a valid address. Better pick an address |
| 258 | * known to be invalid on your system and assign it to CFG_RESET_ADDRESS. |
| 259 | */ |
| 260 | addr = CFG_MONITOR_BASE - sizeof (ulong); |
| 261 | #endif |
| 262 | ((void (*)(void)) addr) (); |
| 263 | return 1; |
| 264 | |
| 265 | } |
wdenk | ba91e26 | 2005-05-30 23:55:42 +0000 | [diff] [blame] | 266 | #endif /* CONFIG_HAVE_OWN_RESET */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 267 | |
| 268 | /* ------------------------------------------------------------------------- */ |
| 269 | |
| 270 | /* |
| 271 | * Get timebase clock frequency (like cpu_clk in Hz) |
| 272 | * |
| 273 | */ |
| 274 | unsigned long get_tbclk (void) |
| 275 | { |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 276 | ulong tbclk; |
| 277 | |
| 278 | tbclk = (gd->bus_clk + 3L) / 4L; |
| 279 | |
| 280 | return (tbclk); |
| 281 | } |
| 282 | |
| 283 | /* ------------------------------------------------------------------------- */ |
| 284 | |
| 285 | #if defined(CONFIG_WATCHDOG) |
| 286 | void watchdog_reset (void) |
| 287 | { |
| 288 | int re_enable = disable_interrupts (); |
| 289 | |
| 290 | reset_8260_watchdog ((immap_t *) CFG_IMMR); |
| 291 | if (re_enable) |
| 292 | enable_interrupts (); |
| 293 | } |
| 294 | #endif /* CONFIG_WATCHDOG */ |
| 295 | |
| 296 | /* ------------------------------------------------------------------------- */ |