cpu.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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 <mpc86xx.h>
  29. #include <asm/fsl_law.h>
  30. #if defined(CONFIG_OF_FLAT_TREE)
  31. #include <ft_build.h>
  32. #endif
  33. int
  34. checkcpu(void)
  35. {
  36. sys_info_t sysinfo;
  37. uint pvr, svr;
  38. uint ver;
  39. uint major, minor;
  40. uint lcrr; /* local bus clock ratio register */
  41. uint clkdiv; /* clock divider portion of lcrr */
  42. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  43. volatile ccsr_gur_t *gur = &immap->im_gur;
  44. puts("Freescale PowerPC\n");
  45. pvr = get_pvr();
  46. ver = PVR_VER(pvr);
  47. major = PVR_MAJ(pvr);
  48. minor = PVR_MIN(pvr);
  49. puts("CPU:\n");
  50. puts(" Core: ");
  51. switch (ver) {
  52. case PVR_VER(PVR_86xx):
  53. {
  54. uint msscr0 = mfspr(MSSCR0);
  55. printf("E600 Core %d", (msscr0 & 0x20) ? 1 : 0 );
  56. if (gur->pordevsr & MPC86xx_PORDEVSR_CORE1TE)
  57. puts("\n Core1Translation Enabled");
  58. debug(" (MSSCR0=%x, PORDEVSR=%x)", msscr0, gur->pordevsr);
  59. }
  60. break;
  61. default:
  62. puts("Unknown");
  63. break;
  64. }
  65. printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr);
  66. svr = get_svr();
  67. ver = SVR_VER(svr);
  68. major = SVR_MAJ(svr);
  69. minor = SVR_MIN(svr);
  70. puts(" System: ");
  71. switch (ver) {
  72. case SVR_8641:
  73. if (SVR_SUBVER(svr) == 1) {
  74. puts("8641D");
  75. } else {
  76. puts("8641");
  77. }
  78. break;
  79. case SVR_8610:
  80. puts("8610");
  81. break;
  82. default:
  83. puts("Unknown");
  84. break;
  85. }
  86. printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
  87. get_sys_info(&sysinfo);
  88. puts(" Clocks: ");
  89. printf("CPU:%4lu MHz, ", sysinfo.freqProcessor / 1000000);
  90. printf("MPX:%4lu MHz, ", sysinfo.freqSystemBus / 1000000);
  91. printf("DDR:%4lu MHz, ", sysinfo.freqSystemBus / 2000000);
  92. #if defined(CFG_LBC_LCRR)
  93. lcrr = CFG_LBC_LCRR;
  94. #else
  95. {
  96. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  97. volatile ccsr_lbc_t *lbc = &immap->im_lbc;
  98. lcrr = lbc->lcrr;
  99. }
  100. #endif
  101. clkdiv = lcrr & 0x0f;
  102. if (clkdiv == 2 || clkdiv == 4 || clkdiv == 8) {
  103. printf("LBC:%4lu MHz\n",
  104. sysinfo.freqSystemBus / 1000000 / clkdiv);
  105. } else {
  106. printf(" LBC: unknown (lcrr: 0x%08x)\n", lcrr);
  107. }
  108. puts(" L2: ");
  109. if (get_l2cr() & 0x80000000)
  110. puts("Enabled\n");
  111. else
  112. puts("Disabled\n");
  113. return 0;
  114. }
  115. static inline void
  116. soft_restart(unsigned long addr)
  117. {
  118. #if !defined(CONFIG_MPC8641HPCN) && !defined(CONFIG_MPC8610HPCD)
  119. /*
  120. * SRR0 has system reset vector, SRR1 has default MSR value
  121. * rfi restores MSR from SRR1 and sets the PC to the SRR0 value
  122. */
  123. __asm__ __volatile__ ("mtspr 26, %0" :: "r" (addr));
  124. __asm__ __volatile__ ("li 4, (1 << 6)" ::: "r4");
  125. __asm__ __volatile__ ("mtspr 27, 4");
  126. __asm__ __volatile__ ("rfi");
  127. #else /* CONFIG_MPC8641HPCN */
  128. out8(PIXIS_BASE + PIXIS_RST, 0);
  129. #endif /* !CONFIG_MPC8641HPCN */
  130. while (1) ; /* not reached */
  131. }
  132. /*
  133. * No generic way to do board reset. Simply call soft_reset.
  134. */
  135. void
  136. do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  137. {
  138. #if !defined(CONFIG_MPC8641HPCN) && !defined(CONFIG_MPC8610HPCD)
  139. #ifdef CFG_RESET_ADDRESS
  140. ulong addr = CFG_RESET_ADDRESS;
  141. #else
  142. /*
  143. * note: when CFG_MONITOR_BASE points to a RAM address,
  144. * CFG_MONITOR_BASE - sizeof (ulong) is usually a valid
  145. * address. Better pick an address known to be invalid on your
  146. * system and assign it to CFG_RESET_ADDRESS.
  147. */
  148. ulong addr = CFG_MONITOR_BASE - sizeof(ulong);
  149. #endif
  150. /* flush and disable I/D cache */
  151. __asm__ __volatile__ ("mfspr 3, 1008" ::: "r3");
  152. __asm__ __volatile__ ("ori 5, 5, 0xcc00" ::: "r5");
  153. __asm__ __volatile__ ("ori 4, 3, 0xc00" ::: "r4");
  154. __asm__ __volatile__ ("andc 5, 3, 5" ::: "r5");
  155. __asm__ __volatile__ ("sync");
  156. __asm__ __volatile__ ("mtspr 1008, 4");
  157. __asm__ __volatile__ ("isync");
  158. __asm__ __volatile__ ("sync");
  159. __asm__ __volatile__ ("mtspr 1008, 5");
  160. __asm__ __volatile__ ("isync");
  161. __asm__ __volatile__ ("sync");
  162. soft_restart(addr);
  163. #else /* CONFIG_MPC8641HPCN */
  164. out8(PIXIS_BASE + PIXIS_RST, 0);
  165. #endif /* !CONFIG_MPC8641HPCN */
  166. while (1) ; /* not reached */
  167. }
  168. /*
  169. * Get timebase clock frequency
  170. */
  171. unsigned long
  172. get_tbclk(void)
  173. {
  174. sys_info_t sys_info;
  175. get_sys_info(&sys_info);
  176. return (sys_info.freqSystemBus + 3L) / 4L;
  177. }
  178. #if defined(CONFIG_WATCHDOG)
  179. void
  180. watchdog_reset(void)
  181. {
  182. }
  183. #endif /* CONFIG_WATCHDOG */
  184. #if defined(CONFIG_DDR_ECC)
  185. void
  186. dma_init(void)
  187. {
  188. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  189. volatile ccsr_dma_t *dma = &immap->im_dma;
  190. dma->satr0 = 0x00040000;
  191. dma->datr0 = 0x00040000;
  192. asm("sync; isync");
  193. }
  194. uint
  195. dma_check(void)
  196. {
  197. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  198. volatile ccsr_dma_t *dma = &immap->im_dma;
  199. volatile uint status = dma->sr0;
  200. /* While the channel is busy, spin */
  201. while ((status & 4) == 4) {
  202. status = dma->sr0;
  203. }
  204. if (status != 0) {
  205. printf("DMA Error: status = %x\n", status);
  206. }
  207. return status;
  208. }
  209. int
  210. dma_xfer(void *dest, uint count, void *src)
  211. {
  212. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  213. volatile ccsr_dma_t *dma = &immap->im_dma;
  214. dma->dar0 = (uint) dest;
  215. dma->sar0 = (uint) src;
  216. dma->bcr0 = count;
  217. dma->mr0 = 0xf000004;
  218. asm("sync;isync");
  219. dma->mr0 = 0xf000005;
  220. asm("sync;isync");
  221. return dma_check();
  222. }
  223. #endif /* CONFIG_DDR_ECC */
  224. #ifdef CONFIG_OF_FLAT_TREE
  225. void
  226. ft_cpu_setup(void *blob, bd_t *bd)
  227. {
  228. u32 *p;
  229. ulong clock;
  230. int len;
  231. clock = bd->bi_busfreq;
  232. p = ft_get_prop(blob, "/cpus/" OF_CPU "/bus-frequency", &len);
  233. if (p != NULL)
  234. *p = cpu_to_be32(clock);
  235. p = ft_get_prop(blob, "/" OF_SOC "/serial@4500/clock-frequency", &len);
  236. if (p != NULL)
  237. *p = cpu_to_be32(clock);
  238. p = ft_get_prop(blob, "/" OF_SOC "/serial@4600/clock-frequency", &len);
  239. if (p != NULL)
  240. *p = cpu_to_be32(clock);
  241. #if defined(CONFIG_TSEC1)
  242. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/mac-address", &len);
  243. if (p != NULL)
  244. memcpy(p, bd->bi_enetaddr, 6);
  245. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/local-mac-address", &len);
  246. if (p)
  247. memcpy(p, bd->bi_enetaddr, 6);
  248. #endif
  249. #if defined(CONFIG_TSEC2)
  250. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/mac-address", &len);
  251. if (p != NULL)
  252. memcpy(p, bd->bi_enet1addr, 6);
  253. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/local-mac-address", &len);
  254. if (p != NULL)
  255. memcpy(p, bd->bi_enet1addr, 6);
  256. #endif
  257. #if defined(CONFIG_TSEC3)
  258. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@26000/mac-address", &len);
  259. if (p != NULL)
  260. memcpy(p, bd->bi_enet2addr, 6);
  261. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@26000/local-mac-address", &len);
  262. if (p != NULL)
  263. memcpy(p, bd->bi_enet2addr, 6);
  264. #endif
  265. #if defined(CONFIG_TSEC4)
  266. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@27000/mac-address", &len);
  267. if (p != NULL)
  268. memcpy(p, bd->bi_enet3addr, 6);
  269. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@27000/local-mac-address", &len);
  270. if (p != NULL)
  271. memcpy(p, bd->bi_enet3addr, 6);
  272. #endif
  273. #endif /* CONFIG_OF_FLAT_TREE */
  274. /*
  275. * Print out the state of various machine registers.
  276. * Currently prints out LAWs and BR0/OR0
  277. */
  278. void mpc86xx_reginfo(void)
  279. {
  280. immap_t *immap = (immap_t *)CFG_IMMR;
  281. ccsr_lbc_t *lbc = &immap->im_lbc;
  282. print_laws();
  283. printf ("Local Bus Controller Registers\n"
  284. "\tBR0\t0x%08X\tOR0\t0x%08X \n", in_be32(&lbc->br0), in_be32(&lbc->or0));
  285. printf("\tBR1\t0x%08X\tOR1\t0x%08X \n", in_be32(&lbc->br1), in_be32(&lbc->or1));
  286. printf("\tBR2\t0x%08X\tOR2\t0x%08X \n", in_be32(&lbc->br2), in_be32(&lbc->or2));
  287. printf("\tBR3\t0x%08X\tOR3\t0x%08X \n", in_be32(&lbc->br3), in_be32(&lbc->or3));
  288. printf("\tBR4\t0x%08X\tOR4\t0x%08X \n", in_be32(&lbc->br4), in_be32(&lbc->or4));
  289. printf("\tBR5\t0x%08X\tOR5\t0x%08X \n", in_be32(&lbc->br5), in_be32(&lbc->or5));
  290. printf("\tBR6\t0x%08X\tOR6\t0x%08X \n", in_be32(&lbc->br6), in_be32(&lbc->or6));
  291. printf("\tBR7\t0x%08X\tOR7\t0x%08X \n", in_be32(&lbc->br7), in_be32(&lbc->or7));
  292. }