cpu.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. /*
  2. * (C) Copyright 2000-2006
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. /*
  8. * CPU specific code for the MPC825x / MPC826x / MPC827x / MPC828x
  9. *
  10. * written or collected and sometimes rewritten by
  11. * Magnus Damm <damm@bitsmart.com>
  12. *
  13. * modified by
  14. * Wolfgang Denk <wd@denx.de>
  15. *
  16. * modified for 8260 by
  17. * Murray Jensen <Murray.Jensen@cmst.csiro.au>
  18. *
  19. * added 8260 masks by
  20. * Marius Groeger <mag@sysgo.de>
  21. *
  22. * added HiP7 (824x/827x/8280) processors support by
  23. * Yuli Barcohen <yuli@arabellasw.com>
  24. */
  25. #include <common.h>
  26. #include <watchdog.h>
  27. #include <command.h>
  28. #include <mpc8260.h>
  29. #include <netdev.h>
  30. #include <asm/processor.h>
  31. #include <asm/cpm_8260.h>
  32. #if defined(CONFIG_OF_LIBFDT)
  33. #include <libfdt.h>
  34. #include <fdt_support.h>
  35. #endif
  36. DECLARE_GLOBAL_DATA_PTR;
  37. #if defined(CONFIG_GET_CPU_STR_F)
  38. extern int get_cpu_str_f (char *buf);
  39. #endif
  40. int checkcpu (void)
  41. {
  42. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  43. ulong clock = gd->cpu_clk;
  44. uint pvr = get_pvr ();
  45. uint immr, rev, m, k;
  46. char buf[32];
  47. puts ("CPU: ");
  48. switch (pvr) {
  49. case PVR_8260:
  50. case PVR_8260_HIP3:
  51. k = 3;
  52. break;
  53. case PVR_8260_HIP4:
  54. k = 4;
  55. break;
  56. case PVR_8260_HIP7R1:
  57. case PVR_8260_HIP7RA:
  58. case PVR_8260_HIP7:
  59. k = 7;
  60. break;
  61. default:
  62. return -1; /* whoops! not an MPC8260 */
  63. }
  64. rev = pvr & 0xff;
  65. immr = immap->im_memctl.memc_immr;
  66. if ((immr & IMMR_ISB_MSK) != CONFIG_SYS_IMMR)
  67. return -1; /* whoops! someone moved the IMMR */
  68. #if defined(CONFIG_GET_CPU_STR_F)
  69. get_cpu_str_f (buf);
  70. printf ("%s (HiP%d Rev %02x, Mask ", buf, k, rev);
  71. #else
  72. printf (CPU_ID_STR " (HiP%d Rev %02x, Mask ", k, rev);
  73. #endif
  74. /*
  75. * the bottom 16 bits of the immr are the Part Number and Mask Number
  76. * (4-34); the 16 bits at PROFF_REVNUM (0x8af0) in dual port ram is the
  77. * RISC Microcode Revision Number (13-10).
  78. * For the 8260, Motorola doesn't include the Microcode Revision
  79. * in the mask.
  80. */
  81. m = immr & (IMMR_PARTNUM_MSK | IMMR_MASKNUM_MSK);
  82. k = immap->im_dprambase16[PROFF_REVNUM / sizeof(u16)];
  83. switch (m) {
  84. case 0x0000:
  85. puts ("0.2 2J24M");
  86. break;
  87. case 0x0010:
  88. puts ("A.0 K22A");
  89. break;
  90. case 0x0011:
  91. puts ("A.1 1K22A-XC");
  92. break;
  93. case 0x0001:
  94. puts ("B.1 1K23A");
  95. break;
  96. case 0x0021:
  97. puts ("B.2 2K23A-XC");
  98. break;
  99. case 0x0023:
  100. puts ("B.3 3K23A");
  101. break;
  102. case 0x0024:
  103. puts ("C.2 6K23A");
  104. break;
  105. case 0x0060:
  106. puts ("A.0(A) 2K25A");
  107. break;
  108. case 0x0062:
  109. puts ("B.1 4K25A");
  110. break;
  111. case 0x0064:
  112. puts ("C.0 5K25A");
  113. break;
  114. case 0x0A00:
  115. puts ("0.0 0K49M");
  116. break;
  117. case 0x0A01:
  118. puts ("0.1 1K49M");
  119. break;
  120. case 0x0A10:
  121. puts ("1.0 1K49M");
  122. break;
  123. case 0x0C00:
  124. puts ("0.0 0K50M");
  125. break;
  126. case 0x0C10:
  127. puts ("1.0 1K50M");
  128. break;
  129. case 0x0D00:
  130. puts ("0.0 0K50M");
  131. break;
  132. case 0x0D10:
  133. puts ("1.0 1K50M");
  134. break;
  135. default:
  136. printf ("unknown [immr=0x%04x,k=0x%04x]", m, k);
  137. break;
  138. }
  139. printf (") at %s MHz\n", strmhz (buf, clock));
  140. return 0;
  141. }
  142. /* ------------------------------------------------------------------------- */
  143. /* configures a UPM by writing into the UPM RAM array */
  144. /* uses bank 11 and a dummy physical address (=BRx_BA_MSK) */
  145. /* NOTE: the physical address chosen must not overlap into any other area */
  146. /* mapped by the memory controller because bank 11 has the lowest priority */
  147. void upmconfig (uint upm, uint * table, uint size)
  148. {
  149. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  150. volatile memctl8260_t *memctl = &immap->im_memctl;
  151. volatile uchar *dummy = (uchar *) BRx_BA_MSK; /* set all BA bits */
  152. uint i;
  153. /* first set up bank 11 to reference the correct UPM at a dummy address */
  154. memctl->memc_or11 = ORxU_AM_MSK; /* set all AM bits */
  155. switch (upm) {
  156. case UPMA:
  157. memctl->memc_br11 =
  158. ((uint)dummy & BRx_BA_MSK) | BRx_PS_32 | BRx_MS_UPMA |
  159. BRx_V;
  160. memctl->memc_mamr = MxMR_OP_WARR;
  161. break;
  162. case UPMB:
  163. memctl->memc_br11 =
  164. ((uint)dummy & BRx_BA_MSK) | BRx_PS_32 | BRx_MS_UPMB |
  165. BRx_V;
  166. memctl->memc_mbmr = MxMR_OP_WARR;
  167. break;
  168. case UPMC:
  169. memctl->memc_br11 =
  170. ((uint)dummy & BRx_BA_MSK) | BRx_PS_32 | BRx_MS_UPMC |
  171. BRx_V;
  172. memctl->memc_mcmr = MxMR_OP_WARR;
  173. break;
  174. default:
  175. panic ("upmconfig passed invalid UPM number (%u)\n", upm);
  176. break;
  177. }
  178. /*
  179. * at this point, the dummy address is set up to access the selected UPM,
  180. * the MAD pointer is zero, and the MxMR OP is set for writing to RAM
  181. *
  182. * now we simply load the mdr with each word and poke the dummy address.
  183. * the MAD is incremented on each access.
  184. */
  185. for (i = 0; i < size; i++) {
  186. memctl->memc_mdr = table[i];
  187. *dummy = 0;
  188. }
  189. /* now kill bank 11 */
  190. memctl->memc_br11 = 0;
  191. }
  192. /* ------------------------------------------------------------------------- */
  193. #if !defined(CONFIG_HAVE_OWN_RESET)
  194. int
  195. do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
  196. {
  197. ulong msr, addr;
  198. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  199. immap->im_clkrst.car_rmr = RMR_CSRE; /* Checkstop Reset enable */
  200. /* Interrupts and MMU off */
  201. __asm__ __volatile__ ("mfmsr %0":"=r" (msr):);
  202. msr &= ~(MSR_ME | MSR_EE | MSR_IR | MSR_DR);
  203. __asm__ __volatile__ ("mtmsr %0"::"r" (msr));
  204. /*
  205. * Trying to execute the next instruction at a non-existing address
  206. * should cause a machine check, resulting in reset
  207. */
  208. #ifdef CONFIG_SYS_RESET_ADDRESS
  209. addr = CONFIG_SYS_RESET_ADDRESS;
  210. #else
  211. /*
  212. * note: when CONFIG_SYS_MONITOR_BASE points to a RAM address, CONFIG_SYS_MONITOR_BASE
  213. * - sizeof (ulong) is usually a valid address. Better pick an address
  214. * known to be invalid on your system and assign it to CONFIG_SYS_RESET_ADDRESS.
  215. */
  216. addr = CONFIG_SYS_MONITOR_BASE - sizeof (ulong);
  217. #endif
  218. ((void (*)(void)) addr) ();
  219. return 1;
  220. }
  221. #endif /* CONFIG_HAVE_OWN_RESET */
  222. /* ------------------------------------------------------------------------- */
  223. /*
  224. * Get timebase clock frequency (like cpu_clk in Hz)
  225. *
  226. */
  227. unsigned long get_tbclk (void)
  228. {
  229. ulong tbclk;
  230. tbclk = (gd->bus_clk + 3L) / 4L;
  231. return (tbclk);
  232. }
  233. /* ------------------------------------------------------------------------- */
  234. #if defined(CONFIG_WATCHDOG)
  235. void watchdog_reset (void)
  236. {
  237. int re_enable = disable_interrupts ();
  238. reset_8260_watchdog ((immap_t *) CONFIG_SYS_IMMR);
  239. if (re_enable)
  240. enable_interrupts ();
  241. }
  242. #endif /* CONFIG_WATCHDOG */
  243. /* ------------------------------------------------------------------------- */
  244. #ifdef CONFIG_OF_BOARD_SETUP
  245. void ft_cpu_setup (void *blob, bd_t *bd)
  246. {
  247. #if defined(CONFIG_HAS_ETH0) || defined(CONFIG_HAS_ETH1) ||\
  248. defined(CONFIG_HAS_ETH2) || defined(CONFIG_HAS_ETH3)
  249. fdt_fixup_ethernet(blob);
  250. #endif
  251. do_fixup_by_compat_u32(blob, "fsl,cpm2-brg",
  252. "clock-frequency", bd->bi_brgfreq, 1);
  253. do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
  254. "bus-frequency", bd->bi_busfreq, 1);
  255. do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
  256. "timebase-frequency", OF_TBCLK, 1);
  257. do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
  258. "clock-frequency", bd->bi_intfreq, 1);
  259. fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
  260. }
  261. #endif /* CONFIG_OF_BOARD_SETUP */
  262. /*
  263. * Initializes on-chip ethernet controllers.
  264. * to override, implement board_eth_init()
  265. */
  266. int cpu_eth_init(bd_t *bis)
  267. {
  268. #if defined(CONFIG_ETHER_ON_FCC)
  269. fec_initialize(bis);
  270. #endif
  271. #if defined(CONFIG_ETHER_ON_SCC)
  272. mpc82xx_scc_enet_initialize(bis);
  273. #endif
  274. return 0;
  275. }