cpu.c 9.1 KB

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