cpu.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. /*
  2. * (C) Copyright 2000-2002
  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. * m8xx.c
  25. *
  26. * CPU specific code
  27. *
  28. * written or collected and sometimes rewritten by
  29. * Magnus Damm <damm@bitsmart.com>
  30. *
  31. * minor modifications by
  32. * Wolfgang Denk <wd@denx.de>
  33. */
  34. #include <common.h>
  35. #include <watchdog.h>
  36. #include <command.h>
  37. #include <mpc8xx.h>
  38. #include <asm/cache.h>
  39. static char *cpu_warning = "\n " \
  40. "*** Warning: CPU Core has Silicon Bugs -- Check the Errata ***";
  41. #if ((defined(CONFIG_MPC860) || defined(CONFIG_MPC855)) && \
  42. !defined(CONFIG_MPC862))
  43. # ifdef CONFIG_MPC855
  44. # define ID_STR "PC855"
  45. # else
  46. # define ID_STR "PC860"
  47. # endif
  48. static int check_CPU (long clock, uint pvr, uint immr)
  49. {
  50. volatile immap_t *immap = (immap_t *) (immr & 0xFFFF0000);
  51. uint k, m;
  52. char buf[32];
  53. char pre = 'X';
  54. char *mid = "xx";
  55. char *suf;
  56. /* the highest 16 bits should be 0x0050 for a 860 */
  57. if ((pvr >> 16) != 0x0050)
  58. return -1;
  59. k = (immr << 16) | *((ushort *) & immap->im_cpm.cp_dparam[0xB0]);
  60. m = 0;
  61. switch (k) {
  62. case 0x00020001: pre = 'p'; suf = ""; break;
  63. case 0x00030001: suf = ""; break;
  64. case 0x00120003: suf = "A"; break;
  65. case 0x00130003: suf = "A3"; break;
  66. case 0x00200004: suf = "B"; break;
  67. case 0x00300004: suf = "C"; break;
  68. case 0x00310004: suf = "C1"; m = 1;
  69. break;
  70. case 0x00200064: mid = "SR"; suf = "B"; break;
  71. case 0x00300065: mid = "SR"; suf = "C"; break;
  72. case 0x00310065: mid = "SR"; suf = "C1"; m = 1; break;
  73. case 0x05010000: suf = "D3"; m = 1; break;
  74. case 0x05020000: suf = "D4"; m = 1; break;
  75. /* this value is not documented anywhere */
  76. case 0x40000000: pre = 'P'; suf = "D"; m = 1; break;
  77. default: suf = NULL; break;
  78. }
  79. if (suf)
  80. printf ("%c" ID_STR "%sZPnn%s", pre, mid, suf);
  81. else
  82. printf ("unknown M" ID_STR " (0x%08x)", k);
  83. printf (" at %s MHz:", strmhz (buf, clock));
  84. printf (" %u kB I-Cache", checkicache () >> 10);
  85. printf (" %u kB D-Cache", checkdcache () >> 10);
  86. /* lets check and see if we're running on a 860T (or P?) */
  87. immap->im_cpm.cp_fec.fec_addr_low = 0x12345678;
  88. if (immap->im_cpm.cp_fec.fec_addr_low == 0x12345678) {
  89. printf (" FEC present");
  90. }
  91. if (!m) {
  92. puts (cpu_warning);
  93. }
  94. putc ('\n');
  95. return 0;
  96. }
  97. #elif defined(CONFIG_MPC862)
  98. static int check_CPU (long clock, uint pvr, uint immr)
  99. {
  100. volatile immap_t *immap = (immap_t *) (immr & 0xFFFF0000);
  101. uint k, m;
  102. char buf[32];
  103. char pre = 'X';
  104. char *mid = "xx";
  105. char *suf;
  106. /* the highest 16 bits should be 0x0050 for a 8xx */
  107. if ((pvr >> 16) != 0x0050)
  108. return -1;
  109. k = (immr << 16) | *((ushort *) & immap->im_cpm.cp_dparam[0xB0]);
  110. m = 0;
  111. switch (k) {
  112. /* this value is not documented anywhere */
  113. case 0x06000000: mid = "P"; suf = "0"; break;
  114. case 0x06010001: mid = "P"; suf = "A"; m = 1; break;
  115. case 0x07000003: mid = "P"; suf = "B"; m = 1; break;
  116. default: suf = NULL; break;
  117. }
  118. if (suf)
  119. printf ("%cPC862%sZPnn%s", pre, mid, suf);
  120. else
  121. printf ("unknown MPC862 (0x%08x)", k);
  122. printf (" at %s MHz:", strmhz (buf, clock));
  123. printf (" %u kB I-Cache", checkicache () >> 10);
  124. printf (" %u kB D-Cache", checkdcache () >> 10);
  125. /* lets check and see if we're running on a 862T (or P?) */
  126. immap->im_cpm.cp_fec.fec_addr_low = 0x12345678;
  127. if (immap->im_cpm.cp_fec.fec_addr_low == 0x12345678) {
  128. printf (" FEC present");
  129. }
  130. if (!m) {
  131. puts (cpu_warning);
  132. }
  133. putc ('\n');
  134. return 0;
  135. }
  136. #elif defined(CONFIG_MPC823)
  137. static int check_CPU (long clock, uint pvr, uint immr)
  138. {
  139. volatile immap_t *immap = (immap_t *) (immr & 0xFFFF0000);
  140. uint k, m;
  141. char buf[32];
  142. char *suf;
  143. /* the highest 16 bits should be 0x0050 for a 8xx */
  144. if ((pvr >> 16) != 0x0050)
  145. return -1;
  146. k = (immr << 16) | *((ushort *) & immap->im_cpm.cp_dparam[0xB0]);
  147. m = 0;
  148. switch (k) {
  149. /* MPC823 */
  150. case 0x20000000: suf = "0"; break;
  151. case 0x20010000: suf = "0.1"; break;
  152. case 0x20020000: suf = "Z2/3"; break;
  153. case 0x20020001: suf = "Z3"; break;
  154. case 0x21000000: suf = "A"; break;
  155. case 0x21010000: suf = "B"; m = 1; break;
  156. case 0x21010001: suf = "B2"; m = 1; break;
  157. /* MPC823E */
  158. case 0x24010000: suf = NULL;
  159. puts ("PPC823EZTnnB2");
  160. m = 1;
  161. break;
  162. default:
  163. suf = NULL;
  164. printf ("unknown MPC823 (0x%08x)", k);
  165. break;
  166. }
  167. if (suf)
  168. printf ("PPC823ZTnn%s", suf);
  169. printf (" at %s MHz:", strmhz (buf, clock));
  170. printf (" %u kB I-Cache", checkicache () >> 10);
  171. printf (" %u kB D-Cache", checkdcache () >> 10);
  172. /* lets check and see if we're running on a 860T (or P?) */
  173. immap->im_cpm.cp_fec.fec_addr_low = 0x12345678;
  174. if (immap->im_cpm.cp_fec.fec_addr_low == 0x12345678) {
  175. puts (" FEC present");
  176. }
  177. if (!m) {
  178. puts (cpu_warning);
  179. }
  180. putc ('\n');
  181. return 0;
  182. }
  183. #elif defined(CONFIG_MPC850)
  184. static int check_CPU (long clock, uint pvr, uint immr)
  185. {
  186. volatile immap_t *immap = (immap_t *) (immr & 0xFFFF0000);
  187. uint k, m;
  188. char buf[32];
  189. /* the highest 16 bits should be 0x0050 for a 8xx */
  190. if ((pvr >> 16) != 0x0050)
  191. return -1;
  192. k = (immr << 16) | *((ushort *) & immap->im_cpm.cp_dparam[0xB0]);
  193. m = 0;
  194. switch (k) {
  195. case 0x20020001:
  196. printf ("XPC850xxZT");
  197. break;
  198. case 0x21000065:
  199. printf ("XPC850xxZTA");
  200. break;
  201. case 0x21010067:
  202. printf ("XPC850xxZTB");
  203. m = 1;
  204. break;
  205. case 0x21020068:
  206. printf ("XPC850xxZTC");
  207. m = 1;
  208. break;
  209. default:
  210. printf ("unknown MPC850 (0x%08x)", k);
  211. }
  212. printf (" at %s MHz:", strmhz (buf, clock));
  213. printf (" %u kB I-Cache", checkicache () >> 10);
  214. printf (" %u kB D-Cache", checkdcache () >> 10);
  215. /* lets check and see if we're running on a 850T (or P?) */
  216. immap->im_cpm.cp_fec.fec_addr_low = 0x12345678;
  217. if (immap->im_cpm.cp_fec.fec_addr_low == 0x12345678) {
  218. printf (" FEC present");
  219. }
  220. if (!m) {
  221. puts (cpu_warning);
  222. }
  223. putc ('\n');
  224. return 0;
  225. }
  226. #else
  227. #error CPU undefined
  228. #endif
  229. /* ------------------------------------------------------------------------- */
  230. int checkcpu (void)
  231. {
  232. DECLARE_GLOBAL_DATA_PTR;
  233. ulong clock = gd->cpu_clk;
  234. uint immr = get_immr (0); /* Return full IMMR contents */
  235. uint pvr = get_pvr ();
  236. puts ("CPU: ");
  237. /* 850 has PARTNUM 20 */
  238. /* 801 has PARTNUM 10 */
  239. return check_CPU (clock, pvr, immr);
  240. }
  241. /* ------------------------------------------------------------------------- */
  242. /* L1 i-cache */
  243. /* the standard 860 has 128 sets of 16 bytes in 2 ways (= 4 kB) */
  244. /* the 860 P (plus) has 256 sets of 16 bytes in 4 ways (= 16 kB) */
  245. int checkicache (void)
  246. {
  247. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  248. volatile memctl8xx_t *memctl = &immap->im_memctl;
  249. u32 cacheon = rd_ic_cst () & IDC_ENABLED;
  250. #ifdef CONFIG_IP860
  251. u32 k = memctl->memc_br1 & ~0x00007fff; /* probe in flash memoryarea */
  252. #else
  253. u32 k = memctl->memc_br0 & ~0x00007fff; /* probe in flash memoryarea */
  254. #endif
  255. u32 m;
  256. u32 lines = -1;
  257. wr_ic_cst (IDC_UNALL);
  258. wr_ic_cst (IDC_INVALL);
  259. wr_ic_cst (IDC_DISABLE);
  260. __asm__ volatile ("isync");
  261. while (!((m = rd_ic_cst ()) & IDC_CERR2)) {
  262. wr_ic_adr (k);
  263. wr_ic_cst (IDC_LDLCK);
  264. __asm__ volatile ("isync");
  265. lines++;
  266. k += 0x10; /* the number of bytes in a cacheline */
  267. }
  268. wr_ic_cst (IDC_UNALL);
  269. wr_ic_cst (IDC_INVALL);
  270. if (cacheon)
  271. wr_ic_cst (IDC_ENABLE);
  272. else
  273. wr_ic_cst (IDC_DISABLE);
  274. __asm__ volatile ("isync");
  275. return lines << 4;
  276. };
  277. /* ------------------------------------------------------------------------- */
  278. /* L1 d-cache */
  279. /* the standard 860 has 128 sets of 16 bytes in 2 ways (= 4 kB) */
  280. /* the 860 P (plus) has 256 sets of 16 bytes in 2 ways (= 8 kB) */
  281. /* call with cache disabled */
  282. int checkdcache (void)
  283. {
  284. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  285. volatile memctl8xx_t *memctl = &immap->im_memctl;
  286. u32 cacheon = rd_dc_cst () & IDC_ENABLED;
  287. #ifdef CONFIG_IP860
  288. u32 k = memctl->memc_br1 & ~0x00007fff; /* probe in flash memoryarea */
  289. #else
  290. u32 k = memctl->memc_br0 & ~0x00007fff; /* probe in flash memoryarea */
  291. #endif
  292. u32 m;
  293. u32 lines = -1;
  294. wr_dc_cst (IDC_UNALL);
  295. wr_dc_cst (IDC_INVALL);
  296. wr_dc_cst (IDC_DISABLE);
  297. while (!((m = rd_dc_cst ()) & IDC_CERR2)) {
  298. wr_dc_adr (k);
  299. wr_dc_cst (IDC_LDLCK);
  300. lines++;
  301. k += 0x10; /* the number of bytes in a cacheline */
  302. }
  303. wr_dc_cst (IDC_UNALL);
  304. wr_dc_cst (IDC_INVALL);
  305. if (cacheon)
  306. wr_dc_cst (IDC_ENABLE);
  307. else
  308. wr_dc_cst (IDC_DISABLE);
  309. return lines << 4;
  310. };
  311. /* ------------------------------------------------------------------------- */
  312. void upmconfig (uint upm, uint * table, uint size)
  313. {
  314. uint i;
  315. uint addr = 0;
  316. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  317. volatile memctl8xx_t *memctl = &immap->im_memctl;
  318. for (i = 0; i < size; i++) {
  319. memctl->memc_mdr = table[i]; /* (16-15) */
  320. memctl->memc_mcr = addr | upm; /* (16-16) */
  321. addr++;
  322. }
  323. }
  324. /* ------------------------------------------------------------------------- */
  325. int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  326. {
  327. ulong msr, addr;
  328. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  329. immap->im_clkrst.car_plprcr |= PLPRCR_CSR; /* Checkstop Reset enable */
  330. /* Interrupts and MMU off */
  331. __asm__ volatile ("mtspr 81, 0");
  332. __asm__ volatile ("mfmsr %0":"=r" (msr));
  333. msr &= ~0x1030;
  334. __asm__ volatile ("mtmsr %0"::"r" (msr));
  335. /*
  336. * Trying to execute the next instruction at a non-existing address
  337. * should cause a machine check, resulting in reset
  338. */
  339. #ifdef CFG_RESET_ADDRESS
  340. addr = CFG_RESET_ADDRESS;
  341. #else
  342. /*
  343. * note: when CFG_MONITOR_BASE points to a RAM address, CFG_MONITOR_BASE
  344. * - sizeof (ulong) is usually a valid address. Better pick an address
  345. * known to be invalid on your system and assign it to CFG_RESET_ADDRESS.
  346. * "(ulong)-1" used to be a good choice for many systems...
  347. */
  348. addr = CFG_MONITOR_BASE - sizeof (ulong);
  349. #endif
  350. ((void (*)(void)) addr) ();
  351. return 1;
  352. }
  353. /* ------------------------------------------------------------------------- */
  354. /*
  355. * Get timebase clock frequency (like cpu_clk in Hz)
  356. *
  357. * See table 15-5 pp. 15-16, and SCCR[RTSEL] pp. 15-27.
  358. */
  359. unsigned long get_tbclk (void)
  360. {
  361. DECLARE_GLOBAL_DATA_PTR;
  362. volatile immap_t *immr = (volatile immap_t *) CFG_IMMR;
  363. ulong oscclk, factor;
  364. if (immr->im_clkrst.car_sccr & SCCR_TBS) {
  365. return (gd->cpu_clk / 16);
  366. }
  367. factor = (((CFG_PLPRCR) & PLPRCR_MF_MSK) >> PLPRCR_MF_SHIFT) + 1;
  368. oscclk = gd->cpu_clk / factor;
  369. if ((immr->im_clkrst.car_sccr & SCCR_RTSEL) == 0 || factor > 2) {
  370. return (oscclk / 4);
  371. }
  372. return (oscclk / 16);
  373. }
  374. /* ------------------------------------------------------------------------- */
  375. #if defined(CONFIG_WATCHDOG)
  376. void watchdog_reset (void)
  377. {
  378. int re_enable = disable_interrupts ();
  379. reset_8xx_watchdog ((immap_t *) CFG_IMMR);
  380. if (re_enable)
  381. enable_interrupts ();
  382. }
  383. void reset_8xx_watchdog (volatile immap_t * immr)
  384. {
  385. # if defined(CONFIG_LWMON)
  386. /*
  387. * The LWMON board uses a MAX6301 Watchdog
  388. * with the trigger pin connected to port PA.7
  389. *
  390. * (The old board version used a MAX706TESA Watchdog, which
  391. * had to be handled exactly the same.)
  392. */
  393. # define WATCHDOG_BIT 0x0100
  394. immr->im_ioport.iop_papar &= ~(WATCHDOG_BIT); /* GPIO */
  395. immr->im_ioport.iop_padir |= WATCHDOG_BIT; /* Output */
  396. immr->im_ioport.iop_paodr &= ~(WATCHDOG_BIT); /* active output */
  397. immr->im_ioport.iop_padat ^= WATCHDOG_BIT; /* Toggle WDI */
  398. # else
  399. /*
  400. * All other boards use the MPC8xx Internal Watchdog
  401. */
  402. immr->im_siu_conf.sc_swsr = 0x556c; /* write magic1 */
  403. immr->im_siu_conf.sc_swsr = 0xaa39; /* write magic2 */
  404. # endif /* CONFIG_LWMON */
  405. }
  406. #endif /* CONFIG_WATCHDOG */
  407. /* ------------------------------------------------------------------------- */