cpu.c 8.8 KB

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