cpu.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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 checkcpu (void)
  37. {
  38. sys_info_t sysinfo;
  39. uint pvr, svr;
  40. uint ver;
  41. uint major, minor;
  42. uint lcrr; /* local bus clock ratio register */
  43. uint clkdiv; /* clock divider portion of lcrr */
  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. puts("E600");
  54. break;
  55. default:
  56. puts("Unknown");
  57. break;
  58. }
  59. printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr);
  60. svr = get_svr();
  61. ver = SVR_VER(svr);
  62. major = SVR_MAJ(svr);
  63. minor = SVR_MIN(svr);
  64. puts(" System: ");
  65. switch (ver) {
  66. case SVR_8641:
  67. puts("8641");
  68. break;
  69. case SVR_8641D:
  70. puts("8641D");
  71. break;
  72. default:
  73. puts("Unknown");
  74. break;
  75. }
  76. printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
  77. get_sys_info(&sysinfo);
  78. puts(" Clocks: ");
  79. printf("CPU:%4lu MHz, ", sysinfo.freqProcessor / 1000000);
  80. printf("MPX:%4lu MHz, ", sysinfo.freqSystemBus / 1000000);
  81. printf("DDR:%4lu MHz, ", sysinfo.freqSystemBus / 2000000);
  82. #if defined(CFG_LBC_LCRR)
  83. lcrr = CFG_LBC_LCRR;
  84. #else
  85. {
  86. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  87. volatile ccsr_lbc_t *lbc= &immap->im_lbc;
  88. lcrr = lbc->lcrr;
  89. }
  90. #endif
  91. clkdiv = lcrr & 0x0f;
  92. if (clkdiv == 2 || clkdiv == 4 || clkdiv == 8) {
  93. printf("LBC:%4lu MHz\n",
  94. sysinfo.freqSystemBus / 1000000 / clkdiv);
  95. } else {
  96. printf(" LBC: unknown (lcrr: 0x%08x)\n", lcrr);
  97. }
  98. puts(" L2: ");
  99. if (get_l2cr() & 0x80000000)
  100. puts("Enabled\n");
  101. else
  102. puts("Disabled\n");
  103. return 0;
  104. }
  105. static inline void
  106. soft_restart(unsigned long addr)
  107. {
  108. #ifndef CONFIG_MPC8641HPCN
  109. /* SRR0 has system reset vector, SRR1 has default MSR value */
  110. /* rfi restores MSR from SRR1 and sets the PC to the SRR0 value */
  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. mpc8641_reset_board(cmdtp, flag, argc, argv);
  153. #endif /* !CONFIG_MPC8641HPCN */
  154. while(1); /* not reached */
  155. }
  156. /*
  157. * Get timebase clock frequency
  158. */
  159. unsigned long get_tbclk(void)
  160. {
  161. sys_info_t sys_info;
  162. get_sys_info(&sys_info);
  163. return (sys_info.freqSystemBus + 3L) / 4L;
  164. }
  165. #if defined(CONFIG_WATCHDOG)
  166. void
  167. watchdog_reset(void)
  168. {
  169. }
  170. #endif /* CONFIG_WATCHDOG */
  171. #if defined(CONFIG_DDR_ECC)
  172. void dma_init(void)
  173. {
  174. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  175. volatile ccsr_dma_t *dma = &immap->im_dma;
  176. dma->satr0 = 0x00040000;
  177. dma->datr0 = 0x00040000;
  178. asm("sync; isync");
  179. }
  180. uint dma_check(void)
  181. {
  182. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  183. volatile ccsr_dma_t *dma = &immap->im_dma;
  184. volatile uint status = dma->sr0;
  185. /* While the channel is busy, spin */
  186. while((status & 4) == 4) {
  187. status = dma->sr0;
  188. }
  189. if (status != 0) {
  190. printf ("DMA Error: status = %x\n", status);
  191. }
  192. return status;
  193. }
  194. int dma_xfer(void *dest, uint count, void *src)
  195. {
  196. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  197. volatile ccsr_dma_t *dma = &immap->im_dma;
  198. dma->dar0 = (uint) dest;
  199. dma->sar0 = (uint) src;
  200. dma->bcr0 = count;
  201. dma->mr0 = 0xf000004;
  202. asm("sync;isync");
  203. dma->mr0 = 0xf000005;
  204. asm("sync;isync");
  205. return dma_check();
  206. }
  207. #endif /* CONFIG_DDR_ECC */
  208. #ifdef CONFIG_OF_FLAT_TREE
  209. void ft_cpu_setup(void *blob, bd_t *bd)
  210. {
  211. u32 *p;
  212. ulong clock;
  213. int len;
  214. clock = bd->bi_busfreq;
  215. p = ft_get_prop(blob, "/cpus/" OF_CPU "/bus-frequency", &len);
  216. if (p != NULL)
  217. *p = cpu_to_be32(clock);
  218. p = ft_get_prop(blob, "/" OF_SOC "/serial@4500/clock-frequency", &len);
  219. if (p != NULL)
  220. *p = cpu_to_be32(clock);
  221. p = ft_get_prop(blob, "/" OF_SOC "/serial@4600/clock-frequency", &len);
  222. if (p != NULL)
  223. *p = cpu_to_be32(clock);
  224. #if defined(CONFIG_MPC86XX_TSEC1)
  225. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/address", &len);
  226. memcpy(p, bd->bi_enetaddr, 6);
  227. #endif
  228. #if defined(CONFIG_MPC86XX_TSEC2)
  229. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/address", &len);
  230. memcpy(p, bd->bi_enet1addr, 6);
  231. #endif
  232. #if defined(CONFIG_MPC86XX_TSEC3)
  233. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@26000/address", &len);
  234. memcpy(p, bd->bi_enet2addr, 6);
  235. #endif
  236. #if defined(CONFIG_MPC86XX_TSEC4)
  237. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@27000/address", &len);
  238. memcpy(p, bd->bi_enet3addr, 6);
  239. #endif
  240. }
  241. #endif