cpu.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. /*
  47. * Both MCF5270 and MCF5271 are members of the MPC5271 family. Try to
  48. * determine which one we are running on, based on the Chip Identification
  49. * Register (CIR).
  50. */
  51. int checkcpu (void)
  52. {
  53. char buf[32];
  54. unsigned short cir; /* Chip Identification Register */
  55. unsigned short pin; /* Part identification number */
  56. unsigned char prn; /* Part revision number */
  57. char *cpu_model;
  58. cir = mbar_readShort(MCF_CCM_CIR);
  59. pin = cir >> MCF_CCM_CIR_PIN_LEN;
  60. prn = cir & MCF_CCM_CIR_PRN_MASK;
  61. switch (pin) {
  62. case MCF_CCM_CIR_PIN_MCF5270:
  63. cpu_model = "5270";
  64. break;
  65. case MCF_CCM_CIR_PIN_MCF5271:
  66. cpu_model = "5271";
  67. break;
  68. default:
  69. cpu_model = NULL;
  70. break;
  71. }
  72. if (cpu_model)
  73. printf("CPU: Freescale ColdFire MCF%s rev. %hu, at %s MHz\n",
  74. cpu_model, prn, strmhz(buf, CFG_CLK));
  75. else
  76. printf("CPU: Unknown - Freescale ColdFire MCF5271 family"
  77. " (PIN: 0x%x) rev. %hu, at %s MHz\n",
  78. pin, prn, strmhz(buf, CFG_CLK));
  79. return 0;
  80. }
  81. int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]) {
  82. mbar_writeByte(MCF_RCM_RCR,
  83. MCF_RCM_RCR_SOFTRST | MCF_RCM_RCR_FRCRSTOUT);
  84. return 0;
  85. };
  86. #if defined(CONFIG_WATCHDOG)
  87. void watchdog_reset (void)
  88. {
  89. mbar_writeShort(MCF_WTM_WSR, 0x5555);
  90. mbar_writeShort(MCF_WTM_WSR, 0xAAAA);
  91. }
  92. int watchdog_disable (void)
  93. {
  94. mbar_writeShort(MCF_WTM_WCR, 0);
  95. return (0);
  96. }
  97. int watchdog_init (void)
  98. {
  99. mbar_writeShort(MCF_WTM_WCR, MCF_WTM_WCR_EN);
  100. return (0);
  101. }
  102. #endif /* #ifdef CONFIG_WATCHDOG */
  103. #endif
  104. #ifdef CONFIG_M5272
  105. int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]) {
  106. volatile wdog_t * wdp = (wdog_t *)(CFG_MBAR + MCFSIM_WRRR);
  107. wdp->wdog_wrrr = 0;
  108. udelay (1000);
  109. /* enable watchdog, set timeout to 0 and wait */
  110. wdp->wdog_wrrr = 1;
  111. while (1);
  112. /* we don't return! */
  113. return 0;
  114. };
  115. int checkcpu(void) {
  116. ulong *dirp = (ulong *)(CFG_MBAR + MCFSIM_DIR);
  117. uchar msk;
  118. char *suf;
  119. puts ("CPU: ");
  120. msk = (*dirp > 28) & 0xf;
  121. switch (msk) {
  122. case 0x2: suf = "1K75N"; break;
  123. case 0x4: suf = "3K75N"; break;
  124. default:
  125. suf = NULL;
  126. printf ("Freescale MCF5272 (Mask:%01x)\n", msk);
  127. break;
  128. }
  129. if (suf)
  130. printf ("Freescale MCF5272 %s\n", suf);
  131. return 0;
  132. };
  133. #if defined(CONFIG_WATCHDOG)
  134. /* Called by macro WATCHDOG_RESET */
  135. void watchdog_reset (void)
  136. {
  137. volatile immap_t * regp = (volatile immap_t *)CFG_MBAR;
  138. regp->wdog_reg.wdog_wcr = 0;
  139. }
  140. int watchdog_disable (void)
  141. {
  142. volatile immap_t *regp = (volatile immap_t *)CFG_MBAR;
  143. regp->wdog_reg.wdog_wcr = 0; /* reset watchdog counter */
  144. regp->wdog_reg.wdog_wirr = 0; /* disable watchdog interrupt */
  145. regp->wdog_reg.wdog_wrrr = 0; /* disable watchdog timer */
  146. puts ("WATCHDOG:disabled\n");
  147. return (0);
  148. }
  149. int watchdog_init (void)
  150. {
  151. volatile immap_t *regp = (volatile immap_t *)CFG_MBAR;
  152. regp->wdog_reg.wdog_wirr = 0; /* disable watchdog interrupt */
  153. /* set timeout and enable watchdog */
  154. regp->wdog_reg.wdog_wrrr = ((CONFIG_WATCHDOG_TIMEOUT * CFG_HZ) / (32768 * 1000)) - 1;
  155. regp->wdog_reg.wdog_wcr = 0; /* reset watchdog counter */
  156. puts ("WATCHDOG:enabled\n");
  157. return (0);
  158. }
  159. #endif /* #ifdef CONFIG_WATCHDOG */
  160. #endif /* #ifdef CONFIG_M5272 */
  161. #ifdef CONFIG_M5282
  162. int checkcpu (void)
  163. {
  164. unsigned char resetsource = MCFRESET_RSR;
  165. printf ("CPU: Freescale Coldfire MCF5282 (PIN: %2.2x REV: %2.2x)\n",
  166. MCFCCM_CIR>>8,MCFCCM_CIR & MCFCCM_CIR_PRN_MASK);
  167. printf ("Reset:%s%s%s%s%s%s%s\n",
  168. (resetsource & MCFRESET_RSR_LOL) ? " Loss of Lock" : "",
  169. (resetsource & MCFRESET_RSR_LOC) ? " Loss of Clock" : "",
  170. (resetsource & MCFRESET_RSR_EXT) ? " External" : "",
  171. (resetsource & MCFRESET_RSR_POR) ? " Power On" : "",
  172. (resetsource & MCFRESET_RSR_WDR) ? " Watchdog" : "",
  173. (resetsource & MCFRESET_RSR_SOFT) ? " Software" : "",
  174. (resetsource & MCFRESET_RSR_LVD) ? " Low Voltage" : ""
  175. );
  176. return 0;
  177. }
  178. int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
  179. {
  180. MCFRESET_RCR = MCFRESET_RCR_SOFTRST;
  181. return 0;
  182. };
  183. #endif
  184. #ifdef CONFIG_M5249 /* test-only: todo... */
  185. int checkcpu (void)
  186. {
  187. char buf[32];
  188. printf ("CPU: Freescale Coldfire MCF5249 at %s MHz\n", strmhz(buf, CFG_CLK));
  189. return 0;
  190. }
  191. int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]) {
  192. /* enable watchdog, set timeout to 0 and wait */
  193. mbar_writeByte(MCFSIM_SYPCR, 0xc0);
  194. while (1);
  195. /* we don't return! */
  196. return 0;
  197. };
  198. #endif