cpu.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. /*
  2. * Copyright 2004,2007-2010 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. DECLARE_GLOBAL_DATA_PTR;
  35. int checkcpu (void)
  36. {
  37. sys_info_t sysinfo;
  38. uint pvr, svr;
  39. uint fam;
  40. uint ver;
  41. uint major, minor;
  42. struct cpu_type *cpu;
  43. char buf1[32], buf2[32];
  44. #if defined(CONFIG_DDR_CLK_FREQ) || defined(CONFIG_FSL_CORENET)
  45. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  46. #endif /* CONFIG_FSL_CORENET */
  47. #ifdef CONFIG_DDR_CLK_FREQ
  48. u32 ddr_ratio = ((gur->porpllsr) & MPC85xx_PORPLLSR_DDR_RATIO)
  49. >> MPC85xx_PORPLLSR_DDR_RATIO_SHIFT;
  50. #else
  51. #ifdef CONFIG_FSL_CORENET
  52. u32 ddr_sync = ((gur->rcwsr[5]) & FSL_CORENET_RCWSR5_DDR_SYNC)
  53. >> FSL_CORENET_RCWSR5_DDR_SYNC_SHIFT;
  54. #else
  55. u32 ddr_ratio = 0;
  56. #endif /* CONFIG_FSL_CORENET */
  57. #endif /* CONFIG_DDR_CLK_FREQ */
  58. int i;
  59. svr = get_svr();
  60. major = SVR_MAJ(svr);
  61. #ifdef CONFIG_MPC8536
  62. major &= 0x7; /* the msb of this nibble is a mfg code */
  63. #endif
  64. minor = SVR_MIN(svr);
  65. if (cpu_numcores() > 1) {
  66. #ifndef CONFIG_MP
  67. puts("Unicore software on multiprocessor system!!\n"
  68. "To enable mutlticore build define CONFIG_MP\n");
  69. #endif
  70. volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC85xx_PIC_ADDR);
  71. printf("CPU%d: ", pic->whoami);
  72. } else {
  73. puts("CPU: ");
  74. }
  75. cpu = gd->cpu;
  76. puts(cpu->name);
  77. if (IS_E_PROCESSOR(svr))
  78. puts("E");
  79. printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
  80. pvr = get_pvr();
  81. fam = PVR_FAM(pvr);
  82. ver = PVR_VER(pvr);
  83. major = PVR_MAJ(pvr);
  84. minor = PVR_MIN(pvr);
  85. printf("Core: ");
  86. switch (fam) {
  87. case PVR_FAM(PVR_85xx):
  88. puts("E500");
  89. break;
  90. default:
  91. puts("Unknown");
  92. break;
  93. }
  94. if (PVR_MEM(pvr) == 0x03)
  95. puts("MC");
  96. printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr);
  97. get_sys_info(&sysinfo);
  98. puts("Clock Configuration:");
  99. for (i = 0; i < cpu_numcores(); i++) {
  100. if (!(i & 3))
  101. printf ("\n ");
  102. printf("CPU%d:%-4s MHz, ",
  103. i,strmhz(buf1, sysinfo.freqProcessor[i]));
  104. }
  105. printf("\n CCB:%-4s MHz,\n", strmhz(buf1, sysinfo.freqSystemBus));
  106. #ifdef CONFIG_FSL_CORENET
  107. if (ddr_sync == 1) {
  108. printf(" DDR:%-4s MHz (%s MT/s data rate) "
  109. "(Synchronous), ",
  110. strmhz(buf1, sysinfo.freqDDRBus/2),
  111. strmhz(buf2, sysinfo.freqDDRBus));
  112. } else {
  113. printf(" DDR:%-4s MHz (%s MT/s data rate) "
  114. "(Asynchronous), ",
  115. strmhz(buf1, sysinfo.freqDDRBus/2),
  116. strmhz(buf2, sysinfo.freqDDRBus));
  117. }
  118. #else
  119. switch (ddr_ratio) {
  120. case 0x0:
  121. printf(" DDR:%-4s MHz (%s MT/s data rate), ",
  122. strmhz(buf1, sysinfo.freqDDRBus/2),
  123. strmhz(buf2, sysinfo.freqDDRBus));
  124. break;
  125. case 0x7:
  126. printf(" DDR:%-4s MHz (%s MT/s data rate) "
  127. "(Synchronous), ",
  128. strmhz(buf1, sysinfo.freqDDRBus/2),
  129. strmhz(buf2, sysinfo.freqDDRBus));
  130. break;
  131. default:
  132. printf(" DDR:%-4s MHz (%s MT/s data rate) "
  133. "(Asynchronous), ",
  134. strmhz(buf1, sysinfo.freqDDRBus/2),
  135. strmhz(buf2, sysinfo.freqDDRBus));
  136. break;
  137. }
  138. #endif
  139. if (sysinfo.freqLocalBus > LCRR_CLKDIV) {
  140. printf("LBC:%-4s MHz\n", strmhz(buf1, sysinfo.freqLocalBus));
  141. } else {
  142. printf("LBC: unknown (LCRR[CLKDIV] = 0x%02lx)\n",
  143. sysinfo.freqLocalBus);
  144. }
  145. #ifdef CONFIG_CPM2
  146. printf("CPM: %s MHz\n", strmhz(buf1, sysinfo.freqSystemBus));
  147. #endif
  148. #ifdef CONFIG_QE
  149. printf(" QE:%-4s MHz\n", strmhz(buf1, sysinfo.freqQE));
  150. #endif
  151. #ifdef CONFIG_SYS_DPAA_FMAN
  152. for (i = 0; i < CONFIG_SYS_NUM_FMAN; i++) {
  153. printf(" FMAN%d: %s MHz\n", i,
  154. strmhz(buf1, sysinfo.freqFMan[i]));
  155. }
  156. #endif
  157. #ifdef CONFIG_SYS_DPAA_PME
  158. printf(" PME: %s MHz\n", strmhz(buf1, sysinfo.freqPME));
  159. #endif
  160. puts("L1: D-cache 32 kB enabled\n I-cache 32 kB enabled\n");
  161. return 0;
  162. }
  163. /* ------------------------------------------------------------------------- */
  164. int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char * const argv[])
  165. {
  166. /* Everything after the first generation of PQ3 parts has RSTCR */
  167. #if defined(CONFIG_MPC8540) || defined(CONFIG_MPC8541) || \
  168. defined(CONFIG_MPC8555) || defined(CONFIG_MPC8560)
  169. unsigned long val, msr;
  170. /*
  171. * Initiate hard reset in debug control register DBCR0
  172. * Make sure MSR[DE] = 1. This only resets the core.
  173. */
  174. msr = mfmsr ();
  175. msr |= MSR_DE;
  176. mtmsr (msr);
  177. val = mfspr(DBCR0);
  178. val |= 0x70000000;
  179. mtspr(DBCR0,val);
  180. #else
  181. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  182. out_be32(&gur->rstcr, 0x2); /* HRESET_REQ */
  183. udelay(100);
  184. #endif
  185. return 1;
  186. }
  187. /*
  188. * Get timebase clock frequency
  189. */
  190. unsigned long get_tbclk (void)
  191. {
  192. #ifdef CONFIG_FSL_CORENET
  193. return (gd->bus_clk + 8) / 16;
  194. #else
  195. return (gd->bus_clk + 4UL)/8UL;
  196. #endif
  197. }
  198. #if defined(CONFIG_WATCHDOG)
  199. void
  200. watchdog_reset(void)
  201. {
  202. int re_enable = disable_interrupts();
  203. reset_85xx_watchdog();
  204. if (re_enable) enable_interrupts();
  205. }
  206. void
  207. reset_85xx_watchdog(void)
  208. {
  209. /*
  210. * Clear TSR(WIS) bit by writing 1
  211. */
  212. unsigned long val;
  213. val = mfspr(SPRN_TSR);
  214. val |= TSR_WIS;
  215. mtspr(SPRN_TSR, val);
  216. }
  217. #endif /* CONFIG_WATCHDOG */
  218. /*
  219. * Configures a UPM. The function requires the respective MxMR to be set
  220. * before calling this function. "size" is the number or entries, not a sizeof.
  221. */
  222. void upmconfig (uint upm, uint * table, uint size)
  223. {
  224. int i, mdr, mad, old_mad = 0;
  225. volatile u32 *mxmr;
  226. volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
  227. volatile u32 *brp,*orp;
  228. volatile u8* dummy = NULL;
  229. int upmmask;
  230. switch (upm) {
  231. case UPMA:
  232. mxmr = &lbc->mamr;
  233. upmmask = BR_MS_UPMA;
  234. break;
  235. case UPMB:
  236. mxmr = &lbc->mbmr;
  237. upmmask = BR_MS_UPMB;
  238. break;
  239. case UPMC:
  240. mxmr = &lbc->mcmr;
  241. upmmask = BR_MS_UPMC;
  242. break;
  243. default:
  244. printf("%s: Bad UPM index %d to configure\n", __FUNCTION__, upm);
  245. hang();
  246. }
  247. /* Find the address for the dummy write transaction */
  248. for (brp = &lbc->br0, orp = &lbc->or0, i = 0; i < 8;
  249. i++, brp += 2, orp += 2) {
  250. /* Look for a valid BR with selected UPM */
  251. if ((in_be32(brp) & (BR_V | BR_MSEL)) == (BR_V | upmmask)) {
  252. dummy = (volatile u8*)(in_be32(brp) & BR_BA);
  253. break;
  254. }
  255. }
  256. if (i == 8) {
  257. printf("Error: %s() could not find matching BR\n", __FUNCTION__);
  258. hang();
  259. }
  260. for (i = 0; i < size; i++) {
  261. /* 1 */
  262. out_be32(mxmr, (in_be32(mxmr) & 0x4fffffc0) | MxMR_OP_WARR | i);
  263. /* 2 */
  264. out_be32(&lbc->mdr, table[i]);
  265. /* 3 */
  266. mdr = in_be32(&lbc->mdr);
  267. /* 4 */
  268. *(volatile u8 *)dummy = 0;
  269. /* 5 */
  270. do {
  271. mad = in_be32(mxmr) & MxMR_MAD_MSK;
  272. } while (mad <= old_mad && !(!mad && i == (size-1)));
  273. old_mad = mad;
  274. }
  275. out_be32(mxmr, (in_be32(mxmr) & 0x4fffffc0) | MxMR_OP_NORM);
  276. }
  277. /*
  278. * Initializes on-chip MMC controllers.
  279. * to override, implement board_mmc_init()
  280. */
  281. int cpu_mmc_init(bd_t *bis)
  282. {
  283. #ifdef CONFIG_FSL_ESDHC
  284. return fsl_esdhc_mmc_init(bis);
  285. #else
  286. return 0;
  287. #endif
  288. }