cpu.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. /*
  2. * Copyright 2006 Freescale Semiconductor
  3. * Jeff Brown
  4. * Srikanth Srinivasan (srikanth.srinivasan@freescale.com)
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <common.h>
  25. #include <watchdog.h>
  26. #include <command.h>
  27. #include <asm/cache.h>
  28. #include <asm/mmu.h>
  29. #include <mpc86xx.h>
  30. #include <tsec.h>
  31. #include <asm/fsl_law.h>
  32. int
  33. checkcpu(void)
  34. {
  35. sys_info_t sysinfo;
  36. uint pvr, svr;
  37. uint ver;
  38. uint major, minor;
  39. uint lcrr; /* local bus clock ratio register */
  40. uint clkdiv; /* clock divider portion of lcrr */
  41. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  42. volatile ccsr_gur_t *gur = &immap->im_gur;
  43. puts("Freescale PowerPC\n");
  44. pvr = get_pvr();
  45. ver = PVR_VER(pvr);
  46. major = PVR_MAJ(pvr);
  47. minor = PVR_MIN(pvr);
  48. puts("CPU:\n");
  49. puts(" Core: ");
  50. switch (ver) {
  51. case PVR_VER(PVR_86xx):
  52. {
  53. uint msscr0 = mfspr(MSSCR0);
  54. printf("E600 Core %d", (msscr0 & 0x20) ? 1 : 0 );
  55. if (gur->pordevsr & MPC86xx_PORDEVSR_CORE1TE)
  56. puts("\n Core1Translation Enabled");
  57. debug(" (MSSCR0=%x, PORDEVSR=%x)", msscr0, gur->pordevsr);
  58. }
  59. break;
  60. default:
  61. puts("Unknown");
  62. break;
  63. }
  64. printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr);
  65. svr = get_svr();
  66. ver = SVR_SOC_VER(svr);
  67. major = SVR_MAJ(svr);
  68. minor = SVR_MIN(svr);
  69. puts(" System: ");
  70. switch (ver) {
  71. case SVR_8641:
  72. if (SVR_SUBVER(svr) == 1) {
  73. puts("8641D");
  74. } else {
  75. puts("8641");
  76. }
  77. break;
  78. case SVR_8610:
  79. puts("8610");
  80. break;
  81. default:
  82. puts("Unknown");
  83. break;
  84. }
  85. printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
  86. get_sys_info(&sysinfo);
  87. puts(" Clocks: ");
  88. printf("CPU:%4lu MHz, ", sysinfo.freqProcessor / 1000000);
  89. printf("MPX:%4lu MHz, ", sysinfo.freqSystemBus / 1000000);
  90. printf("DDR:%4lu MHz, ", sysinfo.freqSystemBus / 2000000);
  91. #if defined(CONFIG_SYS_LBC_LCRR)
  92. lcrr = CONFIG_SYS_LBC_LCRR;
  93. #else
  94. {
  95. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  96. volatile ccsr_lbc_t *lbc = &immap->im_lbc;
  97. lcrr = lbc->lcrr;
  98. }
  99. #endif
  100. clkdiv = lcrr & 0x0f;
  101. if (clkdiv == 2 || clkdiv == 4 || clkdiv == 8) {
  102. printf("LBC:%4lu MHz\n",
  103. sysinfo.freqSystemBus / 1000000 / clkdiv);
  104. } else {
  105. printf(" LBC: unknown (lcrr: 0x%08x)\n", lcrr);
  106. }
  107. puts(" L2: ");
  108. if (get_l2cr() & 0x80000000)
  109. puts("Enabled\n");
  110. else
  111. puts("Disabled\n");
  112. return 0;
  113. }
  114. static inline void
  115. soft_restart(unsigned long addr)
  116. {
  117. #if !defined(CONFIG_MPC8641HPCN) && !defined(CONFIG_MPC8610HPCD)
  118. /*
  119. * SRR0 has system reset vector, SRR1 has default MSR value
  120. * rfi restores MSR from SRR1 and sets the PC to the SRR0 value
  121. */
  122. __asm__ __volatile__ ("mtspr 26, %0" :: "r" (addr));
  123. __asm__ __volatile__ ("li 4, (1 << 6)" ::: "r4");
  124. __asm__ __volatile__ ("mtspr 27, 4");
  125. __asm__ __volatile__ ("rfi");
  126. #else /* CONFIG_MPC8641HPCN */
  127. out8(PIXIS_BASE + PIXIS_RST, 0);
  128. #endif /* !CONFIG_MPC8641HPCN */
  129. while (1) ; /* not reached */
  130. }
  131. /*
  132. * No generic way to do board reset. Simply call soft_reset.
  133. */
  134. void
  135. do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  136. {
  137. #if !defined(CONFIG_MPC8641HPCN) && !defined(CONFIG_MPC8610HPCD)
  138. #ifdef CONFIG_SYS_RESET_ADDRESS
  139. ulong addr = CONFIG_SYS_RESET_ADDRESS;
  140. #else
  141. /*
  142. * note: when CONFIG_SYS_MONITOR_BASE points to a RAM address,
  143. * CONFIG_SYS_MONITOR_BASE - sizeof (ulong) is usually a valid
  144. * address. Better pick an address known to be invalid on your
  145. * system and assign it to CONFIG_SYS_RESET_ADDRESS.
  146. */
  147. ulong addr = CONFIG_SYS_MONITOR_BASE - sizeof(ulong);
  148. #endif
  149. /* flush and disable I/D cache */
  150. __asm__ __volatile__ ("mfspr 3, 1008" ::: "r3");
  151. __asm__ __volatile__ ("ori 5, 5, 0xcc00" ::: "r5");
  152. __asm__ __volatile__ ("ori 4, 3, 0xc00" ::: "r4");
  153. __asm__ __volatile__ ("andc 5, 3, 5" ::: "r5");
  154. __asm__ __volatile__ ("sync");
  155. __asm__ __volatile__ ("mtspr 1008, 4");
  156. __asm__ __volatile__ ("isync");
  157. __asm__ __volatile__ ("sync");
  158. __asm__ __volatile__ ("mtspr 1008, 5");
  159. __asm__ __volatile__ ("isync");
  160. __asm__ __volatile__ ("sync");
  161. soft_restart(addr);
  162. #else /* CONFIG_MPC8641HPCN */
  163. out8(PIXIS_BASE + PIXIS_RST, 0);
  164. #endif /* !CONFIG_MPC8641HPCN */
  165. while (1) ; /* not reached */
  166. }
  167. /*
  168. * Get timebase clock frequency
  169. */
  170. unsigned long
  171. get_tbclk(void)
  172. {
  173. sys_info_t sys_info;
  174. get_sys_info(&sys_info);
  175. return (sys_info.freqSystemBus + 3L) / 4L;
  176. }
  177. #if defined(CONFIG_WATCHDOG)
  178. void
  179. watchdog_reset(void)
  180. {
  181. #if defined(CONFIG_MPC8610)
  182. /*
  183. * This actually feed the hard enabled watchdog.
  184. */
  185. volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  186. volatile ccsr_wdt_t *wdt = &immap->im_wdt;
  187. volatile ccsr_gur_t *gur = &immap->im_gur;
  188. u32 tmp = gur->pordevsr;
  189. if (tmp & 0x4000) {
  190. wdt->swsrr = 0x556c;
  191. wdt->swsrr = 0xaa39;
  192. }
  193. #endif
  194. }
  195. #endif /* CONFIG_WATCHDOG */
  196. #if defined(CONFIG_DDR_ECC)
  197. void
  198. dma_init(void)
  199. {
  200. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  201. volatile ccsr_dma_t *dma = &immap->im_dma;
  202. dma->satr0 = 0x00040000;
  203. dma->datr0 = 0x00040000;
  204. asm("sync; isync");
  205. }
  206. uint
  207. dma_check(void)
  208. {
  209. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  210. volatile ccsr_dma_t *dma = &immap->im_dma;
  211. volatile uint status = dma->sr0;
  212. /* While the channel is busy, spin */
  213. while ((status & 4) == 4) {
  214. status = dma->sr0;
  215. }
  216. if (status != 0) {
  217. printf("DMA Error: status = %x\n", status);
  218. }
  219. return status;
  220. }
  221. int
  222. dma_xfer(void *dest, uint count, void *src)
  223. {
  224. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  225. volatile ccsr_dma_t *dma = &immap->im_dma;
  226. dma->dar0 = (uint) dest;
  227. dma->sar0 = (uint) src;
  228. dma->bcr0 = count;
  229. dma->mr0 = 0xf000004;
  230. asm("sync;isync");
  231. dma->mr0 = 0xf000005;
  232. asm("sync;isync");
  233. return dma_check();
  234. }
  235. #endif /* CONFIG_DDR_ECC */
  236. /*
  237. * Print out the state of various machine registers.
  238. * Currently prints out LAWs, BR0/OR0, and BATs
  239. */
  240. void mpc86xx_reginfo(void)
  241. {
  242. immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  243. ccsr_lbc_t *lbc = &immap->im_lbc;
  244. print_bats();
  245. print_laws();
  246. printf ("Local Bus Controller Registers\n"
  247. "\tBR0\t0x%08X\tOR0\t0x%08X \n", in_be32(&lbc->br0), in_be32(&lbc->or0));
  248. printf("\tBR1\t0x%08X\tOR1\t0x%08X \n", in_be32(&lbc->br1), in_be32(&lbc->or1));
  249. printf("\tBR2\t0x%08X\tOR2\t0x%08X \n", in_be32(&lbc->br2), in_be32(&lbc->or2));
  250. printf("\tBR3\t0x%08X\tOR3\t0x%08X \n", in_be32(&lbc->br3), in_be32(&lbc->or3));
  251. printf("\tBR4\t0x%08X\tOR4\t0x%08X \n", in_be32(&lbc->br4), in_be32(&lbc->or4));
  252. printf("\tBR5\t0x%08X\tOR5\t0x%08X \n", in_be32(&lbc->br5), in_be32(&lbc->or5));
  253. printf("\tBR6\t0x%08X\tOR6\t0x%08X \n", in_be32(&lbc->br6), in_be32(&lbc->or6));
  254. printf("\tBR7\t0x%08X\tOR7\t0x%08X \n", in_be32(&lbc->br7), in_be32(&lbc->or7));
  255. }
  256. /*
  257. * Initializes on-chip ethernet controllers.
  258. * to override, implement board_eth_init()
  259. */
  260. int cpu_eth_init(bd_t *bis)
  261. {
  262. #if defined(CONFIG_TSEC_ENET)
  263. tsec_standard_init(bis);
  264. #endif
  265. return 0;
  266. }