cpu.c 4.6 KB

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