cpu.c 13 KB

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