cpu.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. /*
  2. * Copyright 2004 Freescale Semiconductor
  3. * Jeff Brown (jeffrey@freescale.com)
  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. #include "../board/mpc8641hpcn/pixis.h"
  33. int 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. printf(" 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. puts("8641");
  65. break;
  66. case SVR_8641D:
  67. puts("8641D");
  68. break;
  69. default:
  70. puts("Unknown");
  71. break;
  72. }
  73. printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
  74. get_sys_info(&sysinfo);
  75. puts(" Clocks: ");
  76. printf("CPU:%4lu MHz, ", sysinfo.freqProcessor / 1000000);
  77. printf("MPX:%4lu MHz, ", sysinfo.freqSystemBus / 1000000);
  78. printf("DDR:%4lu MHz, ", sysinfo.freqSystemBus / 2000000);
  79. #if defined(CFG_LBC_LCRR)
  80. lcrr = CFG_LBC_LCRR;
  81. #else
  82. {
  83. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  84. volatile ccsr_lbc_t *lbc= &immap->im_lbc;
  85. lcrr = lbc->lcrr;
  86. }
  87. #endif
  88. clkdiv = lcrr & 0x0f;
  89. if (clkdiv == 2 || clkdiv == 4 || clkdiv == 8) {
  90. printf("LBC:%4lu MHz\n",
  91. sysinfo.freqSystemBus / 1000000 / clkdiv);
  92. } else {
  93. printf(" LBC: unknown (lcrr: 0x%08x)\n", lcrr);
  94. }
  95. printf(" L2: ");
  96. if (get_l2cr() & 0x80000000)
  97. printf("Enabled\n");
  98. else
  99. printf("Disabled\n");
  100. return 0;
  101. }
  102. static inline void
  103. soft_restart(unsigned long addr)
  104. {
  105. #ifndef CONFIG_MPC8641HPCN
  106. /* SRR0 has system reset vector, SRR1 has default MSR value */
  107. /* rfi restores MSR from SRR1 and sets the PC to the SRR0 value */
  108. __asm__ __volatile__ ("mtspr 26, %0" :: "r" (addr));
  109. __asm__ __volatile__ ("li 4, (1 << 6)" ::: "r4");
  110. __asm__ __volatile__ ("mtspr 27, 4");
  111. __asm__ __volatile__ ("rfi");
  112. #else /* CONFIG_MPC8641HPCN */
  113. out8(PIXIS_BASE+PIXIS_RST,0);
  114. #endif /* !CONFIG_MPC8641HPCN */
  115. while(1); /* not reached */
  116. }
  117. /*
  118. * No generic way to do board reset. Simply call soft_reset.
  119. */
  120. void
  121. do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  122. {
  123. char cmd;
  124. ulong addr, val;
  125. ulong corepll;
  126. #ifdef CFG_RESET_ADDRESS
  127. addr = CFG_RESET_ADDRESS;
  128. #else
  129. /*
  130. * note: when CFG_MONITOR_BASE points to a RAM address,
  131. * CFG_MONITOR_BASE - sizeof (ulong) is usually a valid
  132. * address. Better pick an address known to be invalid on your
  133. * system and assign it to CFG_RESET_ADDRESS.
  134. */
  135. addr = CFG_MONITOR_BASE - sizeof (ulong);
  136. #endif
  137. #ifndef CONFIG_MPC8641HPCN
  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. if (argc > 1) {
  153. cmd = argv[1][1];
  154. switch(cmd) {
  155. case 'f': /* reset with frequency changed */
  156. if (argc < 5)
  157. goto my_usage;
  158. read_from_px_regs(0);
  159. val = set_px_sysclk(simple_strtoul(argv[2],NULL,10));
  160. corepll = strfractoint(argv[3]);
  161. val = val + set_px_corepll(corepll);
  162. val = val + set_px_mpxpll(simple_strtoul(argv[4],
  163. NULL, 10));
  164. if (val == 3) {
  165. printf("Setting registers VCFGEN0 and VCTL\n");
  166. read_from_px_regs(1);
  167. printf("Resetting board with values from VSPEED0, VSPEED1, VCLKH, and VCLKL ....\n");
  168. set_px_go();
  169. } else
  170. goto my_usage;
  171. while (1); /* Not reached */
  172. case 'l':
  173. if (argv[2][1] == 'f') {
  174. read_from_px_regs(0);
  175. read_from_px_regs_altbank(0);
  176. /* reset with frequency changed */
  177. val = set_px_sysclk(simple_strtoul(argv[3],NULL,10));
  178. corepll = strfractoint(argv[4]);
  179. val = val + set_px_corepll(corepll);
  180. val = val + set_px_mpxpll(simple_strtoul(argv[5],NULL,10));
  181. if (val == 3) {
  182. printf("Setting registers VCFGEN0, VCFGEN1, VBOOT, and VCTL\n");
  183. set_altbank();
  184. read_from_px_regs(1);
  185. read_from_px_regs_altbank(1);
  186. printf("Enabling watchdog timer on the FPGA and resetting board with values from VSPEED0, VSPEED1, VCLKH, and VCLKL to boot from the other bank ....\n");
  187. set_px_go_with_watchdog();
  188. } else
  189. goto my_usage;
  190. while(1); /* Not reached */
  191. } else if(argv[2][1] == 'd'){
  192. /* Reset from next bank without changing frequencies but with watchdog timer enabled */
  193. read_from_px_regs(0);
  194. read_from_px_regs_altbank(0);
  195. printf("Setting registers VCFGEN1, VBOOT, and VCTL\n");
  196. set_altbank();
  197. read_from_px_regs_altbank(1);
  198. printf("Enabling watchdog timer on the FPGA and resetting board to boot from the other bank....\n");
  199. set_px_go_with_watchdog();
  200. while(1); /* Not reached */
  201. } else {
  202. /* Reset from next bank without changing frequency and without watchdog timer enabled */
  203. read_from_px_regs(0);
  204. read_from_px_regs_altbank(0);
  205. if(argc > 2)
  206. goto my_usage;
  207. printf("Setting registers VCFGNE1, VBOOT, and VCTL\n");
  208. set_altbank();
  209. read_from_px_regs_altbank(1);
  210. printf("Resetting board to boot from the other bank....\n");
  211. set_px_go();
  212. }
  213. default:
  214. goto my_usage;
  215. }
  216. my_usage:
  217. printf("\nUsage: reset cf <SYSCLK freq> <COREPLL ratio> <MPXPLL ratio>\n");
  218. printf(" reset altbank [cf <SYSCLK freq> <COREPLL ratio> <MPXPLL ratio>]\n");
  219. printf("For example: reset cf 40 2.5 10\n");
  220. printf("See MPC8641HPCN Design Workbook for valid values of command line parameters.\n");
  221. return;
  222. } else
  223. out8(PIXIS_BASE+PIXIS_RST,0);
  224. #endif /* !CONFIG_MPC8641HPCN */
  225. while(1); /* not reached */
  226. }
  227. /*
  228. * Get timebase clock frequency
  229. */
  230. unsigned long get_tbclk(void)
  231. {
  232. sys_info_t sys_info;
  233. get_sys_info(&sys_info);
  234. return (sys_info.freqSystemBus + 3L) / 4L;
  235. }
  236. #if defined(CONFIG_WATCHDOG)
  237. void
  238. watchdog_reset(void)
  239. {
  240. }
  241. #endif /* CONFIG_WATCHDOG */
  242. #if defined(CONFIG_DDR_ECC)
  243. void dma_init(void)
  244. {
  245. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  246. volatile ccsr_dma_t *dma = &immap->im_dma;
  247. dma->satr0 = 0x00040000;
  248. dma->datr0 = 0x00040000;
  249. asm("sync; isync");
  250. }
  251. uint dma_check(void)
  252. {
  253. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  254. volatile ccsr_dma_t *dma = &immap->im_dma;
  255. volatile uint status = dma->sr0;
  256. /* While the channel is busy, spin */
  257. while((status & 4) == 4) {
  258. status = dma->sr0;
  259. }
  260. if (status != 0) {
  261. printf ("DMA Error: status = %x\n", status);
  262. }
  263. return status;
  264. }
  265. int dma_xfer(void *dest, uint count, void *src)
  266. {
  267. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  268. volatile ccsr_dma_t *dma = &immap->im_dma;
  269. dma->dar0 = (uint) dest;
  270. dma->sar0 = (uint) src;
  271. dma->bcr0 = count;
  272. dma->mr0 = 0xf000004;
  273. asm("sync;isync");
  274. dma->mr0 = 0xf000005;
  275. asm("sync;isync");
  276. return dma_check();
  277. }
  278. #endif /* CONFIG_DDR_ECC */
  279. #ifdef CONFIG_OF_FLAT_TREE
  280. void ft_cpu_setup(void *blob, bd_t *bd)
  281. {
  282. u32 *p;
  283. ulong clock;
  284. int len;
  285. clock = bd->bi_busfreq;
  286. p = ft_get_prop(blob, "/cpus/" OF_CPU "/bus-frequency", &len);
  287. if (p != NULL)
  288. *p = cpu_to_be32(clock);
  289. p = ft_get_prop(blob, "/" OF_SOC "/serial@4500/clock-frequency", &len);
  290. if (p != NULL)
  291. *p = cpu_to_be32(clock);
  292. p = ft_get_prop(blob, "/" OF_SOC "/serial@4600/clock-frequency", &len);
  293. if (p != NULL)
  294. *p = cpu_to_be32(clock);
  295. #if defined(CONFIG_MPC86XX_TSEC1)
  296. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/address", &len);
  297. memcpy(p, bd->bi_enetaddr, 6);
  298. #endif
  299. #if defined(CONFIG_MPC86XX_TSEC2)
  300. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/address", &len);
  301. memcpy(p, bd->bi_enet1addr, 6);
  302. #endif
  303. #if defined(CONFIG_MPC86XX_TSEC3)
  304. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@26000/address", &len);
  305. memcpy(p, bd->bi_enet2addr, 6);
  306. #endif
  307. #if defined(CONFIG_MPC86XX_TSEC4)
  308. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@27000/address", &len);
  309. memcpy(p, bd->bi_enet3addr, 6);
  310. #endif
  311. }
  312. #endif