cpu.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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 <asm/processor.h>
  46. #include <asm/cpm_8260.h>
  47. #if defined(CONFIG_OF_LIBFDT)
  48. #include <libfdt.h>
  49. #include <libfdt_env.h>
  50. #endif
  51. DECLARE_GLOBAL_DATA_PTR;
  52. #if defined(CONFIG_GET_CPU_STR_F)
  53. extern int get_cpu_str_f (char *buf);
  54. #endif
  55. int checkcpu (void)
  56. {
  57. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  58. ulong clock = gd->cpu_clk;
  59. uint pvr = get_pvr ();
  60. uint immr, rev, m, k;
  61. char buf[32];
  62. puts ("CPU: ");
  63. switch (pvr) {
  64. case PVR_8260:
  65. case PVR_8260_HIP3:
  66. k = 3;
  67. break;
  68. case PVR_8260_HIP4:
  69. k = 4;
  70. break;
  71. case PVR_8260_HIP7R1:
  72. case PVR_8260_HIP7RA:
  73. case PVR_8260_HIP7:
  74. k = 7;
  75. break;
  76. default:
  77. return -1; /* whoops! not an MPC8260 */
  78. }
  79. rev = pvr & 0xff;
  80. immr = immap->im_memctl.memc_immr;
  81. if ((immr & IMMR_ISB_MSK) != CFG_IMMR)
  82. return -1; /* whoops! someone moved the IMMR */
  83. #if defined(CONFIG_GET_CPU_STR_F)
  84. get_cpu_str_f (buf);
  85. printf ("%s (HiP%d Rev %02x, Mask ", buf, k, rev);
  86. #else
  87. printf (CPU_ID_STR " (HiP%d Rev %02x, Mask ", k, rev);
  88. #endif
  89. /*
  90. * the bottom 16 bits of the immr are the Part Number and Mask Number
  91. * (4-34); the 16 bits at PROFF_REVNUM (0x8af0) in dual port ram is the
  92. * RISC Microcode Revision Number (13-10).
  93. * For the 8260, Motorola doesn't include the Microcode Revision
  94. * in the mask.
  95. */
  96. m = immr & (IMMR_PARTNUM_MSK | IMMR_MASKNUM_MSK);
  97. k = *((ushort *) & immap->im_dprambase[PROFF_REVNUM]);
  98. switch (m) {
  99. case 0x0000:
  100. puts ("0.2 2J24M");
  101. break;
  102. case 0x0010:
  103. puts ("A.0 K22A");
  104. break;
  105. case 0x0011:
  106. puts ("A.1 1K22A-XC");
  107. break;
  108. case 0x0001:
  109. puts ("B.1 1K23A");
  110. break;
  111. case 0x0021:
  112. puts ("B.2 2K23A-XC");
  113. break;
  114. case 0x0023:
  115. puts ("B.3 3K23A");
  116. break;
  117. case 0x0024:
  118. puts ("C.2 6K23A");
  119. break;
  120. case 0x0060:
  121. puts ("A.0(A) 2K25A");
  122. break;
  123. case 0x0062:
  124. puts ("B.1 4K25A");
  125. break;
  126. case 0x0064:
  127. puts ("C.0 5K25A");
  128. break;
  129. case 0x0A00:
  130. puts ("0.0 0K49M");
  131. break;
  132. case 0x0A01:
  133. puts ("0.1 1K49M");
  134. break;
  135. case 0x0A10:
  136. puts ("1.0 1K49M");
  137. break;
  138. case 0x0C00:
  139. puts ("0.0 0K50M");
  140. break;
  141. case 0x0C10:
  142. puts ("1.0 1K50M");
  143. break;
  144. case 0x0D00:
  145. puts ("0.0 0K50M");
  146. break;
  147. case 0x0D10:
  148. puts ("1.0 1K50M");
  149. break;
  150. default:
  151. printf ("unknown [immr=0x%04x,k=0x%04x]", m, k);
  152. break;
  153. }
  154. printf (") at %s MHz\n", strmhz (buf, clock));
  155. return 0;
  156. }
  157. /* ------------------------------------------------------------------------- */
  158. /* configures a UPM by writing into the UPM RAM array */
  159. /* uses bank 11 and a dummy physical address (=BRx_BA_MSK) */
  160. /* NOTE: the physical address chosen must not overlap into any other area */
  161. /* mapped by the memory controller because bank 11 has the lowest priority */
  162. void upmconfig (uint upm, uint * table, uint size)
  163. {
  164. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  165. volatile memctl8260_t *memctl = &immap->im_memctl;
  166. volatile uchar *dummy = (uchar *) BRx_BA_MSK; /* set all BA bits */
  167. uint i;
  168. /* first set up bank 11 to reference the correct UPM at a dummy address */
  169. memctl->memc_or11 = ORxU_AM_MSK; /* set all AM bits */
  170. switch (upm) {
  171. case UPMA:
  172. memctl->memc_br11 =
  173. ((uint)dummy & BRx_BA_MSK) | BRx_PS_32 | BRx_MS_UPMA |
  174. BRx_V;
  175. memctl->memc_mamr = MxMR_OP_WARR;
  176. break;
  177. case UPMB:
  178. memctl->memc_br11 =
  179. ((uint)dummy & BRx_BA_MSK) | BRx_PS_32 | BRx_MS_UPMB |
  180. BRx_V;
  181. memctl->memc_mbmr = MxMR_OP_WARR;
  182. break;
  183. case UPMC:
  184. memctl->memc_br11 =
  185. ((uint)dummy & BRx_BA_MSK) | BRx_PS_32 | BRx_MS_UPMC |
  186. BRx_V;
  187. memctl->memc_mcmr = MxMR_OP_WARR;
  188. break;
  189. default:
  190. panic ("upmconfig passed invalid UPM number (%u)\n", upm);
  191. break;
  192. }
  193. /*
  194. * at this point, the dummy address is set up to access the selected UPM,
  195. * the MAD pointer is zero, and the MxMR OP is set for writing to RAM
  196. *
  197. * now we simply load the mdr with each word and poke the dummy address.
  198. * the MAD is incremented on each access.
  199. */
  200. for (i = 0; i < size; i++) {
  201. memctl->memc_mdr = table[i];
  202. *dummy = 0;
  203. }
  204. /* now kill bank 11 */
  205. memctl->memc_br11 = 0;
  206. }
  207. /* ------------------------------------------------------------------------- */
  208. #if !defined(CONFIG_HAVE_OWN_RESET)
  209. int
  210. do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
  211. {
  212. ulong msr, addr;
  213. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  214. immap->im_clkrst.car_rmr = RMR_CSRE; /* Checkstop Reset enable */
  215. /* Interrupts and MMU off */
  216. __asm__ __volatile__ ("mfmsr %0":"=r" (msr):);
  217. msr &= ~(MSR_ME | MSR_EE | MSR_IR | MSR_DR);
  218. __asm__ __volatile__ ("mtmsr %0"::"r" (msr));
  219. /*
  220. * Trying to execute the next instruction at a non-existing address
  221. * should cause a machine check, resulting in reset
  222. */
  223. #ifdef CFG_RESET_ADDRESS
  224. addr = CFG_RESET_ADDRESS;
  225. #else
  226. /*
  227. * note: when CFG_MONITOR_BASE points to a RAM address, CFG_MONITOR_BASE
  228. * - sizeof (ulong) is usually a valid address. Better pick an address
  229. * known to be invalid on your system and assign it to CFG_RESET_ADDRESS.
  230. */
  231. addr = CFG_MONITOR_BASE - sizeof (ulong);
  232. #endif
  233. ((void (*)(void)) addr) ();
  234. return 1;
  235. }
  236. #endif /* CONFIG_HAVE_OWN_RESET */
  237. /* ------------------------------------------------------------------------- */
  238. /*
  239. * Get timebase clock frequency (like cpu_clk in Hz)
  240. *
  241. */
  242. unsigned long get_tbclk (void)
  243. {
  244. ulong tbclk;
  245. tbclk = (gd->bus_clk + 3L) / 4L;
  246. return (tbclk);
  247. }
  248. /* ------------------------------------------------------------------------- */
  249. #if defined(CONFIG_WATCHDOG)
  250. void watchdog_reset (void)
  251. {
  252. int re_enable = disable_interrupts ();
  253. reset_8260_watchdog ((immap_t *) CFG_IMMR);
  254. if (re_enable)
  255. enable_interrupts ();
  256. }
  257. #endif /* CONFIG_WATCHDOG */
  258. /* ------------------------------------------------------------------------- */
  259. #if defined(CONFIG_OF_LIBFDT)
  260. static void do_fixup(void *fdt, const char *node, const char *prop,
  261. const void *val, int len, int create)
  262. {
  263. #if defined(DEBUG)
  264. int i;
  265. debug("Updating property '%s/%s' = ", node, prop);
  266. for (i = 0; i < len; i++)
  267. debug(" %.2x", *(u8*)(val+i));
  268. debug("\n");
  269. #endif
  270. int rc = fdt_find_and_setprop(fdt, node, prop, val, len, create);
  271. if (rc)
  272. printf("Unable to update property %s:%s, err=%s\n",
  273. node, prop, fdt_strerror(rc));
  274. }
  275. static void do_fixup_u32(void *fdt, const char *node, const char *prop,
  276. u32 val, int create)
  277. {
  278. val = cpu_to_fdt32(val);
  279. do_fixup(fdt, node, prop, &val, sizeof(val), create);
  280. }
  281. void ft_cpu_setup (void *blob, bd_t *bd)
  282. {
  283. char * cpu_path = "/cpus/" OF_CPU;
  284. do_fixup_u32(blob, cpu_path, "bus-frequency", bd->bi_busfreq, 1);
  285. do_fixup_u32(blob, cpu_path, "timebase-frequency", OF_TBCLK, 1);
  286. do_fixup_u32(blob, cpu_path, "clock-frequency", bd->bi_intfreq, 1);
  287. }
  288. #endif /* CONFIG_OF_LIBFDT */