cpu.c 13 KB

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