cpu.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * (C) Copyright 2000-2010
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. /*
  8. * CPU specific code for the MPC5xxx CPUs
  9. */
  10. #include <common.h>
  11. #include <watchdog.h>
  12. #include <command.h>
  13. #include <net.h>
  14. #include <mpc5xxx.h>
  15. #include <netdev.h>
  16. #include <asm/io.h>
  17. #include <asm/processor.h>
  18. #if defined(CONFIG_OF_LIBFDT)
  19. #include <libfdt.h>
  20. #include <fdt_support.h>
  21. #endif
  22. #if defined(CONFIG_OF_IDE_FIXUP)
  23. #include <ide.h>
  24. #endif
  25. DECLARE_GLOBAL_DATA_PTR;
  26. int checkcpu (void)
  27. {
  28. ulong clock = gd->cpu_clk;
  29. char buf[32];
  30. uint svr, pvr;
  31. puts ("CPU: ");
  32. svr = get_svr();
  33. pvr = get_pvr();
  34. switch (pvr) {
  35. case PVR_5200:
  36. printf("MPC5200");
  37. break;
  38. case PVR_5200B:
  39. printf("MPC5200B");
  40. break;
  41. default:
  42. printf("Unknown MPC5xxx");
  43. break;
  44. }
  45. printf (" v%d.%d, Core v%d.%d", SVR_MJREV (svr), SVR_MNREV (svr),
  46. PVR_MAJ(pvr), PVR_MIN(pvr));
  47. printf (" at %s MHz\n", strmhz (buf, clock));
  48. return 0;
  49. }
  50. /* ------------------------------------------------------------------------- */
  51. int
  52. do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
  53. {
  54. ulong msr;
  55. /* Interrupts and MMU off */
  56. __asm__ __volatile__ ("mfmsr %0":"=r" (msr):);
  57. msr &= ~(MSR_ME | MSR_EE | MSR_IR | MSR_DR);
  58. __asm__ __volatile__ ("mtmsr %0"::"r" (msr));
  59. /* Charge the watchdog timer */
  60. *(vu_long *)(MPC5XXX_GPT0_COUNTER) = 0x0001000f;
  61. *(vu_long *)(MPC5XXX_GPT0_ENABLE) = 0x9004; /* wden|ce|timer_ms */
  62. while(1);
  63. return 1;
  64. }
  65. /* ------------------------------------------------------------------------- */
  66. /*
  67. * Get timebase clock frequency (like cpu_clk in Hz)
  68. *
  69. */
  70. unsigned long get_tbclk (void)
  71. {
  72. ulong tbclk;
  73. tbclk = (gd->bus_clk + 3L) / 4L;
  74. return (tbclk);
  75. }
  76. /* ------------------------------------------------------------------------- */
  77. #ifdef CONFIG_OF_BOARD_SETUP
  78. void ft_cpu_setup(void *blob, bd_t *bd)
  79. {
  80. int div = in_8((void*)CONFIG_SYS_MBAR + 0x204) & 0x0020 ? 8 : 4;
  81. char * cpu_path = "/cpus/" OF_CPU;
  82. #ifdef CONFIG_MPC5xxx_FEC
  83. uchar enetaddr[6];
  84. char * eth_path = "/" OF_SOC "/ethernet@3000";
  85. #endif
  86. do_fixup_by_path_u32(blob, cpu_path, "timebase-frequency", OF_TBCLK, 1);
  87. do_fixup_by_path_u32(blob, cpu_path, "bus-frequency", bd->bi_busfreq, 1);
  88. do_fixup_by_path_u32(blob, cpu_path, "clock-frequency", bd->bi_intfreq, 1);
  89. do_fixup_by_path_u32(blob, "/" OF_SOC, "bus-frequency", bd->bi_ipbfreq, 1);
  90. do_fixup_by_path_u32(blob, "/" OF_SOC, "system-frequency",
  91. bd->bi_busfreq*div, 1);
  92. #ifdef CONFIG_MPC5xxx_FEC
  93. eth_getenv_enetaddr("ethaddr", enetaddr);
  94. do_fixup_by_path(blob, eth_path, "mac-address", enetaddr, 6, 0);
  95. do_fixup_by_path(blob, eth_path, "local-mac-address", enetaddr, 6, 0);
  96. #endif
  97. #ifdef CONFIG_OF_IDE_FIXUP
  98. if (!ide_device_present(0)) {
  99. /* NO CF card detected -> delete ata node in DTS */
  100. int nodeoffset = 0;
  101. char nodename[] = "/soc5200@f0000000/ata@3a00";
  102. nodeoffset = fdt_path_offset(blob, nodename);
  103. if (nodeoffset >= 0) {
  104. fdt_del_node(blob, nodeoffset);
  105. } else {
  106. printf("%s: cannot find %s node err:%s\n",
  107. __func__, nodename, fdt_strerror(nodeoffset));
  108. }
  109. }
  110. #endif /* CONFIG_OF_IDE_FIXUP */
  111. fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
  112. }
  113. #endif /* CONFIG_OF_BOARD_SETUP */
  114. #ifdef CONFIG_MPC5xxx_FEC
  115. /* Default initializations for FEC controllers. To override,
  116. * create a board-specific function called:
  117. * int board_eth_init(bd_t *bis)
  118. */
  119. int cpu_eth_init(bd_t *bis)
  120. {
  121. return mpc5xxx_fec_initialize(bis);
  122. }
  123. #endif
  124. #if defined(CONFIG_WATCHDOG)
  125. void watchdog_reset(void)
  126. {
  127. int re_enable = disable_interrupts();
  128. reset_5xxx_watchdog();
  129. if (re_enable) enable_interrupts();
  130. }
  131. void reset_5xxx_watchdog(void)
  132. {
  133. volatile struct mpc5xxx_gpt *gpt0 =
  134. (struct mpc5xxx_gpt *) MPC5XXX_GPT;
  135. /* Trigger TIMER_0 by writing A5 to OCPW */
  136. clrsetbits_be32(&gpt0->emsr, 0xff000000, 0xa5000000);
  137. }
  138. #endif /* CONFIG_WATCHDOG */