cpu.c 4.5 KB

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