cpu.c 8.9 KB

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