cpu.c 4.1 KB

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