cpu.c 9.6 KB

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