cpu.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. /*
  2. * Copyright 2004,2007,2008 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 <tsec.h>
  32. #include <netdev.h>
  33. #include <fsl_esdhc.h>
  34. #include <asm/cache.h>
  35. #include <asm/io.h>
  36. DECLARE_GLOBAL_DATA_PTR;
  37. struct cpu_type cpu_type_list [] = {
  38. CPU_TYPE_ENTRY(8533, 8533),
  39. CPU_TYPE_ENTRY(8533, 8533_E),
  40. CPU_TYPE_ENTRY(8535, 8535),
  41. CPU_TYPE_ENTRY(8535, 8535_E),
  42. CPU_TYPE_ENTRY(8536, 8536),
  43. CPU_TYPE_ENTRY(8536, 8536_E),
  44. CPU_TYPE_ENTRY(8540, 8540),
  45. CPU_TYPE_ENTRY(8541, 8541),
  46. CPU_TYPE_ENTRY(8541, 8541_E),
  47. CPU_TYPE_ENTRY(8543, 8543),
  48. CPU_TYPE_ENTRY(8543, 8543_E),
  49. CPU_TYPE_ENTRY(8544, 8544),
  50. CPU_TYPE_ENTRY(8544, 8544_E),
  51. CPU_TYPE_ENTRY(8545, 8545),
  52. CPU_TYPE_ENTRY(8545, 8545_E),
  53. CPU_TYPE_ENTRY(8547, 8547_E),
  54. CPU_TYPE_ENTRY(8548, 8548),
  55. CPU_TYPE_ENTRY(8548, 8548_E),
  56. CPU_TYPE_ENTRY(8555, 8555),
  57. CPU_TYPE_ENTRY(8555, 8555_E),
  58. CPU_TYPE_ENTRY(8560, 8560),
  59. CPU_TYPE_ENTRY(8567, 8567),
  60. CPU_TYPE_ENTRY(8567, 8567_E),
  61. CPU_TYPE_ENTRY(8568, 8568),
  62. CPU_TYPE_ENTRY(8568, 8568_E),
  63. CPU_TYPE_ENTRY(8569, 8569),
  64. CPU_TYPE_ENTRY(8569, 8569_E),
  65. CPU_TYPE_ENTRY(8572, 8572),
  66. CPU_TYPE_ENTRY(8572, 8572_E),
  67. CPU_TYPE_ENTRY(P2020, P2020),
  68. CPU_TYPE_ENTRY(P2020, P2020_E),
  69. };
  70. struct cpu_type *identify_cpu(u32 ver)
  71. {
  72. int i;
  73. for (i = 0; i < ARRAY_SIZE(cpu_type_list); i++)
  74. if (cpu_type_list[i].soc_ver == ver)
  75. return &cpu_type_list[i];
  76. return NULL;
  77. }
  78. int checkcpu (void)
  79. {
  80. sys_info_t sysinfo;
  81. uint pvr, svr;
  82. uint fam;
  83. uint ver;
  84. uint major, minor;
  85. struct cpu_type *cpu;
  86. char buf1[32], buf2[32];
  87. #ifdef CONFIG_DDR_CLK_FREQ
  88. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  89. u32 ddr_ratio = ((gur->porpllsr) & MPC85xx_PORPLLSR_DDR_RATIO)
  90. >> MPC85xx_PORPLLSR_DDR_RATIO_SHIFT;
  91. #else
  92. u32 ddr_ratio = 0;
  93. #endif
  94. int i;
  95. svr = get_svr();
  96. ver = SVR_SOC_VER(svr);
  97. major = SVR_MAJ(svr);
  98. #ifdef CONFIG_MPC8536
  99. major &= 0x7; /* the msb of this nibble is a mfg code */
  100. #endif
  101. minor = SVR_MIN(svr);
  102. #if (CONFIG_NUM_CPUS > 1)
  103. volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC85xx_PIC_ADDR);
  104. printf("CPU%d: ", pic->whoami);
  105. #else
  106. puts("CPU: ");
  107. #endif
  108. cpu = identify_cpu(ver);
  109. if (cpu) {
  110. puts(cpu->name);
  111. if (IS_E_PROCESSOR(svr))
  112. puts("E");
  113. } else {
  114. puts("Unknown");
  115. }
  116. printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
  117. pvr = get_pvr();
  118. fam = PVR_FAM(pvr);
  119. ver = PVR_VER(pvr);
  120. major = PVR_MAJ(pvr);
  121. minor = PVR_MIN(pvr);
  122. printf("Core: ");
  123. switch (fam) {
  124. case PVR_FAM(PVR_85xx):
  125. puts("E500");
  126. break;
  127. default:
  128. puts("Unknown");
  129. break;
  130. }
  131. if (PVR_MEM(pvr) == 0x03)
  132. puts("MC");
  133. printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr);
  134. get_sys_info(&sysinfo);
  135. puts("Clock Configuration:");
  136. for (i = 0; i < CONFIG_NUM_CPUS; i++) {
  137. if (!(i & 3))
  138. printf ("\n ");
  139. printf("CPU%d:%-4s MHz, ",
  140. i,strmhz(buf1, sysinfo.freqProcessor[i]));
  141. }
  142. printf("\n CCB:%-4s MHz,\n", strmhz(buf1, sysinfo.freqSystemBus));
  143. switch (ddr_ratio) {
  144. case 0x0:
  145. printf(" DDR:%-4s MHz (%s MT/s data rate), ",
  146. strmhz(buf1, sysinfo.freqDDRBus/2),
  147. strmhz(buf2, sysinfo.freqDDRBus));
  148. break;
  149. case 0x7:
  150. printf(" DDR:%-4s MHz (%s MT/s data rate) (Synchronous), ",
  151. strmhz(buf1, sysinfo.freqDDRBus/2),
  152. strmhz(buf2, sysinfo.freqDDRBus));
  153. break;
  154. default:
  155. printf(" DDR:%-4s MHz (%s MT/s data rate) (Asynchronous), ",
  156. strmhz(buf1, sysinfo.freqDDRBus/2),
  157. strmhz(buf2, sysinfo.freqDDRBus));
  158. break;
  159. }
  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. #ifdef CONFIG_CPM2
  166. printf("CPM: %s MHz\n", strmhz(buf1, sysinfo.freqSystemBus));
  167. #endif
  168. #ifdef CONFIG_QE
  169. printf(" QE:%-4s MHz\n", strmhz(buf1, sysinfo.freqQE));
  170. #endif
  171. puts("L1: D-cache 32 kB enabled\n I-cache 32 kB enabled\n");
  172. return 0;
  173. }
  174. /* ------------------------------------------------------------------------- */
  175. int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
  176. {
  177. uint pvr;
  178. uint ver;
  179. unsigned long val, msr;
  180. pvr = get_pvr();
  181. ver = PVR_VER(pvr);
  182. if (ver & 1){
  183. /* e500 v2 core has reset control register */
  184. volatile unsigned int * rstcr;
  185. rstcr = (volatile unsigned int *)(CONFIG_SYS_IMMR + 0xE00B0);
  186. *rstcr = 0x2; /* HRESET_REQ */
  187. udelay(100);
  188. }
  189. /*
  190. * Fallthrough if the code above failed
  191. * Initiate hard reset in debug control register DBCR0
  192. * Make sure MSR[DE] = 1
  193. */
  194. msr = mfmsr ();
  195. msr |= MSR_DE;
  196. mtmsr (msr);
  197. val = mfspr(DBCR0);
  198. val |= 0x70000000;
  199. mtspr(DBCR0,val);
  200. return 1;
  201. }
  202. /*
  203. * Get timebase clock frequency
  204. */
  205. unsigned long get_tbclk (void)
  206. {
  207. return (gd->bus_clk + 4UL)/8UL;
  208. }
  209. #if defined(CONFIG_WATCHDOG)
  210. void
  211. watchdog_reset(void)
  212. {
  213. int re_enable = disable_interrupts();
  214. reset_85xx_watchdog();
  215. if (re_enable) enable_interrupts();
  216. }
  217. void
  218. reset_85xx_watchdog(void)
  219. {
  220. /*
  221. * Clear TSR(WIS) bit by writing 1
  222. */
  223. unsigned long val;
  224. val = mfspr(SPRN_TSR);
  225. val |= TSR_WIS;
  226. mtspr(SPRN_TSR, val);
  227. }
  228. #endif /* CONFIG_WATCHDOG */
  229. /*
  230. * Configures a UPM. The function requires the respective MxMR to be set
  231. * before calling this function. "size" is the number or entries, not a sizeof.
  232. */
  233. void upmconfig (uint upm, uint * table, uint size)
  234. {
  235. int i, mdr, mad, old_mad = 0;
  236. volatile u32 *mxmr;
  237. volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
  238. volatile u32 *brp,*orp;
  239. volatile u8* dummy = NULL;
  240. int upmmask;
  241. switch (upm) {
  242. case UPMA:
  243. mxmr = &lbc->mamr;
  244. upmmask = BR_MS_UPMA;
  245. break;
  246. case UPMB:
  247. mxmr = &lbc->mbmr;
  248. upmmask = BR_MS_UPMB;
  249. break;
  250. case UPMC:
  251. mxmr = &lbc->mcmr;
  252. upmmask = BR_MS_UPMC;
  253. break;
  254. default:
  255. printf("%s: Bad UPM index %d to configure\n", __FUNCTION__, upm);
  256. hang();
  257. }
  258. /* Find the address for the dummy write transaction */
  259. for (brp = &lbc->br0, orp = &lbc->or0, i = 0; i < 8;
  260. i++, brp += 2, orp += 2) {
  261. /* Look for a valid BR with selected UPM */
  262. if ((in_be32(brp) & (BR_V | BR_MSEL)) == (BR_V | upmmask)) {
  263. dummy = (volatile u8*)(in_be32(brp) & BR_BA);
  264. break;
  265. }
  266. }
  267. if (i == 8) {
  268. printf("Error: %s() could not find matching BR\n", __FUNCTION__);
  269. hang();
  270. }
  271. for (i = 0; i < size; i++) {
  272. /* 1 */
  273. out_be32(mxmr, (in_be32(mxmr) & 0x4fffffc0) | MxMR_OP_WARR | i);
  274. /* 2 */
  275. out_be32(&lbc->mdr, table[i]);
  276. /* 3 */
  277. mdr = in_be32(&lbc->mdr);
  278. /* 4 */
  279. *(volatile u8 *)dummy = 0;
  280. /* 5 */
  281. do {
  282. mad = in_be32(mxmr) & MxMR_MAD_MSK;
  283. } while (mad <= old_mad && !(!mad && i == (size-1)));
  284. old_mad = mad;
  285. }
  286. out_be32(mxmr, (in_be32(mxmr) & 0x4fffffc0) | MxMR_OP_NORM);
  287. }
  288. /*
  289. * Initializes on-chip ethernet controllers.
  290. * to override, implement board_eth_init()
  291. */
  292. int cpu_eth_init(bd_t *bis)
  293. {
  294. #if defined(CONFIG_ETHER_ON_FCC)
  295. fec_initialize(bis);
  296. #endif
  297. #if defined(CONFIG_UEC_ETH)
  298. uec_standard_init(bis);
  299. #endif
  300. #if defined(CONFIG_TSEC_ENET) || defined(CONFIG_MPC85XX_FEC)
  301. tsec_standard_init(bis);
  302. #endif
  303. return 0;
  304. }
  305. /*
  306. * Initializes on-chip MMC controllers.
  307. * to override, implement board_mmc_init()
  308. */
  309. int cpu_mmc_init(bd_t *bis)
  310. {
  311. #ifdef CONFIG_FSL_ESDHC
  312. return fsl_esdhc_mmc_init(bis);
  313. #else
  314. return 0;
  315. #endif
  316. }