cpu.c 9.1 KB

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