cpu.c 9.2 KB

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