cpu.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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. #include <netdev.h>
  35. #ifdef CONFIG_M5271
  36. /*
  37. * Both MCF5270 and MCF5271 are members of the MPC5271 family. Try to
  38. * determine which one we are running on, based on the Chip Identification
  39. * Register (CIR).
  40. */
  41. int checkcpu(void)
  42. {
  43. char buf[32];
  44. unsigned short cir; /* Chip Identification Register */
  45. unsigned short pin; /* Part identification number */
  46. unsigned char prn; /* Part revision number */
  47. char *cpu_model;
  48. cir = mbar_readShort(MCF_CCM_CIR);
  49. pin = cir >> MCF_CCM_CIR_PIN_LEN;
  50. prn = cir & MCF_CCM_CIR_PRN_MASK;
  51. switch (pin) {
  52. case MCF_CCM_CIR_PIN_MCF5270:
  53. cpu_model = "5270";
  54. break;
  55. case MCF_CCM_CIR_PIN_MCF5271:
  56. cpu_model = "5271";
  57. break;
  58. default:
  59. cpu_model = NULL;
  60. break;
  61. }
  62. if (cpu_model)
  63. printf("CPU: Freescale ColdFire MCF%s rev. %hu, at %s MHz\n",
  64. cpu_model, prn, strmhz(buf, CFG_CLK));
  65. else
  66. printf("CPU: Unknown - Freescale ColdFire MCF5271 family"
  67. " (PIN: 0x%x) rev. %hu, at %s MHz\n",
  68. pin, prn, strmhz(buf, CFG_CLK));
  69. return 0;
  70. }
  71. int do_reset(cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc, char *argv[])
  72. {
  73. mbar_writeByte(MCF_RCM_RCR,
  74. MCF_RCM_RCR_SOFTRST | MCF_RCM_RCR_FRCRSTOUT);
  75. return 0;
  76. };
  77. #if defined(CONFIG_WATCHDOG)
  78. void watchdog_reset(void)
  79. {
  80. mbar_writeShort(MCF_WTM_WSR, 0x5555);
  81. mbar_writeShort(MCF_WTM_WSR, 0xAAAA);
  82. }
  83. int watchdog_disable(void)
  84. {
  85. mbar_writeShort(MCF_WTM_WCR, 0);
  86. return (0);
  87. }
  88. int watchdog_init(void)
  89. {
  90. mbar_writeShort(MCF_WTM_WCR, MCF_WTM_WCR_EN);
  91. return (0);
  92. }
  93. #endif /* #ifdef CONFIG_WATCHDOG */
  94. #endif
  95. #ifdef CONFIG_M5272
  96. int do_reset(cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc, char *argv[])
  97. {
  98. volatile wdog_t *wdp = (wdog_t *) (MMAP_WDOG);
  99. wdp->wdog_wrrr = 0;
  100. udelay(1000);
  101. /* enable watchdog, set timeout to 0 and wait */
  102. wdp->wdog_wrrr = 1;
  103. while (1) ;
  104. /* we don't return! */
  105. return 0;
  106. };
  107. int checkcpu(void)
  108. {
  109. volatile sysctrl_t *sysctrl = (sysctrl_t *) (MMAP_CFG);
  110. uchar msk;
  111. char *suf;
  112. puts("CPU: ");
  113. msk = (sysctrl->sc_dir > 28) & 0xf;
  114. switch (msk) {
  115. case 0x2:
  116. suf = "1K75N";
  117. break;
  118. case 0x4:
  119. suf = "3K75N";
  120. break;
  121. default:
  122. suf = NULL;
  123. printf("Freescale MCF5272 (Mask:%01x)\n", msk);
  124. break;
  125. }
  126. if (suf)
  127. printf("Freescale MCF5272 %s\n", suf);
  128. return 0;
  129. };
  130. #if defined(CONFIG_WATCHDOG)
  131. /* Called by macro WATCHDOG_RESET */
  132. void watchdog_reset(void)
  133. {
  134. volatile wdog_t *wdt = (volatile wdog_t *)(MMAP_WDOG);
  135. wdt->wdog_wcr = 0;
  136. }
  137. int watchdog_disable(void)
  138. {
  139. volatile wdog_t *wdt = (volatile wdog_t *)(MMAP_WDOG);
  140. wdt->wdog_wcr = 0; /* reset watchdog counter */
  141. wdt->wdog_wirr = 0; /* disable watchdog interrupt */
  142. wdt->wdog_wrrr = 0; /* disable watchdog timer */
  143. puts("WATCHDOG:disabled\n");
  144. return (0);
  145. }
  146. int watchdog_init(void)
  147. {
  148. volatile wdog_t *wdt = (volatile wdog_t *)(MMAP_WDOG);
  149. wdt->wdog_wirr = 0; /* disable watchdog interrupt */
  150. /* set timeout and enable watchdog */
  151. wdt->wdog_wrrr =
  152. ((CONFIG_WATCHDOG_TIMEOUT * CFG_HZ) / (32768 * 1000)) - 1;
  153. wdt->wdog_wcr = 0; /* reset watchdog counter */
  154. puts("WATCHDOG:enabled\n");
  155. return (0);
  156. }
  157. #endif /* #ifdef CONFIG_WATCHDOG */
  158. #endif /* #ifdef CONFIG_M5272 */
  159. #ifdef CONFIG_M5275
  160. int do_reset(cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
  161. {
  162. volatile rcm_t *rcm = (rcm_t *)(MMAP_RCM);
  163. udelay(1000);
  164. rcm->rcr = RCM_RCR_SOFTRST;
  165. /* we don't return! */
  166. return 0;
  167. };
  168. int checkcpu(void)
  169. {
  170. char buf[32];
  171. printf("CPU: Freescale Coldfire MCF5275 at %s MHz\n",
  172. strmhz(buf, CFG_CLK));
  173. return 0;
  174. };
  175. #if defined(CONFIG_WATCHDOG)
  176. /* Called by macro WATCHDOG_RESET */
  177. void watchdog_reset(void)
  178. {
  179. volatile wdog_t *wdt = (volatile wdog_t *)(MMAP_WDOG);
  180. wdt->wsr = 0x5555;
  181. wdt->wsr = 0xAAAA;
  182. }
  183. int watchdog_disable(void)
  184. {
  185. volatile wdog_t *wdt = (volatile wdog_t *)(MMAP_WDOG);
  186. wdt->wsr = 0x5555; /* reset watchdog counter */
  187. wdt->wsr = 0xAAAA;
  188. wdt->wcr = 0; /* disable watchdog timer */
  189. puts("WATCHDOG:disabled\n");
  190. return (0);
  191. }
  192. int watchdog_init(void)
  193. {
  194. volatile wdog_t *wdt = (volatile wdog_t *)(MMAP_WDOG);
  195. wdt->wcr = 0; /* disable watchdog */
  196. /* set timeout and enable watchdog */
  197. wdt->wmr =
  198. ((CONFIG_WATCHDOG_TIMEOUT * CFG_HZ) / (32768 * 1000)) - 1;
  199. wdt->wsr = 0x5555; /* reset watchdog counter */
  200. wdt->wsr = 0xAAAA;
  201. puts("WATCHDOG:enabled\n");
  202. return (0);
  203. }
  204. #endif /* #ifdef CONFIG_WATCHDOG */
  205. #endif /* #ifdef CONFIG_M5275 */
  206. #ifdef CONFIG_M5282
  207. int checkcpu(void)
  208. {
  209. unsigned char resetsource = MCFRESET_RSR;
  210. printf("CPU: Freescale Coldfire MCF5282 (PIN: %2.2x REV: %2.2x)\n",
  211. MCFCCM_CIR >> 8, MCFCCM_CIR & MCFCCM_CIR_PRN_MASK);
  212. printf("Reset:%s%s%s%s%s%s%s\n",
  213. (resetsource & MCFRESET_RSR_LOL) ? " Loss of Lock" : "",
  214. (resetsource & MCFRESET_RSR_LOC) ? " Loss of Clock" : "",
  215. (resetsource & MCFRESET_RSR_EXT) ? " External" : "",
  216. (resetsource & MCFRESET_RSR_POR) ? " Power On" : "",
  217. (resetsource & MCFRESET_RSR_WDR) ? " Watchdog" : "",
  218. (resetsource & MCFRESET_RSR_SOFT) ? " Software" : "",
  219. (resetsource & MCFRESET_RSR_LVD) ? " Low Voltage" : "");
  220. return 0;
  221. }
  222. int do_reset(cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc, char *argv[])
  223. {
  224. MCFRESET_RCR = MCFRESET_RCR_SOFTRST;
  225. return 0;
  226. };
  227. #endif
  228. #ifdef CONFIG_M5249
  229. int checkcpu(void)
  230. {
  231. char buf[32];
  232. printf("CPU: Freescale Coldfire MCF5249 at %s MHz\n",
  233. strmhz(buf, CFG_CLK));
  234. return 0;
  235. }
  236. int do_reset(cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc, char *argv[])
  237. {
  238. /* enable watchdog, set timeout to 0 and wait */
  239. mbar_writeByte(MCFSIM_SYPCR, 0xc0);
  240. while (1) ;
  241. /* we don't return! */
  242. return 0;
  243. };
  244. #endif
  245. #ifdef CONFIG_M5253
  246. int checkcpu(void)
  247. {
  248. char buf[32];
  249. unsigned char resetsource = mbar_readLong(SIM_RSR);
  250. printf("CPU: Freescale Coldfire MCF5253 at %s MHz\n",
  251. strmhz(buf, CFG_CLK));
  252. if ((resetsource & SIM_RSR_HRST) || (resetsource & SIM_RSR_SWTR)) {
  253. printf("Reset:%s%s\n",
  254. (resetsource & SIM_RSR_HRST) ? " Hardware/ System Reset"
  255. : "",
  256. (resetsource & SIM_RSR_SWTR) ? " Software Watchdog" :
  257. "");
  258. }
  259. return 0;
  260. }
  261. int do_reset(cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc, char *argv[])
  262. {
  263. /* enable watchdog, set timeout to 0 and wait */
  264. mbar_writeByte(SIM_SYPCR, 0xc0);
  265. while (1) ;
  266. /* we don't return! */
  267. return 0;
  268. };
  269. #endif
  270. #if defined(CONFIG_MCFFEC)
  271. /* Default initializations for MCFFEC controllers. To override,
  272. * create a board-specific function called:
  273. * int board_eth_init(bd_t *bis)
  274. */
  275. int cpu_eth_init(bd_t *bis)
  276. {
  277. return mcffec_initialize(bis);
  278. }
  279. #endif