wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000-2002 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * m8xx.c |
| 10 | * |
| 11 | * CPU specific code |
| 12 | * |
| 13 | * written or collected and sometimes rewritten by |
| 14 | * Magnus Damm <damm@bitsmart.com> |
| 15 | * |
| 16 | * minor modifications by |
| 17 | * Wolfgang Denk <wd@denx.de> |
| 18 | */ |
| 19 | |
| 20 | #include <common.h> |
| 21 | #include <watchdog.h> |
| 22 | #include <command.h> |
| 23 | #include <mpc8xx.h> |
Ben Warren | bbff280 | 2008-10-23 22:02:49 -0700 | [diff] [blame] | 24 | #include <commproc.h> |
Ben Warren | 70618a3 | 2008-10-22 23:20:29 -0700 | [diff] [blame] | 25 | #include <netdev.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 26 | #include <asm/cache.h> |
Wolfgang Denk | 89f85ad | 2011-11-04 15:55:32 +0000 | [diff] [blame] | 27 | #include <linux/compiler.h> |
Marek Vasut | 25fe1e2 | 2012-07-28 00:57:12 +0200 | [diff] [blame] | 28 | #include <asm/io.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 29 | |
Heiko Schocher | 30c0feb | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 30 | #if defined(CONFIG_OF_LIBFDT) |
| 31 | #include <libfdt.h> |
Heiko Schocher | 30c0feb | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 32 | #include <fdt_support.h> |
| 33 | #endif |
| 34 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 35 | DECLARE_GLOBAL_DATA_PTR; |
| 36 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 37 | static char *cpu_warning = "\n " \ |
| 38 | "*** Warning: CPU Core has Silicon Bugs -- Check the Errata ***"; |
| 39 | |
wdenk | 2bb1105 | 2003-07-17 23:16:40 +0000 | [diff] [blame] | 40 | #if ((defined(CONFIG_MPC86x) || defined(CONFIG_MPC855)) && \ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 41 | !defined(CONFIG_MPC862)) |
wdenk | 2bb1105 | 2003-07-17 23:16:40 +0000 | [diff] [blame] | 42 | |
wdenk | ad276f2 | 2004-01-04 16:28:35 +0000 | [diff] [blame] | 43 | static int check_CPU (long clock, uint pvr, uint immr) |
| 44 | { |
| 45 | char *id_str = |
wdenk | 2bb1105 | 2003-07-17 23:16:40 +0000 | [diff] [blame] | 46 | # if defined(CONFIG_MPC855) |
wdenk | ad276f2 | 2004-01-04 16:28:35 +0000 | [diff] [blame] | 47 | "PC855"; |
wdenk | 2bb1105 | 2003-07-17 23:16:40 +0000 | [diff] [blame] | 48 | # elif defined(CONFIG_MPC860P) |
wdenk | ad276f2 | 2004-01-04 16:28:35 +0000 | [diff] [blame] | 49 | "PC860P"; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 50 | # else |
wdenk | ad276f2 | 2004-01-04 16:28:35 +0000 | [diff] [blame] | 51 | NULL; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 52 | # endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 53 | volatile immap_t *immap = (immap_t *) (immr & 0xFFFF0000); |
| 54 | uint k, m; |
| 55 | char buf[32]; |
| 56 | char pre = 'X'; |
| 57 | char *mid = "xx"; |
| 58 | char *suf; |
| 59 | |
| 60 | /* the highest 16 bits should be 0x0050 for a 860 */ |
| 61 | |
| 62 | if ((pvr >> 16) != 0x0050) |
| 63 | return -1; |
| 64 | |
Scott Wood | 8a88e9f | 2013-05-17 20:01:54 -0500 | [diff] [blame] | 65 | k = (immr << 16) | |
| 66 | immap->im_cpm.cp_dparam16[PROFF_REVNUM / sizeof(u16)]; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 67 | m = 0; |
Wolfgang Denk | cf0cdd0 | 2006-03-18 23:31:12 +0100 | [diff] [blame] | 68 | suf = ""; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 69 | |
wdenk | ad276f2 | 2004-01-04 16:28:35 +0000 | [diff] [blame] | 70 | /* |
| 71 | * Some boards use sockets so different CPUs can be used. |
| 72 | * We have to check chip version in run time. |
| 73 | */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 74 | switch (k) { |
Wolfgang Denk | cf0cdd0 | 2006-03-18 23:31:12 +0100 | [diff] [blame] | 75 | case 0x00020001: pre = 'P'; break; |
| 76 | case 0x00030001: break; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 77 | case 0x00120003: suf = "A"; break; |
| 78 | case 0x00130003: suf = "A3"; break; |
| 79 | |
| 80 | case 0x00200004: suf = "B"; break; |
| 81 | |
| 82 | case 0x00300004: suf = "C"; break; |
wdenk | 2bb1105 | 2003-07-17 23:16:40 +0000 | [diff] [blame] | 83 | case 0x00310004: suf = "C1"; m = 1; break; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 84 | |
| 85 | case 0x00200064: mid = "SR"; suf = "B"; break; |
| 86 | case 0x00300065: mid = "SR"; suf = "C"; break; |
| 87 | case 0x00310065: mid = "SR"; suf = "C1"; m = 1; break; |
| 88 | case 0x05010000: suf = "D3"; m = 1; break; |
| 89 | case 0x05020000: suf = "D4"; m = 1; break; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 90 | /* this value is not documented anywhere */ |
| 91 | case 0x40000000: pre = 'P'; suf = "D"; m = 1; break; |
wdenk | ad276f2 | 2004-01-04 16:28:35 +0000 | [diff] [blame] | 92 | /* MPC866P/MPC866T/MPC859T/MPC859DSL/MPC852T */ |
Wolfgang Denk | cf0cdd0 | 2006-03-18 23:31:12 +0100 | [diff] [blame] | 93 | case 0x08010004: /* Rev. A.0 */ |
| 94 | suf = "A"; |
| 95 | /* fall through */ |
| 96 | case 0x08000003: /* Rev. 0.3 */ |
| 97 | pre = 'M'; m = 1; |
wdenk | ad276f2 | 2004-01-04 16:28:35 +0000 | [diff] [blame] | 98 | if (id_str == NULL) |
| 99 | id_str = |
Masahiro Yamada | 8c970ec | 2014-06-20 13:54:55 +0900 | [diff] [blame] | 100 | # if defined(CONFIG_MPC859T) |
wdenk | ad276f2 | 2004-01-04 16:28:35 +0000 | [diff] [blame] | 101 | "PC859T"; |
wdenk | ad276f2 | 2004-01-04 16:28:35 +0000 | [diff] [blame] | 102 | # else |
| 103 | "PC866x"; /* Unknown chip from MPC866 family */ |
| 104 | # endif |
| 105 | break; |
| 106 | case 0x09000000: pre = 'M'; mid = suf = ""; m = 1; |
| 107 | if (id_str == NULL) |
| 108 | id_str = "PC885"; /* 870/875/880/885 */ |
| 109 | break; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 110 | |
| 111 | default: suf = NULL; break; |
| 112 | } |
| 113 | |
wdenk | ad276f2 | 2004-01-04 16:28:35 +0000 | [diff] [blame] | 114 | if (id_str == NULL) |
| 115 | id_str = "PC86x"; /* Unknown 86x chip */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 116 | if (suf) |
wdenk | ad276f2 | 2004-01-04 16:28:35 +0000 | [diff] [blame] | 117 | printf ("%c%s%sZPnn%s", pre, id_str, mid, suf); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 118 | else |
wdenk | ad276f2 | 2004-01-04 16:28:35 +0000 | [diff] [blame] | 119 | printf ("unknown M%s (0x%08x)", id_str, k); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 120 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 121 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 122 | #if defined(CONFIG_SYS_8xx_CPUCLK_MIN) && defined(CONFIG_SYS_8xx_CPUCLK_MAX) |
wdenk | fde3704 | 2004-01-31 20:06:54 +0000 | [diff] [blame] | 123 | printf (" at %s MHz [%d.%d...%d.%d MHz]\n ", |
| 124 | strmhz (buf, clock), |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 125 | CONFIG_SYS_8xx_CPUCLK_MIN / 1000000, |
| 126 | ((CONFIG_SYS_8xx_CPUCLK_MIN % 1000000) + 50000) / 100000, |
| 127 | CONFIG_SYS_8xx_CPUCLK_MAX / 1000000, |
| 128 | ((CONFIG_SYS_8xx_CPUCLK_MAX % 1000000) + 50000) / 100000 |
wdenk | fde3704 | 2004-01-31 20:06:54 +0000 | [diff] [blame] | 129 | ); |
| 130 | #else |
| 131 | printf (" at %s MHz: ", strmhz (buf, clock)); |
| 132 | #endif |
Shruti Kanetkar | 3adfb91 | 2013-08-15 11:25:37 -0500 | [diff] [blame] | 133 | print_size(checkicache(), " I-Cache "); |
| 134 | print_size(checkdcache(), " D-Cache"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 135 | |
wdenk | 20bddb3 | 2004-09-28 17:59:53 +0000 | [diff] [blame] | 136 | /* do we have a FEC (860T/P or 852/859/866/885)? */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 137 | |
| 138 | immap->im_cpm.cp_fec.fec_addr_low = 0x12345678; |
| 139 | if (immap->im_cpm.cp_fec.fec_addr_low == 0x12345678) { |
| 140 | printf (" FEC present"); |
| 141 | } |
| 142 | |
| 143 | if (!m) { |
| 144 | puts (cpu_warning); |
| 145 | } |
| 146 | |
| 147 | putc ('\n'); |
| 148 | |
wdenk | 2bb1105 | 2003-07-17 23:16:40 +0000 | [diff] [blame] | 149 | #ifdef DEBUG |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 150 | if(clock != measure_gclk()) { |
| 151 | printf ("clock %ldHz != %dHz\n", clock, measure_gclk()); |
| 152 | } |
wdenk | 2bb1105 | 2003-07-17 23:16:40 +0000 | [diff] [blame] | 153 | #endif |
| 154 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | #elif defined(CONFIG_MPC862) |
| 159 | |
| 160 | static int check_CPU (long clock, uint pvr, uint immr) |
| 161 | { |
| 162 | volatile immap_t *immap = (immap_t *) (immr & 0xFFFF0000); |
| 163 | uint k, m; |
| 164 | char buf[32]; |
| 165 | char pre = 'X'; |
Wolfgang Denk | 89f85ad | 2011-11-04 15:55:32 +0000 | [diff] [blame] | 166 | __maybe_unused char *mid = "xx"; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 167 | char *suf; |
| 168 | |
| 169 | /* the highest 16 bits should be 0x0050 for a 8xx */ |
| 170 | |
| 171 | if ((pvr >> 16) != 0x0050) |
| 172 | return -1; |
| 173 | |
Scott Wood | 8a88e9f | 2013-05-17 20:01:54 -0500 | [diff] [blame] | 174 | k = (immr << 16) | |
| 175 | immap->im_cpm.cp_dparam16[PROFF_REVNUM / sizeof(u16)]; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 176 | m = 0; |
| 177 | |
| 178 | switch (k) { |
| 179 | |
| 180 | /* this value is not documented anywhere */ |
| 181 | case 0x06000000: mid = "P"; suf = "0"; break; |
| 182 | case 0x06010001: mid = "P"; suf = "A"; m = 1; break; |
| 183 | case 0x07000003: mid = "P"; suf = "B"; m = 1; break; |
| 184 | default: suf = NULL; break; |
| 185 | } |
| 186 | |
wdenk | 5124278 | 2004-12-18 22:35:43 +0000 | [diff] [blame] | 187 | #ifndef CONFIG_MPC857 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 188 | if (suf) |
| 189 | printf ("%cPC862%sZPnn%s", pre, mid, suf); |
| 190 | else |
| 191 | printf ("unknown MPC862 (0x%08x)", k); |
wdenk | 5124278 | 2004-12-18 22:35:43 +0000 | [diff] [blame] | 192 | #else |
| 193 | if (suf) |
| 194 | printf ("%cPC857TZPnn%s", pre, suf); /* only 857T tested right now! */ |
| 195 | else |
| 196 | printf ("unknown MPC857 (0x%08x)", k); |
| 197 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 198 | |
Shruti Kanetkar | 8115936 | 2013-08-15 11:25:38 -0500 | [diff] [blame] | 199 | printf(" at %s MHz: ", strmhz(buf, clock)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 200 | |
Shruti Kanetkar | 3adfb91 | 2013-08-15 11:25:37 -0500 | [diff] [blame] | 201 | print_size(checkicache(), " I-Cache "); |
| 202 | print_size(checkdcache(), " D-Cache"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 203 | |
| 204 | /* lets check and see if we're running on a 862T (or P?) */ |
| 205 | |
| 206 | immap->im_cpm.cp_fec.fec_addr_low = 0x12345678; |
| 207 | if (immap->im_cpm.cp_fec.fec_addr_low == 0x12345678) { |
| 208 | printf (" FEC present"); |
| 209 | } |
| 210 | |
| 211 | if (!m) { |
| 212 | puts (cpu_warning); |
| 213 | } |
| 214 | |
| 215 | putc ('\n'); |
| 216 | |
| 217 | return 0; |
| 218 | } |
| 219 | |
| 220 | #elif defined(CONFIG_MPC823) |
| 221 | |
| 222 | static int check_CPU (long clock, uint pvr, uint immr) |
| 223 | { |
| 224 | volatile immap_t *immap = (immap_t *) (immr & 0xFFFF0000); |
| 225 | uint k, m; |
| 226 | char buf[32]; |
| 227 | char *suf; |
| 228 | |
| 229 | /* the highest 16 bits should be 0x0050 for a 8xx */ |
| 230 | |
| 231 | if ((pvr >> 16) != 0x0050) |
| 232 | return -1; |
| 233 | |
Scott Wood | 8a88e9f | 2013-05-17 20:01:54 -0500 | [diff] [blame] | 234 | k = (immr << 16) | |
| 235 | in_be16(&immap->im_cpm.cp_dparam16[PROFF_REVNUM / sizeof(u16)]); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 236 | m = 0; |
| 237 | |
| 238 | switch (k) { |
| 239 | /* MPC823 */ |
| 240 | case 0x20000000: suf = "0"; break; |
| 241 | case 0x20010000: suf = "0.1"; break; |
| 242 | case 0x20020000: suf = "Z2/3"; break; |
| 243 | case 0x20020001: suf = "Z3"; break; |
| 244 | case 0x21000000: suf = "A"; break; |
| 245 | case 0x21010000: suf = "B"; m = 1; break; |
| 246 | case 0x21010001: suf = "B2"; m = 1; break; |
| 247 | /* MPC823E */ |
| 248 | case 0x24010000: suf = NULL; |
| 249 | puts ("PPC823EZTnnB2"); |
| 250 | m = 1; |
| 251 | break; |
| 252 | default: |
| 253 | suf = NULL; |
| 254 | printf ("unknown MPC823 (0x%08x)", k); |
| 255 | break; |
| 256 | } |
| 257 | if (suf) |
| 258 | printf ("PPC823ZTnn%s", suf); |
| 259 | |
Shruti Kanetkar | 8115936 | 2013-08-15 11:25:38 -0500 | [diff] [blame] | 260 | printf(" at %s MHz: ", strmhz(buf, clock)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 261 | |
Shruti Kanetkar | 3adfb91 | 2013-08-15 11:25:37 -0500 | [diff] [blame] | 262 | print_size(checkicache(), " I-Cache "); |
| 263 | print_size(checkdcache(), " D-Cache"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 264 | |
| 265 | /* lets check and see if we're running on a 860T (or P?) */ |
| 266 | |
| 267 | immap->im_cpm.cp_fec.fec_addr_low = 0x12345678; |
| 268 | if (immap->im_cpm.cp_fec.fec_addr_low == 0x12345678) { |
| 269 | puts (" FEC present"); |
| 270 | } |
| 271 | |
| 272 | if (!m) { |
| 273 | puts (cpu_warning); |
| 274 | } |
| 275 | |
| 276 | putc ('\n'); |
| 277 | |
| 278 | return 0; |
| 279 | } |
| 280 | |
| 281 | #elif defined(CONFIG_MPC850) |
| 282 | |
| 283 | static int check_CPU (long clock, uint pvr, uint immr) |
| 284 | { |
| 285 | volatile immap_t *immap = (immap_t *) (immr & 0xFFFF0000); |
| 286 | uint k, m; |
| 287 | char buf[32]; |
| 288 | |
| 289 | /* the highest 16 bits should be 0x0050 for a 8xx */ |
| 290 | |
| 291 | if ((pvr >> 16) != 0x0050) |
| 292 | return -1; |
| 293 | |
Scott Wood | 8a88e9f | 2013-05-17 20:01:54 -0500 | [diff] [blame] | 294 | k = (immr << 16) | |
| 295 | immap->im_cpm.cp_dparam16[PROFF_REVNUM / sizeof(u16)]; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 296 | m = 0; |
| 297 | |
| 298 | switch (k) { |
| 299 | case 0x20020001: |
| 300 | printf ("XPC850xxZT"); |
| 301 | break; |
| 302 | case 0x21000065: |
| 303 | printf ("XPC850xxZTA"); |
| 304 | break; |
| 305 | case 0x21010067: |
| 306 | printf ("XPC850xxZTB"); |
| 307 | m = 1; |
| 308 | break; |
| 309 | case 0x21020068: |
| 310 | printf ("XPC850xxZTC"); |
| 311 | m = 1; |
| 312 | break; |
| 313 | default: |
| 314 | printf ("unknown MPC850 (0x%08x)", k); |
| 315 | } |
Shruti Kanetkar | 8115936 | 2013-08-15 11:25:38 -0500 | [diff] [blame] | 316 | printf(" at %s MHz: ", strmhz(buf, clock)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 317 | |
Shruti Kanetkar | 3adfb91 | 2013-08-15 11:25:37 -0500 | [diff] [blame] | 318 | print_size(checkicache(), " I-Cache "); |
| 319 | print_size(checkdcache(), " D-Cache"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 320 | |
| 321 | /* lets check and see if we're running on a 850T (or P?) */ |
| 322 | |
| 323 | immap->im_cpm.cp_fec.fec_addr_low = 0x12345678; |
| 324 | if (immap->im_cpm.cp_fec.fec_addr_low == 0x12345678) { |
| 325 | printf (" FEC present"); |
| 326 | } |
| 327 | |
| 328 | if (!m) { |
| 329 | puts (cpu_warning); |
| 330 | } |
| 331 | |
| 332 | putc ('\n'); |
| 333 | |
| 334 | return 0; |
| 335 | } |
| 336 | #else |
| 337 | #error CPU undefined |
| 338 | #endif |
| 339 | /* ------------------------------------------------------------------------- */ |
| 340 | |
| 341 | int checkcpu (void) |
| 342 | { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 343 | ulong clock = gd->cpu_clk; |
| 344 | uint immr = get_immr (0); /* Return full IMMR contents */ |
| 345 | uint pvr = get_pvr (); |
| 346 | |
| 347 | puts ("CPU: "); |
| 348 | |
| 349 | /* 850 has PARTNUM 20 */ |
| 350 | /* 801 has PARTNUM 10 */ |
| 351 | return check_CPU (clock, pvr, immr); |
| 352 | } |
| 353 | |
| 354 | /* ------------------------------------------------------------------------- */ |
| 355 | /* L1 i-cache */ |
| 356 | /* the standard 860 has 128 sets of 16 bytes in 2 ways (= 4 kB) */ |
| 357 | /* the 860 P (plus) has 256 sets of 16 bytes in 4 ways (= 16 kB) */ |
| 358 | |
| 359 | int checkicache (void) |
| 360 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 361 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 362 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
| 363 | u32 cacheon = rd_ic_cst () & IDC_ENABLED; |
| 364 | |
wdenk | 2bb1105 | 2003-07-17 23:16:40 +0000 | [diff] [blame] | 365 | #ifdef CONFIG_IP86x |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 366 | u32 k = memctl->memc_br1 & ~0x00007fff; /* probe in flash memoryarea */ |
| 367 | #else |
| 368 | u32 k = memctl->memc_br0 & ~0x00007fff; /* probe in flash memoryarea */ |
| 369 | #endif |
| 370 | u32 m; |
| 371 | u32 lines = -1; |
| 372 | |
| 373 | wr_ic_cst (IDC_UNALL); |
| 374 | wr_ic_cst (IDC_INVALL); |
| 375 | wr_ic_cst (IDC_DISABLE); |
| 376 | __asm__ volatile ("isync"); |
| 377 | |
| 378 | while (!((m = rd_ic_cst ()) & IDC_CERR2)) { |
| 379 | wr_ic_adr (k); |
| 380 | wr_ic_cst (IDC_LDLCK); |
| 381 | __asm__ volatile ("isync"); |
| 382 | |
| 383 | lines++; |
| 384 | k += 0x10; /* the number of bytes in a cacheline */ |
| 385 | } |
| 386 | |
| 387 | wr_ic_cst (IDC_UNALL); |
| 388 | wr_ic_cst (IDC_INVALL); |
| 389 | |
| 390 | if (cacheon) |
| 391 | wr_ic_cst (IDC_ENABLE); |
| 392 | else |
| 393 | wr_ic_cst (IDC_DISABLE); |
| 394 | |
| 395 | __asm__ volatile ("isync"); |
| 396 | |
| 397 | return lines << 4; |
| 398 | }; |
| 399 | |
| 400 | /* ------------------------------------------------------------------------- */ |
| 401 | /* L1 d-cache */ |
| 402 | /* the standard 860 has 128 sets of 16 bytes in 2 ways (= 4 kB) */ |
| 403 | /* the 860 P (plus) has 256 sets of 16 bytes in 2 ways (= 8 kB) */ |
| 404 | /* call with cache disabled */ |
| 405 | |
| 406 | int checkdcache (void) |
| 407 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 408 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 409 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
| 410 | u32 cacheon = rd_dc_cst () & IDC_ENABLED; |
| 411 | |
wdenk | 2bb1105 | 2003-07-17 23:16:40 +0000 | [diff] [blame] | 412 | #ifdef CONFIG_IP86x |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 413 | u32 k = memctl->memc_br1 & ~0x00007fff; /* probe in flash memoryarea */ |
| 414 | #else |
| 415 | u32 k = memctl->memc_br0 & ~0x00007fff; /* probe in flash memoryarea */ |
| 416 | #endif |
| 417 | u32 m; |
| 418 | u32 lines = -1; |
| 419 | |
| 420 | wr_dc_cst (IDC_UNALL); |
| 421 | wr_dc_cst (IDC_INVALL); |
| 422 | wr_dc_cst (IDC_DISABLE); |
| 423 | |
| 424 | while (!((m = rd_dc_cst ()) & IDC_CERR2)) { |
| 425 | wr_dc_adr (k); |
| 426 | wr_dc_cst (IDC_LDLCK); |
| 427 | lines++; |
| 428 | k += 0x10; /* the number of bytes in a cacheline */ |
| 429 | } |
| 430 | |
| 431 | wr_dc_cst (IDC_UNALL); |
| 432 | wr_dc_cst (IDC_INVALL); |
| 433 | |
| 434 | if (cacheon) |
| 435 | wr_dc_cst (IDC_ENABLE); |
| 436 | else |
| 437 | wr_dc_cst (IDC_DISABLE); |
| 438 | |
| 439 | return lines << 4; |
| 440 | }; |
| 441 | |
| 442 | /* ------------------------------------------------------------------------- */ |
| 443 | |
| 444 | void upmconfig (uint upm, uint * table, uint size) |
| 445 | { |
| 446 | uint i; |
| 447 | uint addr = 0; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 448 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 449 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
| 450 | |
| 451 | for (i = 0; i < size; i++) { |
| 452 | memctl->memc_mdr = table[i]; /* (16-15) */ |
| 453 | memctl->memc_mcr = addr | upm; /* (16-16) */ |
| 454 | addr++; |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | /* ------------------------------------------------------------------------- */ |
| 459 | |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 460 | int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 461 | { |
| 462 | ulong msr, addr; |
| 463 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 464 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 465 | |
| 466 | immap->im_clkrst.car_plprcr |= PLPRCR_CSR; /* Checkstop Reset enable */ |
| 467 | |
| 468 | /* Interrupts and MMU off */ |
| 469 | __asm__ volatile ("mtspr 81, 0"); |
| 470 | __asm__ volatile ("mfmsr %0":"=r" (msr)); |
| 471 | |
| 472 | msr &= ~0x1030; |
| 473 | __asm__ volatile ("mtmsr %0"::"r" (msr)); |
| 474 | |
| 475 | /* |
| 476 | * Trying to execute the next instruction at a non-existing address |
| 477 | * should cause a machine check, resulting in reset |
| 478 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 479 | #ifdef CONFIG_SYS_RESET_ADDRESS |
| 480 | addr = CONFIG_SYS_RESET_ADDRESS; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 481 | #else |
| 482 | /* |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 483 | * note: when CONFIG_SYS_MONITOR_BASE points to a RAM address, CONFIG_SYS_MONITOR_BASE |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 484 | * - sizeof (ulong) is usually a valid address. Better pick an address |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 485 | * known to be invalid on your system and assign it to CONFIG_SYS_RESET_ADDRESS. |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 486 | * "(ulong)-1" used to be a good choice for many systems... |
| 487 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 488 | addr = CONFIG_SYS_MONITOR_BASE - sizeof (ulong); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 489 | #endif |
| 490 | ((void (*)(void)) addr) (); |
| 491 | return 1; |
| 492 | } |
| 493 | |
| 494 | /* ------------------------------------------------------------------------- */ |
| 495 | |
| 496 | /* |
| 497 | * Get timebase clock frequency (like cpu_clk in Hz) |
| 498 | * |
wdenk | ad276f2 | 2004-01-04 16:28:35 +0000 | [diff] [blame] | 499 | * See sections 14.2 and 14.6 of the User's Manual |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 500 | */ |
| 501 | unsigned long get_tbclk (void) |
| 502 | { |
wdenk | ad276f2 | 2004-01-04 16:28:35 +0000 | [diff] [blame] | 503 | uint immr = get_immr (0); /* Return full IMMR contents */ |
| 504 | volatile immap_t *immap = (volatile immap_t *)(immr & 0xFFFF0000); |
| 505 | ulong oscclk, factor, pll; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 506 | |
wdenk | ad276f2 | 2004-01-04 16:28:35 +0000 | [diff] [blame] | 507 | if (immap->im_clkrst.car_sccr & SCCR_TBS) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 508 | return (gd->cpu_clk / 16); |
| 509 | } |
| 510 | |
wdenk | ad276f2 | 2004-01-04 16:28:35 +0000 | [diff] [blame] | 511 | pll = immap->im_clkrst.car_plprcr; |
| 512 | |
| 513 | #define PLPRCR_val(a) ((pll & PLPRCR_ ## a ## _MSK) >> PLPRCR_ ## a ## _SHIFT) |
| 514 | |
| 515 | /* |
| 516 | * For newer PQ1 chips (MPC866/87x/88x families), PLL multiplication |
| 517 | * factor is calculated as follows: |
| 518 | * |
| 519 | * MFN |
| 520 | * MFI + ------- |
| 521 | * MFD + 1 |
| 522 | * factor = ----------------- |
| 523 | * (PDF + 1) * 2^S |
| 524 | * |
| 525 | * For older chips, it's just MF field of PLPRCR plus one. |
| 526 | */ |
wdenk | 2b80ae5 | 2004-01-18 18:21:54 +0000 | [diff] [blame] | 527 | if ((immr & 0x0FFF) >= MPC8xx_NEW_CLK) { /* MPC866/87x/88x series */ |
wdenk | ad276f2 | 2004-01-04 16:28:35 +0000 | [diff] [blame] | 528 | factor = (PLPRCR_val(MFI) + PLPRCR_val(MFN)/(PLPRCR_val(MFD)+1))/ |
| 529 | (PLPRCR_val(PDF)+1) / (1<<PLPRCR_val(S)); |
| 530 | } else { |
| 531 | factor = PLPRCR_val(MF)+1; |
| 532 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 533 | |
| 534 | oscclk = gd->cpu_clk / factor; |
| 535 | |
wdenk | ad276f2 | 2004-01-04 16:28:35 +0000 | [diff] [blame] | 536 | if ((immap->im_clkrst.car_sccr & SCCR_RTSEL) == 0 || factor > 2) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 537 | return (oscclk / 4); |
| 538 | } |
| 539 | return (oscclk / 16); |
| 540 | } |
| 541 | |
| 542 | /* ------------------------------------------------------------------------- */ |
| 543 | |
| 544 | #if defined(CONFIG_WATCHDOG) |
| 545 | void watchdog_reset (void) |
| 546 | { |
| 547 | int re_enable = disable_interrupts (); |
| 548 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 549 | reset_8xx_watchdog ((immap_t *) CONFIG_SYS_IMMR); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 550 | if (re_enable) |
| 551 | enable_interrupts (); |
| 552 | } |
wdenk | eb8f2fb | 2005-05-09 10:17:32 +0000 | [diff] [blame] | 553 | #endif /* CONFIG_WATCHDOG */ |
| 554 | |
Masahiro Yamada | 0211cad | 2014-12-15 23:26:14 +0900 | [diff] [blame] | 555 | #if defined(CONFIG_WATCHDOG) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 556 | |
| 557 | void reset_8xx_watchdog (volatile immap_t * immr) |
| 558 | { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 559 | /* |
| 560 | * All other boards use the MPC8xx Internal Watchdog |
| 561 | */ |
| 562 | immr->im_siu_conf.sc_swsr = 0x556c; /* write magic1 */ |
| 563 | immr->im_siu_conf.sc_swsr = 0xaa39; /* write magic2 */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 564 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 565 | #endif /* CONFIG_WATCHDOG */ |
Ben Warren | 70618a3 | 2008-10-22 23:20:29 -0700 | [diff] [blame] | 566 | |
| 567 | /* |
| 568 | * Initializes on-chip ethernet controllers. |
| 569 | * to override, implement board_eth_init() |
| 570 | */ |
| 571 | int cpu_eth_init(bd_t *bis) |
| 572 | { |
Ben Warren | acd137b | 2008-12-09 23:34:15 -0800 | [diff] [blame] | 573 | #if defined(SCC_ENET) && defined(CONFIG_CMD_NET) |
Ben Warren | bbff280 | 2008-10-23 22:02:49 -0700 | [diff] [blame] | 574 | scc_initialize(bis); |
| 575 | #endif |
Ben Warren | 70618a3 | 2008-10-22 23:20:29 -0700 | [diff] [blame] | 576 | #if defined(FEC_ENET) |
| 577 | fec_initialize(bis); |
| 578 | #endif |
| 579 | return 0; |
| 580 | } |