cpu.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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. * MCF5275 additions
  10. * Copyright (C) 2008 Arthur Shipkowski (art@videon-central.com)
  11. *
  12. * See file CREDITS for list of people who contributed to this
  13. * project.
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License as
  17. * published by the Free Software Foundation; either version 2 of
  18. * the License, or (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  28. * MA 02111-1307 USA
  29. */
  30. #include <common.h>
  31. #include <watchdog.h>
  32. #include <command.h>
  33. #include <asm/immap.h>
  34. #ifdef CONFIG_M5271
  35. /*
  36. * Both MCF5270 and MCF5271 are members of the MPC5271 family. Try to
  37. * determine which one we are running on, based on the Chip Identification
  38. * Register (CIR).
  39. */
  40. int checkcpu(void)
  41. {
  42. char buf[32];
  43. unsigned short cir; /* Chip Identification Register */
  44. unsigned short pin; /* Part identification number */
  45. unsigned char prn; /* Part revision number */
  46. char *cpu_model;
  47. cir = mbar_readShort(MCF_CCM_CIR);
  48. pin = cir >> MCF_CCM_CIR_PIN_LEN;
  49. prn = cir & MCF_CCM_CIR_PRN_MASK;
  50. switch (pin) {
  51. case MCF_CCM_CIR_PIN_MCF5270:
  52. cpu_model = "5270";
  53. break;
  54. case MCF_CCM_CIR_PIN_MCF5271:
  55. cpu_model = "5271";
  56. break;
  57. default:
  58. cpu_model = NULL;
  59. break;
  60. }
  61. if (cpu_model)
  62. printf("CPU: Freescale ColdFire MCF%s rev. %hu, at %s MHz\n",
  63. cpu_model, prn, strmhz(buf, CFG_CLK));
  64. else
  65. printf("CPU: Unknown - Freescale ColdFire MCF5271 family"
  66. " (PIN: 0x%x) rev. %hu, at %s MHz\n",
  67. pin, prn, strmhz(buf, CFG_CLK));
  68. return 0;
  69. }
  70. int do_reset(cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc, char *argv[])
  71. {
  72. mbar_writeByte(MCF_RCM_RCR,
  73. MCF_RCM_RCR_SOFTRST | MCF_RCM_RCR_FRCRSTOUT);
  74. return 0;
  75. };
  76. #if defined(CONFIG_WATCHDOG)
  77. void watchdog_reset(void)
  78. {
  79. mbar_writeShort(MCF_WTM_WSR, 0x5555);
  80. mbar_writeShort(MCF_WTM_WSR, 0xAAAA);
  81. }
  82. int watchdog_disable(void)
  83. {
  84. mbar_writeShort(MCF_WTM_WCR, 0);
  85. return (0);
  86. }
  87. int watchdog_init(void)
  88. {
  89. mbar_writeShort(MCF_WTM_WCR, MCF_WTM_WCR_EN);
  90. return (0);
  91. }
  92. #endif /* #ifdef CONFIG_WATCHDOG */
  93. #endif
  94. #ifdef CONFIG_M5272
  95. int do_reset(cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc, char *argv[])
  96. {
  97. volatile wdog_t *wdp = (wdog_t *) (MMAP_WDOG);
  98. wdp->wdog_wrrr = 0;
  99. udelay(1000);
  100. /* enable watchdog, set timeout to 0 and wait */
  101. wdp->wdog_wrrr = 1;
  102. while (1) ;
  103. /* we don't return! */
  104. return 0;
  105. };
  106. int checkcpu(void)
  107. {
  108. volatile sysctrl_t *sysctrl = (sysctrl_t *) (MMAP_CFG);
  109. uchar msk;
  110. char *suf;
  111. puts("CPU: ");
  112. msk = (sysctrl->sc_dir > 28) & 0xf;
  113. switch (msk) {
  114. case 0x2:
  115. suf = "1K75N";
  116. break;
  117. case 0x4:
  118. suf = "3K75N";
  119. break;
  120. default:
  121. suf = NULL;
  122. printf("Freescale MCF5272 (Mask:%01x)\n", msk);
  123. break;
  124. }
  125. if (suf)
  126. printf("Freescale MCF5272 %s\n", suf);
  127. return 0;
  128. };
  129. #if defined(CONFIG_WATCHDOG)
  130. /* Called by macro WATCHDOG_RESET */
  131. void watchdog_reset(void)
  132. {
  133. volatile wdog_t *wdt = (volatile wdog_t *)(MMAP_WDOG);
  134. wdt->wdog_wcr = 0;
  135. }
  136. int watchdog_disable(void)
  137. {
  138. volatile wdog_t *wdt = (volatile wdog_t *)(MMAP_WDOG);
  139. wdt->wdog_wcr = 0; /* reset watchdog counter */
  140. wdt->wdog_wirr = 0; /* disable watchdog interrupt */
  141. wdt->wdog_wrrr = 0; /* disable watchdog timer */
  142. puts("WATCHDOG:disabled\n");
  143. return (0);
  144. }
  145. int watchdog_init(void)
  146. {
  147. volatile wdog_t *wdt = (volatile wdog_t *)(MMAP_WDOG);
  148. wdt->wdog_wirr = 0; /* disable watchdog interrupt */
  149. /* set timeout and enable watchdog */
  150. wdt->wdog_wrrr =
  151. ((CONFIG_WATCHDOG_TIMEOUT * CFG_HZ) / (32768 * 1000)) - 1;
  152. wdt->wdog_wcr = 0; /* reset watchdog counter */
  153. puts("WATCHDOG:enabled\n");
  154. return (0);
  155. }
  156. #endif /* #ifdef CONFIG_WATCHDOG */
  157. #endif /* #ifdef CONFIG_M5272 */
  158. #ifdef CONFIG_M5275
  159. int do_reset(cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
  160. {
  161. volatile rcm_t *rcm = (rcm_t *)(MMAP_RCM);
  162. udelay(1000);
  163. rcm->rcr = RCM_RCR_SOFTRST;
  164. /* we don't return! */
  165. return 0;
  166. };
  167. int checkcpu(void)
  168. {
  169. char buf[32];
  170. printf("CPU: Freescale Coldfire MCF5275 at %s MHz\n",
  171. strmhz(buf, CFG_CLK));
  172. return 0;
  173. };
  174. #if defined(CONFIG_WATCHDOG)
  175. /* Called by macro WATCHDOG_RESET */
  176. void watchdog_reset(void)
  177. {
  178. volatile wdog_t *wdt = (volatile wdog_t *)(MMAP_WDOG);
  179. wdt->wsr = 0x5555;
  180. wdt->wsr = 0xAAAA;
  181. }
  182. int watchdog_disable(void)
  183. {
  184. volatile wdog_t *wdt = (volatile wdog_t *)(MMAP_WDOG);
  185. wdt->wsr = 0x5555; /* reset watchdog counter */
  186. wdt->wsr = 0xAAAA;
  187. wdt->wcr = 0; /* disable watchdog timer */
  188. puts("WATCHDOG:disabled\n");
  189. return (0);
  190. }
  191. int watchdog_init(void)
  192. {
  193. volatile wdog_t *wdt = (volatile wdog_t *)(MMAP_WDOG);
  194. wdt->wcr = 0; /* disable watchdog */
  195. /* set timeout and enable watchdog */
  196. wdt->wmr =
  197. ((CONFIG_WATCHDOG_TIMEOUT * CFG_HZ) / (32768 * 1000)) - 1;
  198. wdt->wsr = 0x5555; /* reset watchdog counter */
  199. wdt->wsr = 0xAAAA;
  200. puts("WATCHDOG:enabled\n");
  201. return (0);
  202. }
  203. #endif /* #ifdef CONFIG_WATCHDOG */
  204. #endif /* #ifdef CONFIG_M5275 */
  205. #ifdef CONFIG_M5282
  206. int checkcpu(void)
  207. {
  208. unsigned char resetsource = MCFRESET_RSR;
  209. printf("CPU: Freescale Coldfire MCF5282 (PIN: %2.2x REV: %2.2x)\n",
  210. MCFCCM_CIR >> 8, MCFCCM_CIR & MCFCCM_CIR_PRN_MASK);
  211. printf("Reset:%s%s%s%s%s%s%s\n",
  212. (resetsource & MCFRESET_RSR_LOL) ? " Loss of Lock" : "",
  213. (resetsource & MCFRESET_RSR_LOC) ? " Loss of Clock" : "",
  214. (resetsource & MCFRESET_RSR_EXT) ? " External" : "",
  215. (resetsource & MCFRESET_RSR_POR) ? " Power On" : "",
  216. (resetsource & MCFRESET_RSR_WDR) ? " Watchdog" : "",
  217. (resetsource & MCFRESET_RSR_SOFT) ? " Software" : "",
  218. (resetsource & MCFRESET_RSR_LVD) ? " Low Voltage" : "");
  219. return 0;
  220. }
  221. int do_reset(cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc, char *argv[])
  222. {
  223. MCFRESET_RCR = MCFRESET_RCR_SOFTRST;
  224. return 0;
  225. };
  226. #endif
  227. #ifdef CONFIG_M5249
  228. int checkcpu(void)
  229. {
  230. char buf[32];
  231. printf("CPU: Freescale Coldfire MCF5249 at %s MHz\n",
  232. strmhz(buf, CFG_CLK));
  233. return 0;
  234. }
  235. int do_reset(cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc, char *argv[])
  236. {
  237. /* enable watchdog, set timeout to 0 and wait */
  238. mbar_writeByte(MCFSIM_SYPCR, 0xc0);
  239. while (1) ;
  240. /* we don't return! */
  241. return 0;
  242. };
  243. #endif
  244. #ifdef CONFIG_M5253
  245. int checkcpu(void)
  246. {
  247. char buf[32];
  248. unsigned char resetsource = mbar_readLong(SIM_RSR);
  249. printf("CPU: Freescale Coldfire MCF5253 at %s MHz\n",
  250. strmhz(buf, CFG_CLK));
  251. if ((resetsource & SIM_RSR_HRST) || (resetsource & SIM_RSR_SWTR)) {
  252. printf("Reset:%s%s\n",
  253. (resetsource & SIM_RSR_HRST) ? " Hardware/ System Reset"
  254. : "",
  255. (resetsource & SIM_RSR_SWTR) ? " Software Watchdog" :
  256. "");
  257. }
  258. return 0;
  259. }
  260. int do_reset(cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc, char *argv[])
  261. {
  262. /* enable watchdog, set timeout to 0 and wait */
  263. mbar_writeByte(SIM_SYPCR, 0xc0);
  264. while (1) ;
  265. /* we don't return! */
  266. return 0;
  267. };
  268. #endif