cpu.c 6.6 KB

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