cpu.c 8.4 KB

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