cpu.c 6.5 KB

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