cpu.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. /*
  2. * (C) Copyright 2000-2007
  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. * CPU specific code
  25. *
  26. * written or collected and sometimes rewritten by
  27. * Magnus Damm <damm@bitsmart.com>
  28. *
  29. * minor modifications by
  30. * Wolfgang Denk <wd@denx.de>
  31. */
  32. #include <common.h>
  33. #include <watchdog.h>
  34. #include <command.h>
  35. #include <asm/cache.h>
  36. #include <ppc4xx.h>
  37. DECLARE_GLOBAL_DATA_PTR;
  38. void board_reset(void);
  39. #if defined(CONFIG_405GP) || \
  40. defined(CONFIG_440EP) || defined(CONFIG_440GR) || \
  41. defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
  42. #define PCI_ASYNC
  43. static int pci_async_enabled(void)
  44. {
  45. #if defined(CONFIG_405GP)
  46. return (mfdcr(strap) & PSR_PCI_ASYNC_EN);
  47. #endif
  48. #if defined(CONFIG_440EP) || defined(CONFIG_440GR) || \
  49. defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
  50. defined(CONFIG_460EX) || defined(CONFIG_460GT)
  51. unsigned long val;
  52. mfsdr(sdr_sdstp1, val);
  53. return (val & SDR0_SDSTP1_PAME_MASK);
  54. #endif
  55. }
  56. #endif
  57. #if defined(CONFIG_PCI) && !defined(CONFIG_IOP480) && \
  58. !defined(CONFIG_405) && !defined(CONFIG_405EX)
  59. static int pci_arbiter_enabled(void)
  60. {
  61. #if defined(CONFIG_405GP)
  62. return (mfdcr(strap) & PSR_PCI_ARBIT_EN);
  63. #endif
  64. #if defined(CONFIG_405EP)
  65. return (mfdcr(cpc0_pci) & CPC0_PCI_ARBIT_EN);
  66. #endif
  67. #if defined(CONFIG_440GP)
  68. return (mfdcr(cpc0_strp1) & CPC0_STRP1_PAE_MASK);
  69. #endif
  70. #if defined(CONFIG_440GX) || defined(CONFIG_440SP) || defined(CONFIG_440SPE)
  71. unsigned long val;
  72. mfsdr(sdr_xcr, val);
  73. return (val & 0x80000000);
  74. #endif
  75. #if defined(CONFIG_440EP) || defined(CONFIG_440GR) || \
  76. defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
  77. defined(CONFIG_460EX) || defined(CONFIG_460GT)
  78. unsigned long val;
  79. mfsdr(sdr_pci0, val);
  80. return (val & 0x80000000);
  81. #endif
  82. }
  83. #endif
  84. #if defined(CONFIG_405EP)
  85. #define I2C_BOOTROM
  86. static int i2c_bootrom_enabled(void)
  87. {
  88. #if defined(CONFIG_405EP)
  89. return (mfdcr(cpc0_boot) & CPC0_BOOT_SEP);
  90. #else
  91. unsigned long val;
  92. mfsdr(sdr_sdcs, val);
  93. return (val & SDR0_SDCS_SDD);
  94. #endif
  95. }
  96. #endif
  97. #if defined(CONFIG_440GX)
  98. #define SDR0_PINSTP_SHIFT 29
  99. static char *bootstrap_str[] = {
  100. "EBC (16 bits)",
  101. "EBC (8 bits)",
  102. "EBC (32 bits)",
  103. "EBC (8 bits)",
  104. "PCI",
  105. "I2C (Addr 0x54)",
  106. "Reserved",
  107. "I2C (Addr 0x50)",
  108. };
  109. static char bootstrap_char[] = { 'A', 'B', 'C', 'B', 'D', 'E', 'x', 'F' };
  110. #endif
  111. #if defined(CONFIG_440SP) || defined(CONFIG_440SPE)
  112. #define SDR0_PINSTP_SHIFT 30
  113. static char *bootstrap_str[] = {
  114. "EBC (8 bits)",
  115. "PCI",
  116. "I2C (Addr 0x54)",
  117. "I2C (Addr 0x50)",
  118. };
  119. static char bootstrap_char[] = { 'A', 'B', 'C', 'D'};
  120. #endif
  121. #if defined(CONFIG_440EP) || defined(CONFIG_440GR)
  122. #define SDR0_PINSTP_SHIFT 29
  123. static char *bootstrap_str[] = {
  124. "EBC (8 bits)",
  125. "PCI",
  126. "NAND (8 bits)",
  127. "EBC (16 bits)",
  128. "EBC (16 bits)",
  129. "I2C (Addr 0x54)",
  130. "PCI",
  131. "I2C (Addr 0x52)",
  132. };
  133. static char bootstrap_char[] = { 'A', 'B', 'C', 'D', 'E', 'G', 'F', 'H' };
  134. #endif
  135. #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
  136. #define SDR0_PINSTP_SHIFT 29
  137. static char *bootstrap_str[] = {
  138. "EBC (8 bits)",
  139. "EBC (16 bits)",
  140. "EBC (16 bits)",
  141. "NAND (8 bits)",
  142. "PCI",
  143. "I2C (Addr 0x54)",
  144. "PCI",
  145. "I2C (Addr 0x52)",
  146. };
  147. static char bootstrap_char[] = { 'A', 'B', 'C', 'D', 'E', 'G', 'F', 'H' };
  148. #endif
  149. #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
  150. #define SDR0_PINSTP_SHIFT 29
  151. static char *bootstrap_str[] = {
  152. "EBC (8 bits)",
  153. "EBC (16 bits)",
  154. "PCI",
  155. "PCI",
  156. "EBC (16 bits)",
  157. "NAND (8 bits)",
  158. "I2C (Addr 0x54)", /* A8 */
  159. "I2C (Addr 0x52)", /* A4 */
  160. };
  161. static char bootstrap_char[] = { 'A', 'B', 'C', 'D', 'E', 'G', 'F', 'H' };
  162. #endif
  163. #if defined(CONFIG_405EZ)
  164. #define SDR0_PINSTP_SHIFT 28
  165. static char *bootstrap_str[] = {
  166. "EBC (8 bits)",
  167. "SPI (fast)",
  168. "NAND (512 page, 4 addr cycle)",
  169. "I2C (Addr 0x50)",
  170. "EBC (32 bits)",
  171. "I2C (Addr 0x50)",
  172. "NAND (2K page, 5 addr cycle)",
  173. "I2C (Addr 0x50)",
  174. "EBC (16 bits)",
  175. "Reserved",
  176. "NAND (2K page, 4 addr cycle)",
  177. "I2C (Addr 0x50)",
  178. "NAND (512 page, 3 addr cycle)",
  179. "I2C (Addr 0x50)",
  180. "SPI (slow)",
  181. "I2C (Addr 0x50)",
  182. };
  183. static char bootstrap_char[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', \
  184. 'I', 'x', 'K', 'L', 'M', 'N', 'O', 'P' };
  185. #endif
  186. #if defined(CONFIG_405EX)
  187. #define SDR0_PINSTP_SHIFT 29
  188. static char *bootstrap_str[] = {
  189. "EBC (8 bits)",
  190. "EBC (16 bits)",
  191. "EBC (16 bits)",
  192. "NAND (8 bits)",
  193. "NAND (8 bits)",
  194. "I2C (Addr 0x54)",
  195. "EBC (8 bits)",
  196. "I2C (Addr 0x52)",
  197. };
  198. static char bootstrap_char[] = { 'A', 'B', 'C', 'D', 'E', 'G', 'F', 'H' };
  199. #endif
  200. #if defined(SDR0_PINSTP_SHIFT)
  201. static int bootstrap_option(void)
  202. {
  203. unsigned long val;
  204. mfsdr(SDR_PINSTP, val);
  205. return ((val & 0xf0000000) >> SDR0_PINSTP_SHIFT);
  206. }
  207. #endif /* SDR0_PINSTP_SHIFT */
  208. #if defined(CONFIG_440)
  209. static int do_chip_reset (unsigned long sys0, unsigned long sys1)
  210. {
  211. /* Changes to cpc0_sys0 and cpc0_sys1 require chip
  212. * reset.
  213. */
  214. mtdcr (cntrl0, mfdcr (cntrl0) | 0x80000000); /* Set SWE */
  215. mtdcr (cpc0_sys0, sys0);
  216. mtdcr (cpc0_sys1, sys1);
  217. mtdcr (cntrl0, mfdcr (cntrl0) & ~0x80000000); /* Clr SWE */
  218. mtspr (dbcr0, 0x20000000); /* Reset the chip */
  219. return 1;
  220. }
  221. #endif
  222. int checkcpu (void)
  223. {
  224. #if !defined(CONFIG_405) /* not used on Xilinx 405 FPGA implementations */
  225. uint pvr = get_pvr();
  226. ulong clock = gd->cpu_clk;
  227. char buf[32];
  228. #if !defined(CONFIG_IOP480)
  229. char addstr[64] = "";
  230. sys_info_t sys_info;
  231. puts ("CPU: ");
  232. get_sys_info(&sys_info);
  233. puts("AMCC PowerPC 4");
  234. #if defined(CONFIG_405GP) || defined(CONFIG_405CR) || \
  235. defined(CONFIG_405EP) || defined(CONFIG_405EZ) || \
  236. defined(CONFIG_405EX)
  237. puts("05");
  238. #endif
  239. #if defined(CONFIG_440)
  240. #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
  241. puts("60");
  242. #else
  243. puts("40");
  244. #endif
  245. #endif
  246. switch (pvr) {
  247. case PVR_405GP_RB:
  248. puts("GP Rev. B");
  249. break;
  250. case PVR_405GP_RC:
  251. puts("GP Rev. C");
  252. break;
  253. case PVR_405GP_RD:
  254. puts("GP Rev. D");
  255. break;
  256. #ifdef CONFIG_405GP
  257. case PVR_405GP_RE: /* 405GP rev E and 405CR rev C have same PVR */
  258. puts("GP Rev. E");
  259. break;
  260. #endif
  261. case PVR_405CR_RA:
  262. puts("CR Rev. A");
  263. break;
  264. case PVR_405CR_RB:
  265. puts("CR Rev. B");
  266. break;
  267. #ifdef CONFIG_405CR
  268. case PVR_405CR_RC: /* 405GP rev E and 405CR rev C have same PVR */
  269. puts("CR Rev. C");
  270. break;
  271. #endif
  272. case PVR_405GPR_RB:
  273. puts("GPr Rev. B");
  274. break;
  275. case PVR_405EP_RB:
  276. puts("EP Rev. B");
  277. break;
  278. case PVR_405EZ_RA:
  279. puts("EZ Rev. A");
  280. break;
  281. case PVR_405EX1_RA:
  282. puts("EX Rev. A");
  283. strcpy(addstr, "Security support");
  284. break;
  285. case PVR_405EX2_RA:
  286. puts("EX Rev. A");
  287. strcpy(addstr, "No Security support");
  288. break;
  289. case PVR_405EXR1_RA:
  290. puts("EXr Rev. A");
  291. strcpy(addstr, "Security support");
  292. break;
  293. case PVR_405EXR2_RA:
  294. puts("EXr Rev. A");
  295. strcpy(addstr, "No Security support");
  296. break;
  297. #if defined(CONFIG_440)
  298. case PVR_440GP_RB:
  299. puts("GP Rev. B");
  300. /* See errata 1.12: CHIP_4 */
  301. if ((mfdcr(cpc0_sys0) != mfdcr(cpc0_strp0)) ||
  302. (mfdcr(cpc0_sys1) != mfdcr(cpc0_strp1)) ){
  303. puts ( "\n\t CPC0_SYSx DCRs corrupted. "
  304. "Resetting chip ...\n");
  305. udelay( 1000 * 1000 ); /* Give time for serial buf to clear */
  306. do_chip_reset ( mfdcr(cpc0_strp0),
  307. mfdcr(cpc0_strp1) );
  308. }
  309. break;
  310. case PVR_440GP_RC:
  311. puts("GP Rev. C");
  312. break;
  313. case PVR_440GX_RA:
  314. puts("GX Rev. A");
  315. break;
  316. case PVR_440GX_RB:
  317. puts("GX Rev. B");
  318. break;
  319. case PVR_440GX_RC:
  320. puts("GX Rev. C");
  321. break;
  322. case PVR_440GX_RF:
  323. puts("GX Rev. F");
  324. break;
  325. case PVR_440EP_RA:
  326. puts("EP Rev. A");
  327. break;
  328. #ifdef CONFIG_440EP
  329. case PVR_440EP_RB: /* 440EP rev B and 440GR rev A have same PVR */
  330. puts("EP Rev. B");
  331. break;
  332. case PVR_440EP_RC: /* 440EP rev C and 440GR rev B have same PVR */
  333. puts("EP Rev. C");
  334. break;
  335. #endif /* CONFIG_440EP */
  336. #ifdef CONFIG_440GR
  337. case PVR_440GR_RA: /* 440EP rev B and 440GR rev A have same PVR */
  338. puts("GR Rev. A");
  339. break;
  340. case PVR_440GR_RB: /* 440EP rev C and 440GR rev B have same PVR */
  341. puts("GR Rev. B");
  342. break;
  343. #endif /* CONFIG_440GR */
  344. #endif /* CONFIG_440 */
  345. #ifdef CONFIG_440EPX
  346. case PVR_440EPX1_RA: /* 440EPx rev A and 440GRx rev A have same PVR */
  347. puts("EPx Rev. A");
  348. strcpy(addstr, "Security/Kasumi support");
  349. break;
  350. case PVR_440EPX2_RA: /* 440EPx rev A and 440GRx rev A have same PVR */
  351. puts("EPx Rev. A");
  352. strcpy(addstr, "No Security/Kasumi support");
  353. break;
  354. #endif /* CONFIG_440EPX */
  355. #ifdef CONFIG_440GRX
  356. case PVR_440GRX1_RA: /* 440EPx rev A and 440GRx rev A have same PVR */
  357. puts("GRx Rev. A");
  358. strcpy(addstr, "Security/Kasumi support");
  359. break;
  360. case PVR_440GRX2_RA: /* 440EPx rev A and 440GRx rev A have same PVR */
  361. puts("GRx Rev. A");
  362. strcpy(addstr, "No Security/Kasumi support");
  363. break;
  364. #endif /* CONFIG_440GRX */
  365. case PVR_440SP_6_RAB:
  366. puts("SP Rev. A/B");
  367. strcpy(addstr, "RAID 6 support");
  368. break;
  369. case PVR_440SP_RAB:
  370. puts("SP Rev. A/B");
  371. strcpy(addstr, "No RAID 6 support");
  372. break;
  373. case PVR_440SP_6_RC:
  374. puts("SP Rev. C");
  375. strcpy(addstr, "RAID 6 support");
  376. break;
  377. case PVR_440SP_RC:
  378. puts("SP Rev. C");
  379. strcpy(addstr, "No RAID 6 support");
  380. break;
  381. case PVR_440SPe_6_RA:
  382. puts("SPe Rev. A");
  383. strcpy(addstr, "RAID 6 support");
  384. break;
  385. case PVR_440SPe_RA:
  386. puts("SPe Rev. A");
  387. strcpy(addstr, "No RAID 6 support");
  388. break;
  389. case PVR_440SPe_6_RB:
  390. puts("SPe Rev. B");
  391. strcpy(addstr, "RAID 6 support");
  392. break;
  393. case PVR_440SPe_RB:
  394. puts("SPe Rev. B");
  395. strcpy(addstr, "No RAID 6 support");
  396. break;
  397. case PVR_460EX_RA:
  398. puts("EX Rev. A");
  399. strcpy(addstr, "No Security/Kasumi support");
  400. break;
  401. case PVR_460EX_SE_RA:
  402. puts("EX Rev. A");
  403. strcpy(addstr, "Security/Kasumi support");
  404. break;
  405. case PVR_460GT_RA:
  406. puts("GT Rev. A");
  407. strcpy(addstr, "No Security/Kasumi support");
  408. break;
  409. case PVR_460GT_SE_RA:
  410. puts("GT Rev. A");
  411. strcpy(addstr, "Security/Kasumi support");
  412. break;
  413. default:
  414. printf (" UNKNOWN (PVR=%08x)", pvr);
  415. break;
  416. }
  417. printf (" at %s MHz (PLB=%lu, OPB=%lu, EBC=%lu MHz)\n", strmhz(buf, clock),
  418. sys_info.freqPLB / 1000000,
  419. get_OPB_freq() / 1000000,
  420. sys_info.freqEBC / 1000000);
  421. if (addstr[0] != 0)
  422. printf(" %s\n", addstr);
  423. #if defined(I2C_BOOTROM)
  424. printf (" I2C boot EEPROM %sabled\n", i2c_bootrom_enabled() ? "en" : "dis");
  425. #endif /* I2C_BOOTROM */
  426. #if defined(SDR0_PINSTP_SHIFT)
  427. printf (" Bootstrap Option %c - ", bootstrap_char[bootstrap_option()]);
  428. printf ("Boot ROM Location %s\n", bootstrap_str[bootstrap_option()]);
  429. #endif /* SDR0_PINSTP_SHIFT */
  430. #if defined(CONFIG_PCI) && !defined(CONFIG_405EX)
  431. printf (" Internal PCI arbiter %sabled", pci_arbiter_enabled() ? "en" : "dis");
  432. #endif
  433. #if defined(PCI_ASYNC)
  434. if (pci_async_enabled()) {
  435. printf (", PCI async ext clock used");
  436. } else {
  437. printf (", PCI sync clock at %lu MHz",
  438. sys_info.freqPLB / sys_info.pllPciDiv / 1000000);
  439. }
  440. #endif
  441. #if defined(CONFIG_PCI) && !defined(CONFIG_405EX)
  442. putc('\n');
  443. #endif
  444. #if defined(CONFIG_405EP) || defined(CONFIG_405EZ) || defined(CONFIG_405EX)
  445. printf (" 16 kB I-Cache 16 kB D-Cache");
  446. #elif defined(CONFIG_440)
  447. printf (" 32 kB I-Cache 32 kB D-Cache");
  448. #else
  449. printf (" 16 kB I-Cache %d kB D-Cache",
  450. ((pvr | 0x00000001) == PVR_405GPR_RB) ? 16 : 8);
  451. #endif
  452. #endif /* !defined(CONFIG_IOP480) */
  453. #if defined(CONFIG_IOP480)
  454. printf ("PLX IOP480 (PVR=%08x)", pvr);
  455. printf (" at %s MHz:", strmhz(buf, clock));
  456. printf (" %u kB I-Cache", 4);
  457. printf (" %u kB D-Cache", 2);
  458. #endif
  459. #endif /* !defined(CONFIG_405) */
  460. putc ('\n');
  461. return 0;
  462. }
  463. int ppc440spe_revB() {
  464. unsigned int pvr;
  465. pvr = get_pvr();
  466. if ((pvr == PVR_440SPe_6_RB) || (pvr == PVR_440SPe_RB))
  467. return 1;
  468. else
  469. return 0;
  470. }
  471. /* ------------------------------------------------------------------------- */
  472. int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  473. {
  474. #if defined(CONFIG_BOARD_RESET)
  475. board_reset();
  476. #else
  477. #if defined(CFG_4xx_RESET_TYPE)
  478. mtspr(dbcr0, CFG_4xx_RESET_TYPE << 28);
  479. #else
  480. /*
  481. * Initiate system reset in debug control register DBCR
  482. */
  483. mtspr(dbcr0, 0x30000000);
  484. #endif /* defined(CFG_4xx_RESET_TYPE) */
  485. #endif /* defined(CONFIG_BOARD_RESET) */
  486. return 1;
  487. }
  488. /*
  489. * Get timebase clock frequency
  490. */
  491. unsigned long get_tbclk (void)
  492. {
  493. #if !defined(CONFIG_IOP480)
  494. sys_info_t sys_info;
  495. get_sys_info(&sys_info);
  496. return (sys_info.freqProcessor);
  497. #else
  498. return (66000000);
  499. #endif
  500. }
  501. #if defined(CONFIG_WATCHDOG)
  502. void watchdog_reset(void)
  503. {
  504. int re_enable = disable_interrupts();
  505. reset_4xx_watchdog();
  506. if (re_enable) enable_interrupts();
  507. }
  508. void reset_4xx_watchdog(void)
  509. {
  510. /*
  511. * Clear TSR(WIS) bit
  512. */
  513. mtspr(tsr, 0x40000000);
  514. }
  515. #endif /* CONFIG_WATCHDOG */