cpu.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. /*
  2. * Copyright 2004,2007-2011 Freescale Semiconductor, Inc.
  3. * (C) Copyright 2002, 2003 Motorola Inc.
  4. * Xianghua Xiao (X.Xiao@motorola.com)
  5. *
  6. * (C) Copyright 2000
  7. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. #include <config.h>
  28. #include <common.h>
  29. #include <watchdog.h>
  30. #include <command.h>
  31. #include <fsl_esdhc.h>
  32. #include <asm/cache.h>
  33. #include <asm/io.h>
  34. #include <asm/mmu.h>
  35. #include <asm/fsl_ifc.h>
  36. #include <asm/fsl_law.h>
  37. #include <asm/fsl_lbc.h>
  38. #include <post.h>
  39. #include <asm/processor.h>
  40. #include <asm/fsl_ddr_sdram.h>
  41. DECLARE_GLOBAL_DATA_PTR;
  42. /*
  43. * Default board reset function
  44. */
  45. static void
  46. __board_reset(void)
  47. {
  48. /* Do nothing */
  49. }
  50. void board_reset(void) __attribute__((weak, alias("__board_reset")));
  51. int checkcpu (void)
  52. {
  53. sys_info_t sysinfo;
  54. uint pvr, svr;
  55. uint ver;
  56. uint major, minor;
  57. struct cpu_type *cpu;
  58. char buf1[32], buf2[32];
  59. #if defined(CONFIG_DDR_CLK_FREQ) || defined(CONFIG_FSL_CORENET)
  60. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  61. #endif /* CONFIG_FSL_CORENET */
  62. #ifdef CONFIG_DDR_CLK_FREQ
  63. u32 ddr_ratio = ((gur->porpllsr) & MPC85xx_PORPLLSR_DDR_RATIO)
  64. >> MPC85xx_PORPLLSR_DDR_RATIO_SHIFT;
  65. #else
  66. #ifdef CONFIG_FSL_CORENET
  67. u32 ddr_sync = ((gur->rcwsr[5]) & FSL_CORENET_RCWSR5_DDR_SYNC)
  68. >> FSL_CORENET_RCWSR5_DDR_SYNC_SHIFT;
  69. #else
  70. u32 ddr_ratio = 0;
  71. #endif /* CONFIG_FSL_CORENET */
  72. #endif /* CONFIG_DDR_CLK_FREQ */
  73. unsigned int i, core, nr_cores = cpu_numcores();
  74. u32 mask = cpu_mask();
  75. svr = get_svr();
  76. major = SVR_MAJ(svr);
  77. minor = SVR_MIN(svr);
  78. if (cpu_numcores() > 1) {
  79. #ifndef CONFIG_MP
  80. puts("Unicore software on multiprocessor system!!\n"
  81. "To enable mutlticore build define CONFIG_MP\n");
  82. #endif
  83. volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
  84. printf("CPU%d: ", pic->whoami);
  85. } else {
  86. puts("CPU: ");
  87. }
  88. cpu = gd->cpu;
  89. puts(cpu->name);
  90. if (IS_E_PROCESSOR(svr))
  91. puts("E");
  92. printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
  93. pvr = get_pvr();
  94. ver = PVR_VER(pvr);
  95. major = PVR_MAJ(pvr);
  96. minor = PVR_MIN(pvr);
  97. printf("Core: ");
  98. switch(ver) {
  99. case PVR_VER_E500_V1:
  100. case PVR_VER_E500_V2:
  101. puts("E500");
  102. break;
  103. case PVR_VER_E500MC:
  104. puts("E500MC");
  105. break;
  106. case PVR_VER_E5500:
  107. puts("E5500");
  108. break;
  109. case PVR_VER_E6500:
  110. puts("E6500");
  111. break;
  112. default:
  113. puts("Unknown");
  114. break;
  115. }
  116. printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr);
  117. get_sys_info(&sysinfo);
  118. puts("Clock Configuration:");
  119. for_each_cpu(i, core, nr_cores, mask) {
  120. if (!(i & 3))
  121. printf ("\n ");
  122. printf("CPU%d:%-4s MHz, ", core,
  123. strmhz(buf1, sysinfo.freqProcessor[core]));
  124. }
  125. printf("\n CCB:%-4s MHz,\n", strmhz(buf1, sysinfo.freqSystemBus));
  126. #ifdef CONFIG_FSL_CORENET
  127. if (ddr_sync == 1) {
  128. printf(" DDR:%-4s MHz (%s MT/s data rate) "
  129. "(Synchronous), ",
  130. strmhz(buf1, sysinfo.freqDDRBus/2),
  131. strmhz(buf2, sysinfo.freqDDRBus));
  132. } else {
  133. printf(" DDR:%-4s MHz (%s MT/s data rate) "
  134. "(Asynchronous), ",
  135. strmhz(buf1, sysinfo.freqDDRBus/2),
  136. strmhz(buf2, sysinfo.freqDDRBus));
  137. }
  138. #else
  139. switch (ddr_ratio) {
  140. case 0x0:
  141. printf(" DDR:%-4s MHz (%s MT/s data rate), ",
  142. strmhz(buf1, sysinfo.freqDDRBus/2),
  143. strmhz(buf2, sysinfo.freqDDRBus));
  144. break;
  145. case 0x7:
  146. printf(" DDR:%-4s MHz (%s MT/s data rate) "
  147. "(Synchronous), ",
  148. strmhz(buf1, sysinfo.freqDDRBus/2),
  149. strmhz(buf2, sysinfo.freqDDRBus));
  150. break;
  151. default:
  152. printf(" DDR:%-4s MHz (%s MT/s data rate) "
  153. "(Asynchronous), ",
  154. strmhz(buf1, sysinfo.freqDDRBus/2),
  155. strmhz(buf2, sysinfo.freqDDRBus));
  156. break;
  157. }
  158. #endif
  159. #if defined(CONFIG_FSL_LBC)
  160. if (sysinfo.freqLocalBus > LCRR_CLKDIV) {
  161. printf("LBC:%-4s MHz\n", strmhz(buf1, sysinfo.freqLocalBus));
  162. } else {
  163. printf("LBC: unknown (LCRR[CLKDIV] = 0x%02lx)\n",
  164. sysinfo.freqLocalBus);
  165. }
  166. #endif
  167. #ifdef CONFIG_CPM2
  168. printf("CPM: %s MHz\n", strmhz(buf1, sysinfo.freqSystemBus));
  169. #endif
  170. #ifdef CONFIG_QE
  171. printf(" QE:%-4s MHz\n", strmhz(buf1, sysinfo.freqQE));
  172. #endif
  173. #ifdef CONFIG_SYS_DPAA_FMAN
  174. for (i = 0; i < CONFIG_SYS_NUM_FMAN; i++) {
  175. printf(" FMAN%d: %s MHz\n", i + 1,
  176. strmhz(buf1, sysinfo.freqFMan[i]));
  177. }
  178. #endif
  179. #ifdef CONFIG_SYS_DPAA_PME
  180. printf(" PME: %s MHz\n", strmhz(buf1, sysinfo.freqPME));
  181. #endif
  182. puts("L1: D-cache 32 kB enabled\n I-cache 32 kB enabled\n");
  183. return 0;
  184. }
  185. /* ------------------------------------------------------------------------- */
  186. int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  187. {
  188. /* Everything after the first generation of PQ3 parts has RSTCR */
  189. #if defined(CONFIG_MPC8540) || defined(CONFIG_MPC8541) || \
  190. defined(CONFIG_MPC8555) || defined(CONFIG_MPC8560)
  191. unsigned long val, msr;
  192. /*
  193. * Initiate hard reset in debug control register DBCR0
  194. * Make sure MSR[DE] = 1. This only resets the core.
  195. */
  196. msr = mfmsr ();
  197. msr |= MSR_DE;
  198. mtmsr (msr);
  199. val = mfspr(DBCR0);
  200. val |= 0x70000000;
  201. mtspr(DBCR0,val);
  202. #else
  203. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  204. /* Attempt board-specific reset */
  205. board_reset();
  206. /* Next try asserting HRESET_REQ */
  207. out_be32(&gur->rstcr, 0x2);
  208. udelay(100);
  209. #endif
  210. return 1;
  211. }
  212. /*
  213. * Get timebase clock frequency
  214. */
  215. #ifndef CONFIG_SYS_FSL_TBCLK_DIV
  216. #define CONFIG_SYS_FSL_TBCLK_DIV 8
  217. #endif
  218. unsigned long get_tbclk (void)
  219. {
  220. unsigned long tbclk_div = CONFIG_SYS_FSL_TBCLK_DIV;
  221. return (gd->bus_clk + (tbclk_div >> 1)) / tbclk_div;
  222. }
  223. #if defined(CONFIG_WATCHDOG)
  224. void
  225. watchdog_reset(void)
  226. {
  227. int re_enable = disable_interrupts();
  228. reset_85xx_watchdog();
  229. if (re_enable) enable_interrupts();
  230. }
  231. void
  232. reset_85xx_watchdog(void)
  233. {
  234. /*
  235. * Clear TSR(WIS) bit by writing 1
  236. */
  237. unsigned long val;
  238. val = mfspr(SPRN_TSR);
  239. val |= TSR_WIS;
  240. mtspr(SPRN_TSR, val);
  241. }
  242. #endif /* CONFIG_WATCHDOG */
  243. /*
  244. * Initializes on-chip MMC controllers.
  245. * to override, implement board_mmc_init()
  246. */
  247. int cpu_mmc_init(bd_t *bis)
  248. {
  249. #ifdef CONFIG_FSL_ESDHC
  250. return fsl_esdhc_mmc_init(bis);
  251. #else
  252. return 0;
  253. #endif
  254. }
  255. /*
  256. * Print out the state of various machine registers.
  257. * Currently prints out LAWs, BR0/OR0 for LBC, CSPR/CSOR/Timing
  258. * parameters for IFC and TLBs
  259. */
  260. void mpc85xx_reginfo(void)
  261. {
  262. print_tlbcam();
  263. print_laws();
  264. #if defined(CONFIG_FSL_LBC)
  265. print_lbc_regs();
  266. #endif
  267. #ifdef CONFIG_FSL_IFC
  268. print_ifc_regs();
  269. #endif
  270. }
  271. /* Common ddr init for non-corenet fsl 85xx platforms */
  272. #ifndef CONFIG_FSL_CORENET
  273. #if defined(CONFIG_SYS_RAMBOOT) && !defined(CONFIG_SYS_INIT_L2_ADDR)
  274. phys_size_t initdram(int board_type)
  275. {
  276. #if defined(CONFIG_SPD_EEPROM) || defined(CONFIG_DDR_SPD)
  277. return fsl_ddr_sdram_size();
  278. #else
  279. return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
  280. #endif
  281. }
  282. #else /* CONFIG_SYS_RAMBOOT */
  283. phys_size_t initdram(int board_type)
  284. {
  285. phys_size_t dram_size = 0;
  286. #if defined(CONFIG_SYS_FSL_ERRATUM_DDR_MSYNC_IN)
  287. {
  288. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  289. unsigned int x = 10;
  290. unsigned int i;
  291. /*
  292. * Work around to stabilize DDR DLL
  293. */
  294. out_be32(&gur->ddrdllcr, 0x81000000);
  295. asm("sync;isync;msync");
  296. udelay(200);
  297. while (in_be32(&gur->ddrdllcr) != 0x81000100) {
  298. setbits_be32(&gur->devdisr, 0x00010000);
  299. for (i = 0; i < x; i++)
  300. ;
  301. clrbits_be32(&gur->devdisr, 0x00010000);
  302. x++;
  303. }
  304. }
  305. #endif
  306. #if defined(CONFIG_SPD_EEPROM) || \
  307. defined(CONFIG_DDR_SPD) || \
  308. defined(CONFIG_SYS_DDR_RAW_TIMING)
  309. dram_size = fsl_ddr_sdram();
  310. #else
  311. dram_size = fixed_sdram();
  312. #endif
  313. dram_size = setup_ddr_tlbs(dram_size / 0x100000);
  314. dram_size *= 0x100000;
  315. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  316. /*
  317. * Initialize and enable DDR ECC.
  318. */
  319. ddr_enable_ecc(dram_size);
  320. #endif
  321. #if defined(CONFIG_FSL_LBC)
  322. /* Some boards also have sdram on the lbc */
  323. lbc_sdram_init();
  324. #endif
  325. debug("DDR: ");
  326. return dram_size;
  327. }
  328. #endif /* CONFIG_SYS_RAMBOOT */
  329. #endif
  330. #if CONFIG_POST & CONFIG_SYS_POST_MEMORY
  331. /* Board-specific functions defined in each board's ddr.c */
  332. void fsl_ddr_get_spd(generic_spd_eeprom_t *ctrl_dimms_spd,
  333. unsigned int ctrl_num);
  334. void read_tlbcam_entry(int idx, u32 *valid, u32 *tsize, unsigned long *epn,
  335. phys_addr_t *rpn);
  336. unsigned int
  337. setup_ddr_tlbs_phys(phys_addr_t p_addr, unsigned int memsize_in_meg);
  338. void clear_ddr_tlbs_phys(phys_addr_t p_addr, unsigned int memsize_in_meg);
  339. static void dump_spd_ddr_reg(void)
  340. {
  341. int i, j, k, m;
  342. u8 *p_8;
  343. u32 *p_32;
  344. ccsr_ddr_t *ddr[CONFIG_NUM_DDR_CONTROLLERS];
  345. generic_spd_eeprom_t
  346. spd[CONFIG_NUM_DDR_CONTROLLERS][CONFIG_DIMM_SLOTS_PER_CTLR];
  347. for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++)
  348. fsl_ddr_get_spd(spd[i], i);
  349. puts("SPD data of all dimms (zero vaule is omitted)...\n");
  350. puts("Byte (hex) ");
  351. k = 1;
  352. for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) {
  353. for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++)
  354. printf("Dimm%d ", k++);
  355. }
  356. puts("\n");
  357. for (k = 0; k < sizeof(generic_spd_eeprom_t); k++) {
  358. m = 0;
  359. printf("%3d (0x%02x) ", k, k);
  360. for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) {
  361. for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++) {
  362. p_8 = (u8 *) &spd[i][j];
  363. if (p_8[k]) {
  364. printf("0x%02x ", p_8[k]);
  365. m++;
  366. } else
  367. puts(" ");
  368. }
  369. }
  370. if (m)
  371. puts("\n");
  372. else
  373. puts("\r");
  374. }
  375. for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) {
  376. switch (i) {
  377. case 0:
  378. ddr[i] = (void *)CONFIG_SYS_MPC85xx_DDR_ADDR;
  379. break;
  380. #ifdef CONFIG_SYS_MPC85xx_DDR2_ADDR
  381. case 1:
  382. ddr[i] = (void *)CONFIG_SYS_MPC85xx_DDR2_ADDR;
  383. break;
  384. #endif
  385. default:
  386. printf("%s unexpected controller number = %u\n",
  387. __func__, i);
  388. return;
  389. }
  390. }
  391. printf("DDR registers dump for all controllers "
  392. "(zero vaule is omitted)...\n");
  393. puts("Offset (hex) ");
  394. for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++)
  395. printf(" Base + 0x%04x", (u32)ddr[i] & 0xFFFF);
  396. puts("\n");
  397. for (k = 0; k < sizeof(ccsr_ddr_t)/4; k++) {
  398. m = 0;
  399. printf("%6d (0x%04x)", k * 4, k * 4);
  400. for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) {
  401. p_32 = (u32 *) ddr[i];
  402. if (p_32[k]) {
  403. printf(" 0x%08x", p_32[k]);
  404. m++;
  405. } else
  406. puts(" ");
  407. }
  408. if (m)
  409. puts("\n");
  410. else
  411. puts("\r");
  412. }
  413. puts("\n");
  414. }
  415. /* invalid the TLBs for DDR and setup new ones to cover p_addr */
  416. static int reset_tlb(phys_addr_t p_addr, u32 size, phys_addr_t *phys_offset)
  417. {
  418. u32 vstart = CONFIG_SYS_DDR_SDRAM_BASE;
  419. unsigned long epn;
  420. u32 tsize, valid, ptr;
  421. int ddr_esel;
  422. clear_ddr_tlbs_phys(p_addr, size>>20);
  423. /* Setup new tlb to cover the physical address */
  424. setup_ddr_tlbs_phys(p_addr, size>>20);
  425. ptr = vstart;
  426. ddr_esel = find_tlb_idx((void *)ptr, 1);
  427. if (ddr_esel != -1) {
  428. read_tlbcam_entry(ddr_esel, &valid, &tsize, &epn, phys_offset);
  429. } else {
  430. printf("TLB error in function %s\n", __func__);
  431. return -1;
  432. }
  433. return 0;
  434. }
  435. /*
  436. * slide the testing window up to test another area
  437. * for 32_bit system, the maximum testable memory is limited to
  438. * CONFIG_MAX_MEM_MAPPED
  439. */
  440. int arch_memory_test_advance(u32 *vstart, u32 *size, phys_addr_t *phys_offset)
  441. {
  442. phys_addr_t test_cap, p_addr;
  443. phys_size_t p_size = min(gd->ram_size, CONFIG_MAX_MEM_MAPPED);
  444. #if !defined(CONFIG_PHYS_64BIT) || \
  445. !defined(CONFIG_SYS_INIT_RAM_ADDR_PHYS) || \
  446. (CONFIG_SYS_INIT_RAM_ADDR_PHYS < 0x100000000ull)
  447. test_cap = p_size;
  448. #else
  449. test_cap = gd->ram_size;
  450. #endif
  451. p_addr = (*vstart) + (*size) + (*phys_offset);
  452. if (p_addr < test_cap - 1) {
  453. p_size = min(test_cap - p_addr, CONFIG_MAX_MEM_MAPPED);
  454. if (reset_tlb(p_addr, p_size, phys_offset) == -1)
  455. return -1;
  456. *vstart = CONFIG_SYS_DDR_SDRAM_BASE;
  457. *size = (u32) p_size;
  458. printf("Testing 0x%08llx - 0x%08llx\n",
  459. (u64)(*vstart) + (*phys_offset),
  460. (u64)(*vstart) + (*phys_offset) + (*size) - 1);
  461. } else
  462. return 1;
  463. return 0;
  464. }
  465. /* initialization for testing area */
  466. int arch_memory_test_prepare(u32 *vstart, u32 *size, phys_addr_t *phys_offset)
  467. {
  468. phys_size_t p_size = min(gd->ram_size, CONFIG_MAX_MEM_MAPPED);
  469. *vstart = CONFIG_SYS_DDR_SDRAM_BASE;
  470. *size = (u32) p_size; /* CONFIG_MAX_MEM_MAPPED < 4G */
  471. *phys_offset = 0;
  472. #if !defined(CONFIG_PHYS_64BIT) || \
  473. !defined(CONFIG_SYS_INIT_RAM_ADDR_PHYS) || \
  474. (CONFIG_SYS_INIT_RAM_ADDR_PHYS < 0x100000000ull)
  475. if (gd->ram_size > CONFIG_MAX_MEM_MAPPED) {
  476. puts("Cannot test more than ");
  477. print_size(CONFIG_MAX_MEM_MAPPED,
  478. " without proper 36BIT support.\n");
  479. }
  480. #endif
  481. printf("Testing 0x%08llx - 0x%08llx\n",
  482. (u64)(*vstart) + (*phys_offset),
  483. (u64)(*vstart) + (*phys_offset) + (*size) - 1);
  484. return 0;
  485. }
  486. /* invalid TLBs for DDR and remap as normal after testing */
  487. int arch_memory_test_cleanup(u32 *vstart, u32 *size, phys_addr_t *phys_offset)
  488. {
  489. unsigned long epn;
  490. u32 tsize, valid, ptr;
  491. phys_addr_t rpn = 0;
  492. int ddr_esel;
  493. /* disable the TLBs for this testing */
  494. ptr = *vstart;
  495. while (ptr < (*vstart) + (*size)) {
  496. ddr_esel = find_tlb_idx((void *)ptr, 1);
  497. if (ddr_esel != -1) {
  498. read_tlbcam_entry(ddr_esel, &valid, &tsize, &epn, &rpn);
  499. disable_tlb(ddr_esel);
  500. }
  501. ptr += TSIZE_TO_BYTES(tsize);
  502. }
  503. puts("Remap DDR ");
  504. setup_ddr_tlbs(gd->ram_size>>20);
  505. puts("\n");
  506. return 0;
  507. }
  508. void arch_memory_failure_handle(void)
  509. {
  510. dump_spd_ddr_reg();
  511. }
  512. #endif