cpu.c 8.0 KB

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