cpu.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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. volatile immap_t *immap = (immap_t *) CFG_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_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(CFG_LBC_LCRR)
  92. lcrr = CFG_LBC_LCRR;
  93. #else
  94. {
  95. volatile immap_t *immap = (immap_t *) CFG_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 CFG_RESET_ADDRESS
  139. ulong addr = CFG_RESET_ADDRESS;
  140. #else
  141. /*
  142. * note: when CFG_MONITOR_BASE points to a RAM address,
  143. * CFG_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 CFG_RESET_ADDRESS.
  146. */
  147. ulong addr = CFG_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. }
  182. #endif /* CONFIG_WATCHDOG */
  183. #if defined(CONFIG_DDR_ECC)
  184. void
  185. dma_init(void)
  186. {
  187. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  188. volatile ccsr_dma_t *dma = &immap->im_dma;
  189. dma->satr0 = 0x00040000;
  190. dma->datr0 = 0x00040000;
  191. asm("sync; isync");
  192. }
  193. uint
  194. dma_check(void)
  195. {
  196. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  197. volatile ccsr_dma_t *dma = &immap->im_dma;
  198. volatile uint status = dma->sr0;
  199. /* While the channel is busy, spin */
  200. while ((status & 4) == 4) {
  201. status = dma->sr0;
  202. }
  203. if (status != 0) {
  204. printf("DMA Error: status = %x\n", status);
  205. }
  206. return status;
  207. }
  208. int
  209. dma_xfer(void *dest, uint count, void *src)
  210. {
  211. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  212. volatile ccsr_dma_t *dma = &immap->im_dma;
  213. dma->dar0 = (uint) dest;
  214. dma->sar0 = (uint) src;
  215. dma->bcr0 = count;
  216. dma->mr0 = 0xf000004;
  217. asm("sync;isync");
  218. dma->mr0 = 0xf000005;
  219. asm("sync;isync");
  220. return dma_check();
  221. }
  222. #endif /* CONFIG_DDR_ECC */
  223. #ifdef CONFIG_OF_FLAT_TREE
  224. void
  225. ft_cpu_setup(void *blob, bd_t *bd)
  226. {
  227. u32 *p;
  228. ulong clock;
  229. int len;
  230. clock = bd->bi_busfreq;
  231. p = ft_get_prop(blob, "/cpus/" OF_CPU "/bus-frequency", &len);
  232. if (p != NULL)
  233. *p = cpu_to_be32(clock);
  234. p = ft_get_prop(blob, "/" OF_SOC "/serial@4500/clock-frequency", &len);
  235. if (p != NULL)
  236. *p = cpu_to_be32(clock);
  237. p = ft_get_prop(blob, "/" OF_SOC "/serial@4600/clock-frequency", &len);
  238. if (p != NULL)
  239. *p = cpu_to_be32(clock);
  240. #if defined(CONFIG_TSEC1)
  241. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/mac-address", &len);
  242. if (p != NULL)
  243. memcpy(p, bd->bi_enetaddr, 6);
  244. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/local-mac-address", &len);
  245. if (p)
  246. memcpy(p, bd->bi_enetaddr, 6);
  247. #endif
  248. #if defined(CONFIG_TSEC2)
  249. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/mac-address", &len);
  250. if (p != NULL)
  251. memcpy(p, bd->bi_enet1addr, 6);
  252. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/local-mac-address", &len);
  253. if (p != NULL)
  254. memcpy(p, bd->bi_enet1addr, 6);
  255. #endif
  256. #if defined(CONFIG_TSEC3)
  257. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@26000/mac-address", &len);
  258. if (p != NULL)
  259. memcpy(p, bd->bi_enet2addr, 6);
  260. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@26000/local-mac-address", &len);
  261. if (p != NULL)
  262. memcpy(p, bd->bi_enet2addr, 6);
  263. #endif
  264. #if defined(CONFIG_TSEC4)
  265. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@27000/mac-address", &len);
  266. if (p != NULL)
  267. memcpy(p, bd->bi_enet3addr, 6);
  268. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@27000/local-mac-address", &len);
  269. if (p != NULL)
  270. memcpy(p, bd->bi_enet3addr, 6);
  271. #endif
  272. }
  273. #endif