cpu.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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. #if defined(CONFIG_OF_FLAT_TREE)
  30. #include <ft_build.h>
  31. #endif
  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. puts("Freescale PowerPC\n");
  42. pvr = get_pvr();
  43. ver = PVR_VER(pvr);
  44. major = PVR_MAJ(pvr);
  45. minor = PVR_MIN(pvr);
  46. puts("CPU:\n");
  47. puts(" Core: ");
  48. switch (ver) {
  49. case PVR_VER(PVR_86xx):
  50. puts("E600");
  51. break;
  52. default:
  53. puts("Unknown");
  54. break;
  55. }
  56. printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr);
  57. svr = get_svr();
  58. ver = SVR_VER(svr);
  59. major = SVR_MAJ(svr);
  60. minor = SVR_MIN(svr);
  61. puts(" System: ");
  62. switch (ver) {
  63. case SVR_8641:
  64. if (SVR_SUBVER(svr) == 1) {
  65. puts("8641D");
  66. } else {
  67. puts("8641");
  68. }
  69. break;
  70. default:
  71. puts("Unknown");
  72. break;
  73. }
  74. printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
  75. get_sys_info(&sysinfo);
  76. puts(" Clocks: ");
  77. printf("CPU:%4lu MHz, ", sysinfo.freqProcessor / 1000000);
  78. printf("MPX:%4lu MHz, ", sysinfo.freqSystemBus / 1000000);
  79. printf("DDR:%4lu MHz, ", sysinfo.freqSystemBus / 2000000);
  80. #if defined(CFG_LBC_LCRR)
  81. lcrr = CFG_LBC_LCRR;
  82. #else
  83. {
  84. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  85. volatile ccsr_lbc_t *lbc = &immap->im_lbc;
  86. lcrr = lbc->lcrr;
  87. }
  88. #endif
  89. clkdiv = lcrr & 0x0f;
  90. if (clkdiv == 2 || clkdiv == 4 || clkdiv == 8) {
  91. printf("LBC:%4lu MHz\n",
  92. sysinfo.freqSystemBus / 1000000 / clkdiv);
  93. } else {
  94. printf(" LBC: unknown (lcrr: 0x%08x)\n", lcrr);
  95. }
  96. puts(" L2: ");
  97. if (get_l2cr() & 0x80000000)
  98. puts("Enabled\n");
  99. else
  100. puts("Disabled\n");
  101. return 0;
  102. }
  103. static inline void
  104. soft_restart(unsigned long addr)
  105. {
  106. #ifndef CONFIG_MPC8641HPCN
  107. /*
  108. * SRR0 has system reset vector, SRR1 has default MSR value
  109. * rfi restores MSR from SRR1 and sets the PC to the SRR0 value
  110. */
  111. __asm__ __volatile__ ("mtspr 26, %0" :: "r" (addr));
  112. __asm__ __volatile__ ("li 4, (1 << 6)" ::: "r4");
  113. __asm__ __volatile__ ("mtspr 27, 4");
  114. __asm__ __volatile__ ("rfi");
  115. #else /* CONFIG_MPC8641HPCN */
  116. out8(PIXIS_BASE + PIXIS_RST, 0);
  117. #endif /* !CONFIG_MPC8641HPCN */
  118. while (1) ; /* not reached */
  119. }
  120. /*
  121. * No generic way to do board reset. Simply call soft_reset.
  122. */
  123. void
  124. do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  125. {
  126. #ifndef CONFIG_MPC8641HPCN
  127. #ifdef CFG_RESET_ADDRESS
  128. ulong addr = CFG_RESET_ADDRESS;
  129. #else
  130. /*
  131. * note: when CFG_MONITOR_BASE points to a RAM address,
  132. * CFG_MONITOR_BASE - sizeof (ulong) is usually a valid
  133. * address. Better pick an address known to be invalid on your
  134. * system and assign it to CFG_RESET_ADDRESS.
  135. */
  136. ulong addr = CFG_MONITOR_BASE - sizeof(ulong);
  137. #endif
  138. /* flush and disable I/D cache */
  139. __asm__ __volatile__ ("mfspr 3, 1008" ::: "r3");
  140. __asm__ __volatile__ ("ori 5, 5, 0xcc00" ::: "r5");
  141. __asm__ __volatile__ ("ori 4, 3, 0xc00" ::: "r4");
  142. __asm__ __volatile__ ("andc 5, 3, 5" ::: "r5");
  143. __asm__ __volatile__ ("sync");
  144. __asm__ __volatile__ ("mtspr 1008, 4");
  145. __asm__ __volatile__ ("isync");
  146. __asm__ __volatile__ ("sync");
  147. __asm__ __volatile__ ("mtspr 1008, 5");
  148. __asm__ __volatile__ ("isync");
  149. __asm__ __volatile__ ("sync");
  150. soft_restart(addr);
  151. #else /* CONFIG_MPC8641HPCN */
  152. out8(PIXIS_BASE + PIXIS_RST, 0);
  153. #endif /* !CONFIG_MPC8641HPCN */
  154. while (1) ; /* not reached */
  155. }
  156. /*
  157. * Get timebase clock frequency
  158. */
  159. unsigned long
  160. get_tbclk(void)
  161. {
  162. sys_info_t sys_info;
  163. get_sys_info(&sys_info);
  164. return (sys_info.freqSystemBus + 3L) / 4L;
  165. }
  166. #if defined(CONFIG_WATCHDOG)
  167. void
  168. watchdog_reset(void)
  169. {
  170. }
  171. #endif /* CONFIG_WATCHDOG */
  172. #if defined(CONFIG_DDR_ECC)
  173. void
  174. dma_init(void)
  175. {
  176. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  177. volatile ccsr_dma_t *dma = &immap->im_dma;
  178. dma->satr0 = 0x00040000;
  179. dma->datr0 = 0x00040000;
  180. asm("sync; isync");
  181. }
  182. uint
  183. dma_check(void)
  184. {
  185. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  186. volatile ccsr_dma_t *dma = &immap->im_dma;
  187. volatile uint status = dma->sr0;
  188. /* While the channel is busy, spin */
  189. while ((status & 4) == 4) {
  190. status = dma->sr0;
  191. }
  192. if (status != 0) {
  193. printf("DMA Error: status = %x\n", status);
  194. }
  195. return status;
  196. }
  197. int
  198. dma_xfer(void *dest, uint count, void *src)
  199. {
  200. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  201. volatile ccsr_dma_t *dma = &immap->im_dma;
  202. dma->dar0 = (uint) dest;
  203. dma->sar0 = (uint) src;
  204. dma->bcr0 = count;
  205. dma->mr0 = 0xf000004;
  206. asm("sync;isync");
  207. dma->mr0 = 0xf000005;
  208. asm("sync;isync");
  209. return dma_check();
  210. }
  211. #endif /* CONFIG_DDR_ECC */
  212. #ifdef CONFIG_OF_FLAT_TREE
  213. void
  214. ft_cpu_setup(void *blob, bd_t *bd)
  215. {
  216. u32 *p;
  217. ulong clock;
  218. int len;
  219. clock = bd->bi_busfreq;
  220. p = ft_get_prop(blob, "/cpus/" OF_CPU "/bus-frequency", &len);
  221. if (p != NULL)
  222. *p = cpu_to_be32(clock);
  223. p = ft_get_prop(blob, "/" OF_SOC "/serial@4500/clock-frequency", &len);
  224. if (p != NULL)
  225. *p = cpu_to_be32(clock);
  226. p = ft_get_prop(blob, "/" OF_SOC "/serial@4600/clock-frequency", &len);
  227. if (p != NULL)
  228. *p = cpu_to_be32(clock);
  229. #if defined(CONFIG_MPC86XX_TSEC1)
  230. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/mac-address", &len);
  231. if (p != NULL)
  232. memcpy(p, bd->bi_enetaddr, 6);
  233. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/local-mac-address", &len);
  234. if (p)
  235. memcpy(p, bd->bi_enetaddr, 6);
  236. #endif
  237. #if defined(CONFIG_MPC86XX_TSEC2)
  238. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/mac-address", &len);
  239. if (p != NULL)
  240. memcpy(p, bd->bi_enet1addr, 6);
  241. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/local-mac-address", &len);
  242. if (p != NULL)
  243. memcpy(p, bd->bi_enet1addr, 6);
  244. #endif
  245. #if defined(CONFIG_MPC86XX_TSEC3)
  246. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@26000/mac-address", &len);
  247. if (p != NULL)
  248. memcpy(p, bd->bi_enet2addr, 6);
  249. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@26000/local-mac-address", &len);
  250. if (p != NULL)
  251. memcpy(p, bd->bi_enet2addr, 6);
  252. #endif
  253. #if defined(CONFIG_MPC86XX_TSEC4)
  254. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@27000/mac-address", &len);
  255. if (p != NULL)
  256. memcpy(p, bd->bi_enet3addr, 6);
  257. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@27000/local-mac-address", &len);
  258. if (p != NULL)
  259. memcpy(p, bd->bi_enet3addr, 6);
  260. #endif
  261. }
  262. #endif