cpu.c 8.9 KB

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