cpu.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  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. default:
  110. puts("Unknown");
  111. break;
  112. }
  113. printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr);
  114. get_sys_info(&sysinfo);
  115. puts("Clock Configuration:");
  116. for_each_cpu(i, core, nr_cores, mask) {
  117. if (!(i & 3))
  118. printf ("\n ");
  119. printf("CPU%d:%-4s MHz, ", core,
  120. strmhz(buf1, sysinfo.freqProcessor[core]));
  121. }
  122. printf("\n CCB:%-4s MHz,\n", strmhz(buf1, sysinfo.freqSystemBus));
  123. #ifdef CONFIG_FSL_CORENET
  124. if (ddr_sync == 1) {
  125. printf(" DDR:%-4s MHz (%s MT/s data rate) "
  126. "(Synchronous), ",
  127. strmhz(buf1, sysinfo.freqDDRBus/2),
  128. strmhz(buf2, sysinfo.freqDDRBus));
  129. } else {
  130. printf(" DDR:%-4s MHz (%s MT/s data rate) "
  131. "(Asynchronous), ",
  132. strmhz(buf1, sysinfo.freqDDRBus/2),
  133. strmhz(buf2, sysinfo.freqDDRBus));
  134. }
  135. #else
  136. switch (ddr_ratio) {
  137. case 0x0:
  138. printf(" DDR:%-4s MHz (%s MT/s data rate), ",
  139. strmhz(buf1, sysinfo.freqDDRBus/2),
  140. strmhz(buf2, sysinfo.freqDDRBus));
  141. break;
  142. case 0x7:
  143. printf(" DDR:%-4s MHz (%s MT/s data rate) "
  144. "(Synchronous), ",
  145. strmhz(buf1, sysinfo.freqDDRBus/2),
  146. strmhz(buf2, sysinfo.freqDDRBus));
  147. break;
  148. default:
  149. printf(" DDR:%-4s MHz (%s MT/s data rate) "
  150. "(Asynchronous), ",
  151. strmhz(buf1, sysinfo.freqDDRBus/2),
  152. strmhz(buf2, sysinfo.freqDDRBus));
  153. break;
  154. }
  155. #endif
  156. #if defined(CONFIG_FSL_LBC)
  157. if (sysinfo.freqLocalBus > LCRR_CLKDIV) {
  158. printf("LBC:%-4s MHz\n", strmhz(buf1, sysinfo.freqLocalBus));
  159. } else {
  160. printf("LBC: unknown (LCRR[CLKDIV] = 0x%02lx)\n",
  161. sysinfo.freqLocalBus);
  162. }
  163. #endif
  164. #ifdef CONFIG_CPM2
  165. printf("CPM: %s MHz\n", strmhz(buf1, sysinfo.freqSystemBus));
  166. #endif
  167. #ifdef CONFIG_QE
  168. printf(" QE:%-4s MHz\n", strmhz(buf1, sysinfo.freqQE));
  169. #endif
  170. #ifdef CONFIG_SYS_DPAA_FMAN
  171. for (i = 0; i < CONFIG_SYS_NUM_FMAN; i++) {
  172. printf(" FMAN%d: %s MHz\n", i + 1,
  173. strmhz(buf1, sysinfo.freqFMan[i]));
  174. }
  175. #endif
  176. #ifdef CONFIG_SYS_DPAA_PME
  177. printf(" PME: %s MHz\n", strmhz(buf1, sysinfo.freqPME));
  178. #endif
  179. puts("L1: D-cache 32 kB enabled\n I-cache 32 kB enabled\n");
  180. return 0;
  181. }
  182. /* ------------------------------------------------------------------------- */
  183. int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  184. {
  185. /* Everything after the first generation of PQ3 parts has RSTCR */
  186. #if defined(CONFIG_MPC8540) || defined(CONFIG_MPC8541) || \
  187. defined(CONFIG_MPC8555) || defined(CONFIG_MPC8560)
  188. unsigned long val, msr;
  189. /*
  190. * Initiate hard reset in debug control register DBCR0
  191. * Make sure MSR[DE] = 1. This only resets the core.
  192. */
  193. msr = mfmsr ();
  194. msr |= MSR_DE;
  195. mtmsr (msr);
  196. val = mfspr(DBCR0);
  197. val |= 0x70000000;
  198. mtspr(DBCR0,val);
  199. #else
  200. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  201. /* Attempt board-specific reset */
  202. board_reset();
  203. /* Next try asserting HRESET_REQ */
  204. out_be32(&gur->rstcr, 0x2);
  205. udelay(100);
  206. #endif
  207. return 1;
  208. }
  209. /*
  210. * Get timebase clock frequency
  211. */
  212. #ifndef CONFIG_SYS_FSL_TBCLK_DIV
  213. #define CONFIG_SYS_FSL_TBCLK_DIV 8
  214. #endif
  215. unsigned long get_tbclk (void)
  216. {
  217. unsigned long tbclk_div = CONFIG_SYS_FSL_TBCLK_DIV;
  218. return (gd->bus_clk + (tbclk_div >> 1)) / tbclk_div;
  219. }
  220. #if defined(CONFIG_WATCHDOG)
  221. void
  222. watchdog_reset(void)
  223. {
  224. int re_enable = disable_interrupts();
  225. reset_85xx_watchdog();
  226. if (re_enable) enable_interrupts();
  227. }
  228. void
  229. reset_85xx_watchdog(void)
  230. {
  231. /*
  232. * Clear TSR(WIS) bit by writing 1
  233. */
  234. unsigned long val;
  235. val = mfspr(SPRN_TSR);
  236. val |= TSR_WIS;
  237. mtspr(SPRN_TSR, val);
  238. }
  239. #endif /* CONFIG_WATCHDOG */
  240. /*
  241. * Initializes on-chip MMC controllers.
  242. * to override, implement board_mmc_init()
  243. */
  244. int cpu_mmc_init(bd_t *bis)
  245. {
  246. #ifdef CONFIG_FSL_ESDHC
  247. return fsl_esdhc_mmc_init(bis);
  248. #else
  249. return 0;
  250. #endif
  251. }
  252. /*
  253. * Print out the state of various machine registers.
  254. * Currently prints out LAWs, BR0/OR0 for LBC, CSPR/CSOR/Timing
  255. * parameters for IFC and TLBs
  256. */
  257. void mpc85xx_reginfo(void)
  258. {
  259. print_tlbcam();
  260. print_laws();
  261. #if defined(CONFIG_FSL_LBC)
  262. print_lbc_regs();
  263. #endif
  264. #ifdef CONFIG_FSL_IFC
  265. print_ifc_regs();
  266. #endif
  267. }
  268. /* Common ddr init for non-corenet fsl 85xx platforms */
  269. #ifndef CONFIG_FSL_CORENET
  270. #if defined(CONFIG_SYS_RAMBOOT) && !defined(CONFIG_SYS_INIT_L2_ADDR)
  271. phys_size_t initdram(int board_type)
  272. {
  273. #if defined(CONFIG_SPD_EEPROM) || defined(CONFIG_DDR_SPD)
  274. return fsl_ddr_sdram_size();
  275. #else
  276. return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
  277. #endif
  278. }
  279. #else /* CONFIG_SYS_RAMBOOT */
  280. phys_size_t initdram(int board_type)
  281. {
  282. phys_size_t dram_size = 0;
  283. #if defined(CONFIG_SYS_FSL_ERRATUM_DDR_MSYNC_IN)
  284. {
  285. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  286. unsigned int x = 10;
  287. unsigned int i;
  288. /*
  289. * Work around to stabilize DDR DLL
  290. */
  291. out_be32(&gur->ddrdllcr, 0x81000000);
  292. asm("sync;isync;msync");
  293. udelay(200);
  294. while (in_be32(&gur->ddrdllcr) != 0x81000100) {
  295. setbits_be32(&gur->devdisr, 0x00010000);
  296. for (i = 0; i < x; i++)
  297. ;
  298. clrbits_be32(&gur->devdisr, 0x00010000);
  299. x++;
  300. }
  301. }
  302. #endif
  303. #if defined(CONFIG_SPD_EEPROM) || \
  304. defined(CONFIG_DDR_SPD) || \
  305. defined(CONFIG_SYS_DDR_RAW_TIMING)
  306. dram_size = fsl_ddr_sdram();
  307. #else
  308. dram_size = fixed_sdram();
  309. #endif
  310. dram_size = setup_ddr_tlbs(dram_size / 0x100000);
  311. dram_size *= 0x100000;
  312. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  313. /*
  314. * Initialize and enable DDR ECC.
  315. */
  316. ddr_enable_ecc(dram_size);
  317. #endif
  318. #if defined(CONFIG_FSL_LBC)
  319. /* Some boards also have sdram on the lbc */
  320. lbc_sdram_init();
  321. #endif
  322. debug("DDR: ");
  323. return dram_size;
  324. }
  325. #endif /* CONFIG_SYS_RAMBOOT */
  326. #endif
  327. #if CONFIG_POST & CONFIG_SYS_POST_MEMORY
  328. /* Board-specific functions defined in each board's ddr.c */
  329. void fsl_ddr_get_spd(generic_spd_eeprom_t *ctrl_dimms_spd,
  330. unsigned int ctrl_num);
  331. void read_tlbcam_entry(int idx, u32 *valid, u32 *tsize, unsigned long *epn,
  332. phys_addr_t *rpn);
  333. unsigned int
  334. setup_ddr_tlbs_phys(phys_addr_t p_addr, unsigned int memsize_in_meg);
  335. void clear_ddr_tlbs_phys(phys_addr_t p_addr, unsigned int memsize_in_meg);
  336. static void dump_spd_ddr_reg(void)
  337. {
  338. int i, j, k, m;
  339. u8 *p_8;
  340. u32 *p_32;
  341. ccsr_ddr_t *ddr[CONFIG_NUM_DDR_CONTROLLERS];
  342. generic_spd_eeprom_t
  343. spd[CONFIG_NUM_DDR_CONTROLLERS][CONFIG_DIMM_SLOTS_PER_CTLR];
  344. for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++)
  345. fsl_ddr_get_spd(spd[i], i);
  346. puts("SPD data of all dimms (zero vaule is omitted)...\n");
  347. puts("Byte (hex) ");
  348. k = 1;
  349. for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) {
  350. for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++)
  351. printf("Dimm%d ", k++);
  352. }
  353. puts("\n");
  354. for (k = 0; k < sizeof(generic_spd_eeprom_t); k++) {
  355. m = 0;
  356. printf("%3d (0x%02x) ", k, k);
  357. for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) {
  358. for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++) {
  359. p_8 = (u8 *) &spd[i][j];
  360. if (p_8[k]) {
  361. printf("0x%02x ", p_8[k]);
  362. m++;
  363. } else
  364. puts(" ");
  365. }
  366. }
  367. if (m)
  368. puts("\n");
  369. else
  370. puts("\r");
  371. }
  372. for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) {
  373. switch (i) {
  374. case 0:
  375. ddr[i] = (void *)CONFIG_SYS_MPC85xx_DDR_ADDR;
  376. break;
  377. #ifdef CONFIG_SYS_MPC85xx_DDR2_ADDR
  378. case 1:
  379. ddr[i] = (void *)CONFIG_SYS_MPC85xx_DDR2_ADDR;
  380. break;
  381. #endif
  382. default:
  383. printf("%s unexpected controller number = %u\n",
  384. __func__, i);
  385. return;
  386. }
  387. }
  388. printf("DDR registers dump for all controllers "
  389. "(zero vaule is omitted)...\n");
  390. puts("Offset (hex) ");
  391. for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++)
  392. printf(" Base + 0x%04x", (u32)ddr[i] & 0xFFFF);
  393. puts("\n");
  394. for (k = 0; k < sizeof(ccsr_ddr_t)/4; k++) {
  395. m = 0;
  396. printf("%6d (0x%04x)", k * 4, k * 4);
  397. for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) {
  398. p_32 = (u32 *) ddr[i];
  399. if (p_32[k]) {
  400. printf(" 0x%08x", p_32[k]);
  401. m++;
  402. } else
  403. puts(" ");
  404. }
  405. if (m)
  406. puts("\n");
  407. else
  408. puts("\r");
  409. }
  410. puts("\n");
  411. }
  412. /* invalid the TLBs for DDR and setup new ones to cover p_addr */
  413. static int reset_tlb(phys_addr_t p_addr, u32 size, phys_addr_t *phys_offset)
  414. {
  415. u32 vstart = CONFIG_SYS_DDR_SDRAM_BASE;
  416. unsigned long epn;
  417. u32 tsize, valid, ptr;
  418. int ddr_esel;
  419. clear_ddr_tlbs_phys(p_addr, size>>20);
  420. /* Setup new tlb to cover the physical address */
  421. setup_ddr_tlbs_phys(p_addr, size>>20);
  422. ptr = vstart;
  423. ddr_esel = find_tlb_idx((void *)ptr, 1);
  424. if (ddr_esel != -1) {
  425. read_tlbcam_entry(ddr_esel, &valid, &tsize, &epn, phys_offset);
  426. } else {
  427. printf("TLB error in function %s\n", __func__);
  428. return -1;
  429. }
  430. return 0;
  431. }
  432. /*
  433. * slide the testing window up to test another area
  434. * for 32_bit system, the maximum testable memory is limited to
  435. * CONFIG_MAX_MEM_MAPPED
  436. */
  437. int arch_memory_test_advance(u32 *vstart, u32 *size, phys_addr_t *phys_offset)
  438. {
  439. phys_addr_t test_cap, p_addr;
  440. phys_size_t p_size = min(gd->ram_size, CONFIG_MAX_MEM_MAPPED);
  441. #if !defined(CONFIG_PHYS_64BIT) || \
  442. !defined(CONFIG_SYS_INIT_RAM_ADDR_PHYS) || \
  443. (CONFIG_SYS_INIT_RAM_ADDR_PHYS < 0x100000000ull)
  444. test_cap = p_size;
  445. #else
  446. test_cap = gd->ram_size;
  447. #endif
  448. p_addr = (*vstart) + (*size) + (*phys_offset);
  449. if (p_addr < test_cap - 1) {
  450. p_size = min(test_cap - p_addr, CONFIG_MAX_MEM_MAPPED);
  451. if (reset_tlb(p_addr, p_size, phys_offset) == -1)
  452. return -1;
  453. *vstart = CONFIG_SYS_DDR_SDRAM_BASE;
  454. *size = (u32) p_size;
  455. printf("Testing 0x%08llx - 0x%08llx\n",
  456. (u64)(*vstart) + (*phys_offset),
  457. (u64)(*vstart) + (*phys_offset) + (*size) - 1);
  458. } else
  459. return 1;
  460. return 0;
  461. }
  462. /* initialization for testing area */
  463. int arch_memory_test_prepare(u32 *vstart, u32 *size, phys_addr_t *phys_offset)
  464. {
  465. phys_size_t p_size = min(gd->ram_size, CONFIG_MAX_MEM_MAPPED);
  466. *vstart = CONFIG_SYS_DDR_SDRAM_BASE;
  467. *size = (u32) p_size; /* CONFIG_MAX_MEM_MAPPED < 4G */
  468. *phys_offset = 0;
  469. #if !defined(CONFIG_PHYS_64BIT) || \
  470. !defined(CONFIG_SYS_INIT_RAM_ADDR_PHYS) || \
  471. (CONFIG_SYS_INIT_RAM_ADDR_PHYS < 0x100000000ull)
  472. if (gd->ram_size > CONFIG_MAX_MEM_MAPPED) {
  473. puts("Cannot test more than ");
  474. print_size(CONFIG_MAX_MEM_MAPPED,
  475. " without proper 36BIT support.\n");
  476. }
  477. #endif
  478. printf("Testing 0x%08llx - 0x%08llx\n",
  479. (u64)(*vstart) + (*phys_offset),
  480. (u64)(*vstart) + (*phys_offset) + (*size) - 1);
  481. return 0;
  482. }
  483. /* invalid TLBs for DDR and remap as normal after testing */
  484. int arch_memory_test_cleanup(u32 *vstart, u32 *size, phys_addr_t *phys_offset)
  485. {
  486. unsigned long epn;
  487. u32 tsize, valid, ptr;
  488. phys_addr_t rpn = 0;
  489. int ddr_esel;
  490. /* disable the TLBs for this testing */
  491. ptr = *vstart;
  492. while (ptr < (*vstart) + (*size)) {
  493. ddr_esel = find_tlb_idx((void *)ptr, 1);
  494. if (ddr_esel != -1) {
  495. read_tlbcam_entry(ddr_esel, &valid, &tsize, &epn, &rpn);
  496. disable_tlb(ddr_esel);
  497. }
  498. ptr += TSIZE_TO_BYTES(tsize);
  499. }
  500. puts("Remap DDR ");
  501. setup_ddr_tlbs(gd->ram_size>>20);
  502. puts("\n");
  503. return 0;
  504. }
  505. void arch_memory_failure_handle(void)
  506. {
  507. dump_spd_ddr_reg();
  508. }
  509. #endif