blob: 2cfe6311d08863606207db7f686b7ab84eb76a59 [file] [log] [blame]
wdenkbf9e3b32004-02-12 00:47:09 +00001/*
2 * (C) Copyright 2003
3 * Josef Baumgartner <josef.baumgartner@telex.de>
4 *
Heiko Schocher9acb6262006-04-20 08:42:42 +02005 * MCF5282 additionals
6 * (C) Copyright 2005
7 * BuS Elektronik GmbH & Co. KG <esw@bus-elektronik.de>
8 *
Matthew Fettkef71d9d92008-02-04 15:38:20 -06009 * MCF5275 additions
10 * Copyright (C) 2008 Arthur Shipkowski (art@videon-central.com)
11 *
wdenkbf9e3b32004-02-12 00:47:09 +000012 * 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
31#include <common.h>
32#include <watchdog.h>
33#include <command.h>
TsiChungLiew83ec20b2007-08-15 19:21:21 -050034#include <asm/immap.h>
Ben Warren89973f82008-08-31 22:22:04 -070035#include <netdev.h>
wdenkbf9e3b32004-02-12 00:47:09 +000036
TsiChung Liewbf9a5212009-06-12 11:29:00 +000037DECLARE_GLOBAL_DATA_PTR;
38
39#ifdef CONFIG_M5208
40int do_reset(cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
41{
42 volatile rcm_t *rcm = (rcm_t *)(MMAP_RCM);
43
44 udelay(1000);
45
46 rcm->rcr = RCM_RCR_SOFTRST;
47
48 /* we don't return! */
49 return 0;
50};
51
52int checkcpu(void)
53{
54 char buf1[32], buf2[32];
55
56 printf("CPU: Freescale Coldfire MCF5208\n"
57 " CPU CLK %s MHz BUS CLK %s MHz\n",
58 strmhz(buf1, gd->cpu_clk),
59 strmhz(buf2, gd->bus_clk));
60 return 0;
61};
62
63#if defined(CONFIG_WATCHDOG)
64/* Called by macro WATCHDOG_RESET */
65void watchdog_reset(void)
66{
67 volatile wdog_t *wdt = (volatile wdog_t *)(MMAP_WDOG);
68 wdt->sr = 0x5555;
69 wdt->sr = 0xAAAA;
70}
71
72int watchdog_disable(void)
73{
74 volatile wdog_t *wdt = (volatile wdog_t *)(MMAP_WDOG);
75
76 wdt->sr = 0x5555; /* reset watchdog counteDECLARE_GLOBAL_DATA_PTR;
77r */
78 wdt->sr = 0xAAAA;
79 wdt->cr = 0; /* disable watchdog timer */
80
81 puts("WATCHDOG:disabled\n");
82 return (0);
83}
84
85int watchdog_init(void)
86{
87 volatile wdog_t *wdt = (volatile wdog_t *)(MMAP_WDOG);
88
89 wdt->cr = 0; /* disable watchdog */
90
91 /* set timeout and enable watchdog */
92 wdt->mr =
93 ((CONFIG_WATCHDOG_TIMEOUT * CONFIG_SYS_HZ) / (32768 * 1000)) - 1;
94 wdt->sr = 0x5555; /* reset watchdog counter */
95 wdt->sr = 0xAAAA;
96
97 puts("WATCHDOG:enabled\n");
98 return (0);
99}
100#endif /* #ifdef CONFIG_WATCHDOG */
101#endif /* #ifdef CONFIG_M5208 */
102
Zachary P. Landaueacbd312006-01-26 17:35:56 -0500103#ifdef CONFIG_M5271
Bartlomiej Sieka363d1d82007-01-23 13:25:22 +0100104/*
105 * Both MCF5270 and MCF5271 are members of the MPC5271 family. Try to
106 * determine which one we are running on, based on the Chip Identification
107 * Register (CIR).
108 */
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500109int checkcpu(void)
Zachary P. Landaueacbd312006-01-26 17:35:56 -0500110{
Marian Balakowiczb75ef852006-05-09 11:45:31 +0200111 char buf[32];
Bartlomiej Sieka363d1d82007-01-23 13:25:22 +0100112 unsigned short cir; /* Chip Identification Register */
113 unsigned short pin; /* Part identification number */
114 unsigned char prn; /* Part revision number */
115 char *cpu_model;
Marian Balakowiczb75ef852006-05-09 11:45:31 +0200116
Bartlomiej Sieka363d1d82007-01-23 13:25:22 +0100117 cir = mbar_readShort(MCF_CCM_CIR);
118 pin = cir >> MCF_CCM_CIR_PIN_LEN;
119 prn = cir & MCF_CCM_CIR_PRN_MASK;
120
121 switch (pin) {
122 case MCF_CCM_CIR_PIN_MCF5270:
123 cpu_model = "5270";
124 break;
125 case MCF_CCM_CIR_PIN_MCF5271:
126 cpu_model = "5271";
127 break;
128 default:
129 cpu_model = NULL;
130 break;
131 }
132
133 if (cpu_model)
134 printf("CPU: Freescale ColdFire MCF%s rev. %hu, at %s MHz\n",
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200135 cpu_model, prn, strmhz(buf, CONFIG_SYS_CLK));
Bartlomiej Sieka363d1d82007-01-23 13:25:22 +0100136 else
137 printf("CPU: Unknown - Freescale ColdFire MCF5271 family"
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500138 " (PIN: 0x%x) rev. %hu, at %s MHz\n",
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200139 pin, prn, strmhz(buf, CONFIG_SYS_CLK));
Bartlomiej Sieka363d1d82007-01-23 13:25:22 +0100140
Zachary P. Landaueacbd312006-01-26 17:35:56 -0500141 return 0;
142}
143
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500144int do_reset(cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc, char *argv[])
145{
Zachary P. Landaueacbd312006-01-26 17:35:56 -0500146 mbar_writeByte(MCF_RCM_RCR,
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500147 MCF_RCM_RCR_SOFTRST | MCF_RCM_RCR_FRCRSTOUT);
Zachary P. Landaueacbd312006-01-26 17:35:56 -0500148 return 0;
149};
150
151#if defined(CONFIG_WATCHDOG)
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500152void watchdog_reset(void)
Zachary P. Landaueacbd312006-01-26 17:35:56 -0500153{
154 mbar_writeShort(MCF_WTM_WSR, 0x5555);
155 mbar_writeShort(MCF_WTM_WSR, 0xAAAA);
156}
157
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500158int watchdog_disable(void)
Zachary P. Landaueacbd312006-01-26 17:35:56 -0500159{
160 mbar_writeShort(MCF_WTM_WCR, 0);
161 return (0);
162}
163
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500164int watchdog_init(void)
Zachary P. Landaueacbd312006-01-26 17:35:56 -0500165{
Zachary P. Landaueacbd312006-01-26 17:35:56 -0500166 mbar_writeShort(MCF_WTM_WCR, MCF_WTM_WCR_EN);
167 return (0);
168}
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500169#endif /* #ifdef CONFIG_WATCHDOG */
Zachary P. Landaueacbd312006-01-26 17:35:56 -0500170
171#endif
wdenkbf9e3b32004-02-12 00:47:09 +0000172
173#ifdef CONFIG_M5272
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500174int do_reset(cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc, char *argv[])
175{
176 volatile wdog_t *wdp = (wdog_t *) (MMAP_WDOG);
wdenkbf9e3b32004-02-12 00:47:09 +0000177
178 wdp->wdog_wrrr = 0;
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500179 udelay(1000);
wdenkbf9e3b32004-02-12 00:47:09 +0000180
181 /* enable watchdog, set timeout to 0 and wait */
182 wdp->wdog_wrrr = 1;
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500183 while (1) ;
wdenkbf9e3b32004-02-12 00:47:09 +0000184
185 /* we don't return! */
186 return 0;
187};
188
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500189int checkcpu(void)
190{
191 volatile sysctrl_t *sysctrl = (sysctrl_t *) (MMAP_CFG);
wdenkbf9e3b32004-02-12 00:47:09 +0000192 uchar msk;
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500193 char *suf;
wdenkbf9e3b32004-02-12 00:47:09 +0000194
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500195 puts("CPU: ");
196 msk = (sysctrl->sc_dir > 28) & 0xf;
wdenkbf9e3b32004-02-12 00:47:09 +0000197 switch (msk) {
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500198 case 0x2:
199 suf = "1K75N";
200 break;
201 case 0x4:
202 suf = "3K75N";
203 break;
204 default:
205 suf = NULL;
206 printf("Freescale MCF5272 (Mask:%01x)\n", msk);
207 break;
208 }
wdenkbf9e3b32004-02-12 00:47:09 +0000209
210 if (suf)
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500211 printf("Freescale MCF5272 %s\n", suf);
wdenkbf9e3b32004-02-12 00:47:09 +0000212 return 0;
213};
214
wdenkbf9e3b32004-02-12 00:47:09 +0000215#if defined(CONFIG_WATCHDOG)
216/* Called by macro WATCHDOG_RESET */
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500217void watchdog_reset(void)
wdenkbf9e3b32004-02-12 00:47:09 +0000218{
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500219 volatile wdog_t *wdt = (volatile wdog_t *)(MMAP_WDOG);
220 wdt->wdog_wcr = 0;
wdenkbf9e3b32004-02-12 00:47:09 +0000221}
222
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500223int watchdog_disable(void)
wdenkbf9e3b32004-02-12 00:47:09 +0000224{
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500225 volatile wdog_t *wdt = (volatile wdog_t *)(MMAP_WDOG);
wdenkbf9e3b32004-02-12 00:47:09 +0000226
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500227 wdt->wdog_wcr = 0; /* reset watchdog counter */
228 wdt->wdog_wirr = 0; /* disable watchdog interrupt */
229 wdt->wdog_wrrr = 0; /* disable watchdog timer */
wdenkbf9e3b32004-02-12 00:47:09 +0000230
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500231 puts("WATCHDOG:disabled\n");
wdenkbf9e3b32004-02-12 00:47:09 +0000232 return (0);
233}
234
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500235int watchdog_init(void)
wdenkbf9e3b32004-02-12 00:47:09 +0000236{
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500237 volatile wdog_t *wdt = (volatile wdog_t *)(MMAP_WDOG);
wdenkbf9e3b32004-02-12 00:47:09 +0000238
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500239 wdt->wdog_wirr = 0; /* disable watchdog interrupt */
wdenkbf9e3b32004-02-12 00:47:09 +0000240
241 /* set timeout and enable watchdog */
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500242 wdt->wdog_wrrr =
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200243 ((CONFIG_WATCHDOG_TIMEOUT * CONFIG_SYS_HZ) / (32768 * 1000)) - 1;
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500244 wdt->wdog_wcr = 0; /* reset watchdog counter */
wdenkbf9e3b32004-02-12 00:47:09 +0000245
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500246 puts("WATCHDOG:enabled\n");
wdenkbf9e3b32004-02-12 00:47:09 +0000247 return (0);
248}
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500249#endif /* #ifdef CONFIG_WATCHDOG */
wdenkbf9e3b32004-02-12 00:47:09 +0000250
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500251#endif /* #ifdef CONFIG_M5272 */
wdenkbf9e3b32004-02-12 00:47:09 +0000252
Matthew Fettkef71d9d92008-02-04 15:38:20 -0600253#ifdef CONFIG_M5275
254int do_reset(cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
255{
256 volatile rcm_t *rcm = (rcm_t *)(MMAP_RCM);
257
258 udelay(1000);
259
260 rcm->rcr = RCM_RCR_SOFTRST;
261
262 /* we don't return! */
263 return 0;
264};
265
266int checkcpu(void)
267{
268 char buf[32];
269
270 printf("CPU: Freescale Coldfire MCF5275 at %s MHz\n",
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200271 strmhz(buf, CONFIG_SYS_CLK));
Matthew Fettkef71d9d92008-02-04 15:38:20 -0600272 return 0;
273};
274
275
276#if defined(CONFIG_WATCHDOG)
277/* Called by macro WATCHDOG_RESET */
278void watchdog_reset(void)
279{
280 volatile wdog_t *wdt = (volatile wdog_t *)(MMAP_WDOG);
281 wdt->wsr = 0x5555;
282 wdt->wsr = 0xAAAA;
283}
284
285int watchdog_disable(void)
286{
287 volatile wdog_t *wdt = (volatile wdog_t *)(MMAP_WDOG);
288
289 wdt->wsr = 0x5555; /* reset watchdog counter */
290 wdt->wsr = 0xAAAA;
291 wdt->wcr = 0; /* disable watchdog timer */
292
293 puts("WATCHDOG:disabled\n");
294 return (0);
295}
296
297int watchdog_init(void)
298{
299 volatile wdog_t *wdt = (volatile wdog_t *)(MMAP_WDOG);
300
301 wdt->wcr = 0; /* disable watchdog */
302
303 /* set timeout and enable watchdog */
304 wdt->wmr =
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200305 ((CONFIG_WATCHDOG_TIMEOUT * CONFIG_SYS_HZ) / (32768 * 1000)) - 1;
Matthew Fettkef71d9d92008-02-04 15:38:20 -0600306 wdt->wsr = 0x5555; /* reset watchdog counter */
307 wdt->wsr = 0xAAAA;
308
309 puts("WATCHDOG:enabled\n");
310 return (0);
311}
312#endif /* #ifdef CONFIG_WATCHDOG */
313
314#endif /* #ifdef CONFIG_M5275 */
315
wdenkbf9e3b32004-02-12 00:47:09 +0000316#ifdef CONFIG_M5282
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500317int checkcpu(void)
wdenkbf9e3b32004-02-12 00:47:09 +0000318{
Wolfgang Denk4176c792006-06-10 19:27:47 +0200319 unsigned char resetsource = MCFRESET_RSR;
Heiko Schocher9acb6262006-04-20 08:42:42 +0200320
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500321 printf("CPU: Freescale Coldfire MCF5282 (PIN: %2.2x REV: %2.2x)\n",
322 MCFCCM_CIR >> 8, MCFCCM_CIR & MCFCCM_CIR_PRN_MASK);
323 printf("Reset:%s%s%s%s%s%s%s\n",
324 (resetsource & MCFRESET_RSR_LOL) ? " Loss of Lock" : "",
325 (resetsource & MCFRESET_RSR_LOC) ? " Loss of Clock" : "",
326 (resetsource & MCFRESET_RSR_EXT) ? " External" : "",
327 (resetsource & MCFRESET_RSR_POR) ? " Power On" : "",
328 (resetsource & MCFRESET_RSR_WDR) ? " Watchdog" : "",
329 (resetsource & MCFRESET_RSR_SOFT) ? " Software" : "",
330 (resetsource & MCFRESET_RSR_LVD) ? " Low Voltage" : "");
wdenkbf9e3b32004-02-12 00:47:09 +0000331 return 0;
332}
333
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500334int do_reset(cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc, char *argv[])
Heiko Schocher9acb6262006-04-20 08:42:42 +0200335{
336 MCFRESET_RCR = MCFRESET_RCR_SOFTRST;
wdenkbf9e3b32004-02-12 00:47:09 +0000337 return 0;
338};
339#endif
stroese8c725b92004-12-16 18:09:49 +0000340
TsiChungLiewa1436a82007-08-16 13:20:50 -0500341#ifdef CONFIG_M5249
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500342int checkcpu(void)
stroese8c725b92004-12-16 18:09:49 +0000343{
344 char buf[32];
345
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500346 printf("CPU: Freescale Coldfire MCF5249 at %s MHz\n",
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200347 strmhz(buf, CONFIG_SYS_CLK));
stroese8c725b92004-12-16 18:09:49 +0000348 return 0;
349}
350
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500351int do_reset(cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc, char *argv[])
352{
stroese8c725b92004-12-16 18:09:49 +0000353 /* enable watchdog, set timeout to 0 and wait */
354 mbar_writeByte(MCFSIM_SYPCR, 0xc0);
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500355 while (1) ;
stroese8c725b92004-12-16 18:09:49 +0000356
357 /* we don't return! */
358 return 0;
359};
360#endif
TsiChungLiewa1436a82007-08-16 13:20:50 -0500361
362#ifdef CONFIG_M5253
363int checkcpu(void)
364{
365 char buf[32];
366
367 unsigned char resetsource = mbar_readLong(SIM_RSR);
368 printf("CPU: Freescale Coldfire MCF5253 at %s MHz\n",
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200369 strmhz(buf, CONFIG_SYS_CLK));
TsiChungLiewa1436a82007-08-16 13:20:50 -0500370
371 if ((resetsource & SIM_RSR_HRST) || (resetsource & SIM_RSR_SWTR)) {
372 printf("Reset:%s%s\n",
373 (resetsource & SIM_RSR_HRST) ? " Hardware/ System Reset"
374 : "",
375 (resetsource & SIM_RSR_SWTR) ? " Software Watchdog" :
376 "");
377 }
378 return 0;
379}
380
381int do_reset(cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc, char *argv[])
382{
383 /* enable watchdog, set timeout to 0 and wait */
384 mbar_writeByte(SIM_SYPCR, 0xc0);
385 while (1) ;
386
387 /* we don't return! */
388 return 0;
389};
390#endif
Ben Warren86882b82008-08-26 22:16:25 -0700391
392#if defined(CONFIG_MCFFEC)
393/* Default initializations for MCFFEC controllers. To override,
394 * create a board-specific function called:
395 * int board_eth_init(bd_t *bis)
396 */
397
Ben Warren86882b82008-08-26 22:16:25 -0700398int cpu_eth_init(bd_t *bis)
399{
400 return mcffec_initialize(bis);
401}
402#endif