cpu.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. * Copyright (C) 2004-2006 Freescale Semiconductor, Inc.
  3. * (C) Copyright 2007 DENX Software Engineering
  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 MPC512x family.
  25. *
  26. * Derived from the MPC83xx code.
  27. */
  28. #include <common.h>
  29. #include <command.h>
  30. #include <net.h>
  31. #include <netdev.h>
  32. #include <asm/processor.h>
  33. #if defined(CONFIG_OF_LIBFDT)
  34. #include <fdt_support.h>
  35. #endif
  36. DECLARE_GLOBAL_DATA_PTR;
  37. int checkcpu (void)
  38. {
  39. volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  40. ulong clock = gd->cpu_clk;
  41. u32 pvr = get_pvr ();
  42. u32 spridr = immr->sysconf.spridr;
  43. char buf1[32], buf2[32];
  44. puts ("CPU: ");
  45. switch (spridr & 0xffff0000) {
  46. case SPR_5121E:
  47. puts ("MPC5121e ");
  48. break;
  49. default:
  50. printf ("Unknown part ID %08x ", spridr & 0xffff0000);
  51. }
  52. printf ("rev. %d.%d, Core ", SVR_MJREV (spridr), SVR_MNREV (spridr));
  53. switch (pvr & 0xffff0000) {
  54. case PVR_E300C4:
  55. puts ("e300c4 ");
  56. break;
  57. default:
  58. puts ("unknown ");
  59. }
  60. printf ("at %s MHz, CSB at %s MHz\n",
  61. strmhz(buf1, clock),
  62. strmhz(buf2, gd->csb_clk) );
  63. return 0;
  64. }
  65. int
  66. do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
  67. {
  68. ulong msr;
  69. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  70. /* Interrupts and MMU off */
  71. __asm__ __volatile__ ("mfmsr %0":"=r" (msr):);
  72. msr &= ~( MSR_EE | MSR_IR | MSR_DR);
  73. __asm__ __volatile__ ("mtmsr %0"::"r" (msr));
  74. /*
  75. * Enable Reset Control Reg - "RSTE" is the magic word that let us go
  76. */
  77. immap->reset.rpr = 0x52535445;
  78. /* Verify Reset Control Reg is enabled */
  79. while (!((immap->reset.rcer) & RCER_CRE))
  80. ;
  81. printf ("Resetting the board.\n");
  82. udelay(200);
  83. /* Perform reset */
  84. immap->reset.rcr = RCR_SWHR;
  85. /* Unreached... */
  86. return 1;
  87. }
  88. /*
  89. * Get timebase clock frequency (like cpu_clk in Hz)
  90. */
  91. unsigned long get_tbclk (void)
  92. {
  93. ulong tbclk;
  94. tbclk = (gd->bus_clk + 3L) / 4L;
  95. return tbclk;
  96. }
  97. #if defined(CONFIG_WATCHDOG)
  98. void watchdog_reset (void)
  99. {
  100. int re_enable = disable_interrupts ();
  101. /* Reset watchdog */
  102. volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  103. immr->wdt.swsrr = 0x556c;
  104. immr->wdt.swsrr = 0xaa39;
  105. if (re_enable)
  106. enable_interrupts ();
  107. }
  108. #endif
  109. #ifdef CONFIG_OF_LIBFDT
  110. #ifdef CONFIG_OF_SUPPORT_OLD_DEVICE_TREES
  111. /*
  112. * fdt setup for old device trees
  113. * fix up
  114. * cpu clocks
  115. * soc clocks
  116. * ethernet addresses
  117. */
  118. static void old_ft_cpu_setup(void *blob, bd_t *bd)
  119. {
  120. /*
  121. * avoid fixing up by path because that
  122. * produces scary error messages
  123. */
  124. uchar enetaddr[6];
  125. /*
  126. * old device trees have ethernet nodes with
  127. * device_type = "network"
  128. */
  129. eth_getenv_enetaddr("ethaddr", enetaddr);
  130. do_fixup_by_prop(blob, "device_type", "network", 8,
  131. "local-mac-address", enetaddr, 6, 0);
  132. do_fixup_by_prop(blob, "device_type", "network", 8,
  133. "address", enetaddr, 6, 0);
  134. /*
  135. * old device trees have soc nodes with
  136. * device_type = "soc"
  137. */
  138. do_fixup_by_prop_u32(blob, "device_type", "soc", 4,
  139. "bus-frequency", bd->bi_ipsfreq, 0);
  140. }
  141. #endif
  142. static void ft_clock_setup(void *blob, bd_t *bd)
  143. {
  144. char *cpu_path = "/cpus/" OF_CPU;
  145. /*
  146. * fixup cpu clocks using path
  147. */
  148. do_fixup_by_path_u32(blob, cpu_path,
  149. "timebase-frequency", OF_TBCLK, 1);
  150. do_fixup_by_path_u32(blob, cpu_path,
  151. "bus-frequency", bd->bi_busfreq, 1);
  152. do_fixup_by_path_u32(blob, cpu_path,
  153. "clock-frequency", bd->bi_intfreq, 1);
  154. /*
  155. * fixup soc clocks using compatible
  156. */
  157. do_fixup_by_compat_u32(blob, OF_SOC_COMPAT,
  158. "bus-frequency", bd->bi_ipsfreq, 1);
  159. }
  160. void ft_cpu_setup(void *blob, bd_t *bd)
  161. {
  162. #ifdef CONFIG_OF_SUPPORT_OLD_DEVICE_TREES
  163. old_ft_cpu_setup(blob, bd);
  164. #endif
  165. ft_clock_setup(blob, bd);
  166. #ifdef CONFIG_HAS_ETH0
  167. fdt_fixup_ethernet(blob);
  168. #endif
  169. }
  170. #endif
  171. #ifdef CONFIG_MPC512x_FEC
  172. /* Default initializations for FEC controllers. To override,
  173. * create a board-specific function called:
  174. * int board_eth_init(bd_t *bis)
  175. */
  176. int cpu_eth_init(bd_t *bis)
  177. {
  178. return mpc512x_fec_initialize(bis);
  179. }
  180. #endif