cpu.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * (C) Copyright 2003
  3. * Martin Winistoerfer, martinwinistoerfer@gmx.ch.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. /*
  8. * File: cpu.c
  9. *
  10. * Discription: Some cpu specific function for watchdog,
  11. * cpu version test, clock setting ...
  12. *
  13. */
  14. #include <common.h>
  15. #include <watchdog.h>
  16. #include <command.h>
  17. #include <mpc5xx.h>
  18. DECLARE_GLOBAL_DATA_PTR;
  19. #if (defined(CONFIG_MPC555))
  20. # define ID_STR "MPC555/556"
  21. /*
  22. * Check version of cpu with Processor Version Register (PVR)
  23. */
  24. static int check_cpu_version (long clock, uint pvr, uint immr)
  25. {
  26. char buf[32];
  27. /* The highest 16 bits should be 0x0002 for a MPC555/556 */
  28. if ((pvr >> 16) == 0x0002) {
  29. printf (" " ID_STR " Version %x", (pvr >> 16));
  30. printf (" at %s MHz:", strmhz (buf, clock));
  31. } else {
  32. printf ("Not supported cpu version");
  33. return -1;
  34. }
  35. return 0;
  36. }
  37. #endif /* CONFIG_MPC555 */
  38. /*
  39. * Check version of mpc5xx
  40. */
  41. int checkcpu (void)
  42. {
  43. ulong clock = gd->cpu_clk;
  44. uint immr = get_immr (0); /* Return full IMMR contents */
  45. uint pvr = get_pvr (); /* Retrieve PVR register */
  46. puts ("CPU: ");
  47. return check_cpu_version (clock, pvr, immr);
  48. }
  49. /*
  50. * Called by macro WATCHDOG_RESET
  51. */
  52. #if defined(CONFIG_WATCHDOG)
  53. void watchdog_reset (void)
  54. {
  55. int re_enable = disable_interrupts ();
  56. reset_5xx_watchdog ((immap_t *) CONFIG_SYS_IMMR);
  57. if (re_enable)
  58. enable_interrupts ();
  59. }
  60. /*
  61. * Will clear software reset
  62. */
  63. void reset_5xx_watchdog (volatile immap_t * immr)
  64. {
  65. /* Use the MPC5xx Internal Watchdog */
  66. immr->im_siu_conf.sc_swsr = 0x556c; /* Prevent SW time-out */
  67. immr->im_siu_conf.sc_swsr = 0xaa39;
  68. }
  69. #endif /* CONFIG_WATCHDOG */
  70. /*
  71. * Get timebase clock frequency
  72. */
  73. unsigned long get_tbclk (void)
  74. {
  75. volatile immap_t *immr = (volatile immap_t *) CONFIG_SYS_IMMR;
  76. ulong oscclk, factor;
  77. if (immr->im_clkrst.car_sccr & SCCR_TBS) {
  78. return (gd->cpu_clk / 16);
  79. }
  80. factor = (((CONFIG_SYS_PLPRCR) & PLPRCR_MF_MSK) >> PLPRCR_MF_SHIFT) + 1;
  81. oscclk = gd->cpu_clk / factor;
  82. if ((immr->im_clkrst.car_sccr & SCCR_RTSEL) == 0 || factor > 2) {
  83. return (oscclk / 4);
  84. }
  85. return (oscclk / 16);
  86. }
  87. void dcache_enable (void)
  88. {
  89. return;
  90. }
  91. void dcache_disable (void)
  92. {
  93. return;
  94. }
  95. int dcache_status (void)
  96. {
  97. return 0; /* always off */
  98. }
  99. /*
  100. * Reset board
  101. */
  102. int do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
  103. {
  104. #if defined(CONFIG_PATI)
  105. volatile ulong *addr = (ulong *) CONFIG_SYS_RESET_ADDRESS;
  106. *addr = 1;
  107. #else
  108. ulong addr;
  109. /* Interrupts off, enable reset */
  110. __asm__ volatile (" mtspr 81, %r0 \n\t"
  111. " mfmsr %r3 \n\t"
  112. " rlwinm %r31,%r3,0,25,23\n\t"
  113. " mtmsr %r31 \n\t");
  114. /*
  115. * Trying to execute the next instruction at a non-existing address
  116. * should cause a machine check, resulting in reset
  117. */
  118. #ifdef CONFIG_SYS_RESET_ADDRESS
  119. addr = CONFIG_SYS_RESET_ADDRESS;
  120. #else
  121. /*
  122. * note: when CONFIG_SYS_MONITOR_BASE points to a RAM address, CONFIG_SYS_MONITOR_BASE * - sizeof (ulong) is usually a valid address. Better pick an address
  123. * known to be invalid on your system and assign it to CONFIG_SYS_RESET_ADDRESS.
  124. * "(ulong)-1" used to be a good choice for many systems...
  125. */
  126. addr = CONFIG_SYS_MONITOR_BASE - sizeof (ulong);
  127. #endif
  128. ((void (*) (void)) addr) ();
  129. #endif /* #if defined(CONFIG_PATI) */
  130. return 1;
  131. }