cpu.c 8.9 KB

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