cpu.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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 <asm/cache.h>
  33. #include <asm/io.h>
  34. DECLARE_GLOBAL_DATA_PTR;
  35. struct cpu_type cpu_type_list [] = {
  36. CPU_TYPE_ENTRY(8533, 8533),
  37. CPU_TYPE_ENTRY(8533, 8533_E),
  38. CPU_TYPE_ENTRY(8536, 8536),
  39. CPU_TYPE_ENTRY(8536, 8536_E),
  40. CPU_TYPE_ENTRY(8540, 8540),
  41. CPU_TYPE_ENTRY(8541, 8541),
  42. CPU_TYPE_ENTRY(8541, 8541_E),
  43. CPU_TYPE_ENTRY(8543, 8543),
  44. CPU_TYPE_ENTRY(8543, 8543_E),
  45. CPU_TYPE_ENTRY(8544, 8544),
  46. CPU_TYPE_ENTRY(8544, 8544_E),
  47. CPU_TYPE_ENTRY(8545, 8545),
  48. CPU_TYPE_ENTRY(8545, 8545_E),
  49. CPU_TYPE_ENTRY(8547, 8547_E),
  50. CPU_TYPE_ENTRY(8548, 8548),
  51. CPU_TYPE_ENTRY(8548, 8548_E),
  52. CPU_TYPE_ENTRY(8555, 8555),
  53. CPU_TYPE_ENTRY(8555, 8555_E),
  54. CPU_TYPE_ENTRY(8560, 8560),
  55. CPU_TYPE_ENTRY(8567, 8567),
  56. CPU_TYPE_ENTRY(8567, 8567_E),
  57. CPU_TYPE_ENTRY(8568, 8568),
  58. CPU_TYPE_ENTRY(8568, 8568_E),
  59. CPU_TYPE_ENTRY(8572, 8572),
  60. CPU_TYPE_ENTRY(8572, 8572_E),
  61. };
  62. struct cpu_type *identify_cpu(u32 ver)
  63. {
  64. int i;
  65. for (i = 0; i < ARRAY_SIZE(cpu_type_list); i++)
  66. if (cpu_type_list[i].soc_ver == ver)
  67. return &cpu_type_list[i];
  68. return NULL;
  69. }
  70. int checkcpu (void)
  71. {
  72. sys_info_t sysinfo;
  73. uint lcrr; /* local bus clock ratio register */
  74. uint clkdiv; /* clock divider portion of lcrr */
  75. uint pvr, svr;
  76. uint fam;
  77. uint ver;
  78. uint major, minor;
  79. struct cpu_type *cpu;
  80. #ifdef CONFIG_DDR_CLK_FREQ
  81. volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
  82. u32 ddr_ratio = ((gur->porpllsr) & 0x00003e00) >> 9;
  83. #else
  84. u32 ddr_ratio = 0;
  85. #endif
  86. svr = get_svr();
  87. ver = SVR_SOC_VER(svr);
  88. major = SVR_MAJ(svr);
  89. #ifdef CONFIG_MPC8536
  90. major &= 0x7; /* the msb of this nibble is a mfg code */
  91. #endif
  92. minor = SVR_MIN(svr);
  93. puts("CPU: ");
  94. cpu = identify_cpu(ver);
  95. if (cpu) {
  96. puts(cpu->name);
  97. if (IS_E_PROCESSOR(svr))
  98. puts("E");
  99. } else {
  100. puts("Unknown");
  101. }
  102. printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
  103. pvr = get_pvr();
  104. fam = PVR_FAM(pvr);
  105. ver = PVR_VER(pvr);
  106. major = PVR_MAJ(pvr);
  107. minor = PVR_MIN(pvr);
  108. printf("Core: ");
  109. switch (fam) {
  110. case PVR_FAM(PVR_85xx):
  111. puts("E500");
  112. break;
  113. default:
  114. puts("Unknown");
  115. break;
  116. }
  117. printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr);
  118. get_sys_info(&sysinfo);
  119. puts("Clock Configuration:\n");
  120. printf(" CPU:%4lu MHz, ", DIV_ROUND_UP(sysinfo.freqProcessor,1000000));
  121. printf("CCB:%4lu MHz,\n", DIV_ROUND_UP(sysinfo.freqSystemBus,1000000));
  122. switch (ddr_ratio) {
  123. case 0x0:
  124. printf(" DDR:%4lu MHz (%lu MT/s data rate), ",
  125. DIV_ROUND_UP(sysinfo.freqDDRBus,2000000), DIV_ROUND_UP(sysinfo.freqDDRBus,1000000));
  126. break;
  127. case 0x7:
  128. printf(" DDR:%4lu MHz (%lu MT/s data rate) (Synchronous), ",
  129. DIV_ROUND_UP(sysinfo.freqDDRBus, 2000000), DIV_ROUND_UP(sysinfo.freqDDRBus, 1000000));
  130. break;
  131. default:
  132. printf(" DDR:%4lu MHz (%lu MT/s data rate) (Asynchronous), ",
  133. DIV_ROUND_UP(sysinfo.freqDDRBus, 2000000), DIV_ROUND_UP(sysinfo.freqDDRBus,1000000));
  134. break;
  135. }
  136. #if defined(CFG_LBC_LCRR)
  137. lcrr = CFG_LBC_LCRR;
  138. #else
  139. {
  140. volatile ccsr_lbc_t *lbc = (void *)(CFG_MPC85xx_LBC_ADDR);
  141. lcrr = lbc->lcrr;
  142. }
  143. #endif
  144. clkdiv = lcrr & 0x0f;
  145. if (clkdiv == 2 || clkdiv == 4 || clkdiv == 8) {
  146. #if defined(CONFIG_MPC8548) || defined(CONFIG_MPC8544) || \
  147. defined(CONFIG_MPC8572) || defined(CONFIG_MPC8536)
  148. /*
  149. * Yes, the entire PQ38 family use the same
  150. * bit-representation for twice the clock divider values.
  151. */
  152. clkdiv *= 2;
  153. #endif
  154. printf("LBC:%4lu MHz\n",
  155. DIV_ROUND_UP(sysinfo.freqSystemBus, 1000000) / clkdiv);
  156. } else {
  157. printf("LBC: unknown (lcrr: 0x%08x)\n", lcrr);
  158. }
  159. #ifdef CONFIG_CPM2
  160. printf("CPM: %lu Mhz\n", sysinfo.freqSystemBus / 1000000);
  161. #endif
  162. puts("L1: D-cache 32 kB enabled\n I-cache 32 kB enabled\n");
  163. return 0;
  164. }
  165. /* ------------------------------------------------------------------------- */
  166. int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
  167. {
  168. uint pvr;
  169. uint ver;
  170. unsigned long val, msr;
  171. pvr = get_pvr();
  172. ver = PVR_VER(pvr);
  173. if (ver & 1){
  174. /* e500 v2 core has reset control register */
  175. volatile unsigned int * rstcr;
  176. rstcr = (volatile unsigned int *)(CFG_IMMR + 0xE00B0);
  177. *rstcr = 0x2; /* HRESET_REQ */
  178. udelay(100);
  179. }
  180. /*
  181. * Fallthrough if the code above failed
  182. * Initiate hard reset in debug control register DBCR0
  183. * Make sure MSR[DE] = 1
  184. */
  185. msr = mfmsr ();
  186. msr |= MSR_DE;
  187. mtmsr (msr);
  188. val = mfspr(DBCR0);
  189. val |= 0x70000000;
  190. mtspr(DBCR0,val);
  191. return 1;
  192. }
  193. /*
  194. * Get timebase clock frequency
  195. */
  196. unsigned long get_tbclk (void)
  197. {
  198. return (gd->bus_clk + 4UL)/8UL;
  199. }
  200. #if defined(CONFIG_WATCHDOG)
  201. void
  202. watchdog_reset(void)
  203. {
  204. int re_enable = disable_interrupts();
  205. reset_85xx_watchdog();
  206. if (re_enable) enable_interrupts();
  207. }
  208. void
  209. reset_85xx_watchdog(void)
  210. {
  211. /*
  212. * Clear TSR(WIS) bit by writing 1
  213. */
  214. unsigned long val;
  215. val = mfspr(SPRN_TSR);
  216. val |= TSR_WIS;
  217. mtspr(SPRN_TSR, val);
  218. }
  219. #endif /* CONFIG_WATCHDOG */
  220. #if defined(CONFIG_DDR_ECC)
  221. void dma_init(void) {
  222. volatile ccsr_dma_t *dma = (void *)(CFG_MPC85xx_DMA_ADDR);
  223. dma->satr0 = 0x02c40000;
  224. dma->datr0 = 0x02c40000;
  225. dma->sr0 = 0xfffffff; /* clear any errors */
  226. asm("sync; isync; msync");
  227. return;
  228. }
  229. uint dma_check(void) {
  230. volatile ccsr_dma_t *dma = (void *)(CFG_MPC85xx_DMA_ADDR);
  231. volatile uint status = dma->sr0;
  232. /* While the channel is busy, spin */
  233. while((status & 4) == 4) {
  234. status = dma->sr0;
  235. }
  236. /* clear MR0[CS] channel start bit */
  237. dma->mr0 &= 0x00000001;
  238. asm("sync;isync;msync");
  239. if (status != 0) {
  240. printf ("DMA Error: status = %x\n", status);
  241. }
  242. return status;
  243. }
  244. int dma_xfer(void *dest, uint count, void *src) {
  245. volatile ccsr_dma_t *dma = (void *)(CFG_MPC85xx_DMA_ADDR);
  246. dma->dar0 = (uint) dest;
  247. dma->sar0 = (uint) src;
  248. dma->bcr0 = count;
  249. dma->mr0 = 0xf000004;
  250. asm("sync;isync;msync");
  251. dma->mr0 = 0xf000005;
  252. asm("sync;isync;msync");
  253. return dma_check();
  254. }
  255. #endif
  256. /*
  257. * Configures a UPM. Currently, the loop fields in MxMR (RLF, WLF and TLF)
  258. * are hardcoded as "1"."size" is the number or entries, not a sizeof.
  259. */
  260. void upmconfig (uint upm, uint * table, uint size)
  261. {
  262. int i, mdr, mad, old_mad = 0;
  263. volatile u32 *mxmr;
  264. volatile ccsr_lbc_t *lbc = (void *)(CFG_MPC85xx_LBC_ADDR);
  265. int loopval = 0x00004440;
  266. volatile u32 *brp,*orp;
  267. volatile u8* dummy = NULL;
  268. int upmmask;
  269. switch (upm) {
  270. case UPMA:
  271. mxmr = &lbc->mamr;
  272. upmmask = BR_MS_UPMA;
  273. break;
  274. case UPMB:
  275. mxmr = &lbc->mbmr;
  276. upmmask = BR_MS_UPMB;
  277. break;
  278. case UPMC:
  279. mxmr = &lbc->mcmr;
  280. upmmask = BR_MS_UPMC;
  281. break;
  282. default:
  283. printf("%s: Bad UPM index %d to configure\n", __FUNCTION__, upm);
  284. hang();
  285. }
  286. /* Find the address for the dummy write transaction */
  287. for (brp = &lbc->br0, orp = &lbc->or0, i = 0; i < 8;
  288. i++, brp += 2, orp += 2) {
  289. /* Look for a valid BR with selected UPM */
  290. if ((in_be32(brp) & (BR_V | upmmask)) == (BR_V | upmmask)) {
  291. dummy = (volatile u8*)(in_be32(brp) >> BR_BA_SHIFT);
  292. break;
  293. }
  294. }
  295. if (i == 8) {
  296. printf("Error: %s() could not find matching BR\n", __FUNCTION__);
  297. hang();
  298. }
  299. for (i = 0; i < size; i++) {
  300. /* 1 */
  301. out_be32(mxmr, loopval | 0x10000000 | i); /* OP_WRITE */
  302. /* 2 */
  303. out_be32(&lbc->mdr, table[i]);
  304. /* 3 */
  305. mdr = in_be32(&lbc->mdr);
  306. /* 4 */
  307. *(volatile u8 *)dummy = 0;
  308. /* 5 */
  309. do {
  310. mad = in_be32(mxmr) & 0x3f;
  311. } while (mad <= old_mad && !(!mad && i == (size-1)));
  312. old_mad = mad;
  313. }
  314. out_be32(mxmr, loopval); /* OP_NORMAL */
  315. }
  316. /*
  317. * Initializes on-chip ethernet controllers.
  318. * to override, implement board_eth_init()
  319. */
  320. int cpu_eth_init(bd_t *bis)
  321. {
  322. #if defined(CONFIG_TSEC_ENET) || defined(CONFIG_MPC85xx_FEC)
  323. tsec_standard_init(bis);
  324. #endif
  325. return 0;
  326. }