cpu.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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, 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 counter */
  67. wdt->sr = 0xAAAA;
  68. wdt->cr = 0; /* disable watchdog timer */
  69. puts("WATCHDOG:disabled\n");
  70. return (0);
  71. }
  72. int watchdog_init(void)
  73. {
  74. volatile wdog_t *wdt = (volatile wdog_t *)(MMAP_WDOG);
  75. wdt->cr = 0; /* disable watchdog */
  76. /* set timeout and enable watchdog */
  77. wdt->mr =
  78. ((CONFIG_WATCHDOG_TIMEOUT * CONFIG_SYS_HZ) / (32768 * 1000)) - 1;
  79. wdt->sr = 0x5555; /* reset watchdog counter */
  80. wdt->sr = 0xAAAA;
  81. puts("WATCHDOG:enabled\n");
  82. return (0);
  83. }
  84. #endif /* #ifdef CONFIG_WATCHDOG */
  85. #endif /* #ifdef CONFIG_M5208 */
  86. #ifdef CONFIG_M5271
  87. /*
  88. * Both MCF5270 and MCF5271 are members of the MPC5271 family. Try to
  89. * determine which one we are running on, based on the Chip Identification
  90. * Register (CIR).
  91. */
  92. int checkcpu(void)
  93. {
  94. char buf[32];
  95. unsigned short cir; /* Chip Identification Register */
  96. unsigned short pin; /* Part identification number */
  97. unsigned char prn; /* Part revision number */
  98. char *cpu_model;
  99. cir = mbar_readShort(MCF_CCM_CIR);
  100. pin = cir >> MCF_CCM_CIR_PIN_LEN;
  101. prn = cir & MCF_CCM_CIR_PRN_MASK;
  102. switch (pin) {
  103. case MCF_CCM_CIR_PIN_MCF5270:
  104. cpu_model = "5270";
  105. break;
  106. case MCF_CCM_CIR_PIN_MCF5271:
  107. cpu_model = "5271";
  108. break;
  109. default:
  110. cpu_model = NULL;
  111. break;
  112. }
  113. if (cpu_model)
  114. printf("CPU: Freescale ColdFire MCF%s rev. %hu, at %s MHz\n",
  115. cpu_model, prn, strmhz(buf, CONFIG_SYS_CLK));
  116. else
  117. printf("CPU: Unknown - Freescale ColdFire MCF5271 family"
  118. " (PIN: 0x%x) rev. %hu, at %s MHz\n",
  119. pin, prn, strmhz(buf, CONFIG_SYS_CLK));
  120. return 0;
  121. }
  122. int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  123. {
  124. /* Call the board specific reset actions first. */
  125. if(board_reset) {
  126. board_reset();
  127. }
  128. mbar_writeByte(MCF_RCM_RCR,
  129. MCF_RCM_RCR_SOFTRST | MCF_RCM_RCR_FRCRSTOUT);
  130. return 0;
  131. };
  132. #if defined(CONFIG_WATCHDOG)
  133. void watchdog_reset(void)
  134. {
  135. mbar_writeShort(MCF_WTM_WSR, 0x5555);
  136. mbar_writeShort(MCF_WTM_WSR, 0xAAAA);
  137. }
  138. int watchdog_disable(void)
  139. {
  140. mbar_writeShort(MCF_WTM_WCR, 0);
  141. return (0);
  142. }
  143. int watchdog_init(void)
  144. {
  145. mbar_writeShort(MCF_WTM_WCR, MCF_WTM_WCR_EN);
  146. return (0);
  147. }
  148. #endif /* #ifdef CONFIG_WATCHDOG */
  149. #endif
  150. #ifdef CONFIG_M5272
  151. int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  152. {
  153. volatile wdog_t *wdp = (wdog_t *) (MMAP_WDOG);
  154. wdp->wdog_wrrr = 0;
  155. udelay(1000);
  156. /* enable watchdog, set timeout to 0 and wait */
  157. wdp->wdog_wrrr = 1;
  158. while (1) ;
  159. /* we don't return! */
  160. return 0;
  161. };
  162. int checkcpu(void)
  163. {
  164. volatile sysctrl_t *sysctrl = (sysctrl_t *) (MMAP_CFG);
  165. uchar msk;
  166. char *suf;
  167. puts("CPU: ");
  168. msk = (sysctrl->sc_dir > 28) & 0xf;
  169. switch (msk) {
  170. case 0x2:
  171. suf = "1K75N";
  172. break;
  173. case 0x4:
  174. suf = "3K75N";
  175. break;
  176. default:
  177. suf = NULL;
  178. printf("Freescale MCF5272 (Mask:%01x)\n", msk);
  179. break;
  180. }
  181. if (suf)
  182. printf("Freescale MCF5272 %s\n", suf);
  183. return 0;
  184. };
  185. #if defined(CONFIG_WATCHDOG)
  186. /* Called by macro WATCHDOG_RESET */
  187. void watchdog_reset(void)
  188. {
  189. volatile wdog_t *wdt = (volatile wdog_t *)(MMAP_WDOG);
  190. wdt->wdog_wcr = 0;
  191. }
  192. int watchdog_disable(void)
  193. {
  194. volatile wdog_t *wdt = (volatile wdog_t *)(MMAP_WDOG);
  195. wdt->wdog_wcr = 0; /* reset watchdog counter */
  196. wdt->wdog_wirr = 0; /* disable watchdog interrupt */
  197. wdt->wdog_wrrr = 0; /* disable watchdog timer */
  198. puts("WATCHDOG:disabled\n");
  199. return (0);
  200. }
  201. int watchdog_init(void)
  202. {
  203. volatile wdog_t *wdt = (volatile wdog_t *)(MMAP_WDOG);
  204. wdt->wdog_wirr = 0; /* disable watchdog interrupt */
  205. /* set timeout and enable watchdog */
  206. wdt->wdog_wrrr =
  207. ((CONFIG_WATCHDOG_TIMEOUT * CONFIG_SYS_HZ) / (32768 * 1000)) - 1;
  208. wdt->wdog_wcr = 0; /* reset watchdog counter */
  209. puts("WATCHDOG:enabled\n");
  210. return (0);
  211. }
  212. #endif /* #ifdef CONFIG_WATCHDOG */
  213. #endif /* #ifdef CONFIG_M5272 */
  214. #ifdef CONFIG_M5275
  215. int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  216. {
  217. volatile rcm_t *rcm = (rcm_t *)(MMAP_RCM);
  218. udelay(1000);
  219. rcm->rcr = RCM_RCR_SOFTRST;
  220. /* we don't return! */
  221. return 0;
  222. };
  223. int checkcpu(void)
  224. {
  225. char buf[32];
  226. printf("CPU: Freescale Coldfire MCF5275 at %s MHz\n",
  227. strmhz(buf, CONFIG_SYS_CLK));
  228. return 0;
  229. };
  230. #if defined(CONFIG_WATCHDOG)
  231. /* Called by macro WATCHDOG_RESET */
  232. void watchdog_reset(void)
  233. {
  234. volatile wdog_t *wdt = (volatile wdog_t *)(MMAP_WDOG);
  235. wdt->wsr = 0x5555;
  236. wdt->wsr = 0xAAAA;
  237. }
  238. int watchdog_disable(void)
  239. {
  240. volatile wdog_t *wdt = (volatile wdog_t *)(MMAP_WDOG);
  241. wdt->wsr = 0x5555; /* reset watchdog counter */
  242. wdt->wsr = 0xAAAA;
  243. wdt->wcr = 0; /* disable watchdog timer */
  244. puts("WATCHDOG:disabled\n");
  245. return (0);
  246. }
  247. int watchdog_init(void)
  248. {
  249. volatile wdog_t *wdt = (volatile wdog_t *)(MMAP_WDOG);
  250. wdt->wcr = 0; /* disable watchdog */
  251. /* set timeout and enable watchdog */
  252. wdt->wmr =
  253. ((CONFIG_WATCHDOG_TIMEOUT * CONFIG_SYS_HZ) / (32768 * 1000)) - 1;
  254. wdt->wsr = 0x5555; /* reset watchdog counter */
  255. 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