cpu.c 3.9 KB

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