cpu.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * (C) Copyright 2003
  3. * Josef Baumgartner <josef.baumgartner@telex.de>
  4. *
  5. * MCF5282 additionals
  6. * (C) Copyright 2005
  7. * BuS Elektronik GmbH & Co. KG <esw@bus-elektronik.de>
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. #include <common.h>
  28. #include <watchdog.h>
  29. #include <command.h>
  30. #ifdef CONFIG_M5271
  31. #include <asm/immap_5271.h>
  32. #include <asm/m5271.h>
  33. #endif
  34. #ifdef CONFIG_M5272
  35. #include <asm/immap_5272.h>
  36. #include <asm/m5272.h>
  37. #endif
  38. #ifdef CONFIG_M5282
  39. #include <asm/m5282.h>
  40. #include <asm/immap_5282.h>
  41. #endif
  42. #ifdef CONFIG_M5249
  43. #include <asm/m5249.h>
  44. #endif
  45. #ifdef CONFIG_M5271
  46. int checkcpu (void)
  47. {
  48. char buf[32];
  49. printf ("CPU: Freescale Coldfire MCF5271 at %s MHz\n", strmhz(buf, CFG_CLK));
  50. return 0;
  51. }
  52. int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]) {
  53. mbar_writeByte(MCF_RCM_RCR,
  54. MCF_RCM_RCR_SOFTRST | MCF_RCM_RCR_FRCRSTOUT);
  55. return 0;
  56. };
  57. #if defined(CONFIG_WATCHDOG)
  58. void watchdog_reset (void)
  59. {
  60. mbar_writeShort(MCF_WTM_WSR, 0x5555);
  61. mbar_writeShort(MCF_WTM_WSR, 0xAAAA);
  62. }
  63. int watchdog_disable (void)
  64. {
  65. mbar_writeShort(MCF_WTM_WCR, 0);
  66. return (0);
  67. }
  68. int watchdog_init (void)
  69. {
  70. mbar_writeShort(MCF_WTM_WCR, MCF_WTM_WCR_EN);
  71. return (0);
  72. }
  73. #endif /* #ifdef CONFIG_WATCHDOG */
  74. #endif
  75. #ifdef CONFIG_M5272
  76. int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]) {
  77. volatile wdog_t * wdp = (wdog_t *)(CFG_MBAR + MCFSIM_WRRR);
  78. wdp->wdog_wrrr = 0;
  79. udelay (1000);
  80. /* enable watchdog, set timeout to 0 and wait */
  81. wdp->wdog_wrrr = 1;
  82. while (1);
  83. /* we don't return! */
  84. return 0;
  85. };
  86. int checkcpu(void) {
  87. ulong *dirp = (ulong *)(CFG_MBAR + MCFSIM_DIR);
  88. uchar msk;
  89. char *suf;
  90. puts ("CPU: ");
  91. msk = (*dirp > 28) & 0xf;
  92. switch (msk) {
  93. case 0x2: suf = "1K75N"; break;
  94. case 0x4: suf = "3K75N"; break;
  95. default:
  96. suf = NULL;
  97. printf ("Freescale MCF5272 (Mask:%01x)\n", msk);
  98. break;
  99. }
  100. if (suf)
  101. printf ("Freescale MCF5272 %s\n", suf);
  102. return 0;
  103. };
  104. #if defined(CONFIG_WATCHDOG)
  105. /* Called by macro WATCHDOG_RESET */
  106. void watchdog_reset (void)
  107. {
  108. volatile immap_t * regp = (volatile immap_t *)CFG_MBAR;
  109. regp->wdog_reg.wdog_wcr = 0;
  110. }
  111. int watchdog_disable (void)
  112. {
  113. volatile immap_t *regp = (volatile immap_t *)CFG_MBAR;
  114. regp->wdog_reg.wdog_wcr = 0; /* reset watchdog counter */
  115. regp->wdog_reg.wdog_wirr = 0; /* disable watchdog interrupt */
  116. regp->wdog_reg.wdog_wrrr = 0; /* disable watchdog timer */
  117. puts ("WATCHDOG:disabled\n");
  118. return (0);
  119. }
  120. int watchdog_init (void)
  121. {
  122. volatile immap_t *regp = (volatile immap_t *)CFG_MBAR;
  123. regp->wdog_reg.wdog_wirr = 0; /* disable watchdog interrupt */
  124. /* set timeout and enable watchdog */
  125. regp->wdog_reg.wdog_wrrr = ((CONFIG_WATCHDOG_TIMEOUT * CFG_HZ) / (32768 * 1000)) - 1;
  126. regp->wdog_reg.wdog_wcr = 0; /* reset watchdog counter */
  127. puts ("WATCHDOG:enabled\n");
  128. return (0);
  129. }
  130. #endif /* #ifdef CONFIG_WATCHDOG */
  131. #endif /* #ifdef CONFIG_M5272 */
  132. #ifdef CONFIG_M5282
  133. int checkcpu (void)
  134. {
  135. unsigned char resetsource = MCFRESET_RSR;
  136. printf ("CPU: Freescale Coldfire MCF5282 (PIN: %2.2x REV: %2.2x)\n",
  137. MCFCCM_CIR>>8,MCFCCM_CIR & MCFCCM_CIR_PRN_MASK);
  138. printf ("Reset:%s%s%s%s%s%s%s\n",
  139. (resetsource & MCFRESET_RSR_LOL) ? " Loss of Lock" : "",
  140. (resetsource & MCFRESET_RSR_LOC) ? " Loss of Clock" : "",
  141. (resetsource & MCFRESET_RSR_EXT) ? " External" : "",
  142. (resetsource & MCFRESET_RSR_POR) ? " Power On" : "",
  143. (resetsource & MCFRESET_RSR_WDR) ? " Watchdog" : "",
  144. (resetsource & MCFRESET_RSR_SOFT) ? " Software" : "",
  145. (resetsource & MCFRESET_RSR_LVD) ? " Low Voltage" : ""
  146. );
  147. return 0;
  148. }
  149. int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
  150. {
  151. MCFRESET_RCR = MCFRESET_RCR_SOFTRST;
  152. return 0;
  153. };
  154. #endif
  155. #ifdef CONFIG_M5249 /* test-only: todo... */
  156. int checkcpu (void)
  157. {
  158. char buf[32];
  159. printf ("CPU: Freescale Coldfire MCF5249 at %s MHz\n", strmhz(buf, CFG_CLK));
  160. return 0;
  161. }
  162. int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]) {
  163. /* enable watchdog, set timeout to 0 and wait */
  164. mbar_writeByte(MCFSIM_SYPCR, 0xc0);
  165. while (1);
  166. /* we don't return! */
  167. return 0;
  168. };
  169. #endif