cpu.c 5.3 KB

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