blob: aa6b2bd670cea9c61025ccbe1478fb55c4446df7 [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 *
wdenkbf9e3b32004-02-12 00:47:09 +00009 * See file CREDITS for list of people who contributed to this
10 * project.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 * MA 02111-1307 USA
26 */
27
28#include <common.h>
29#include <watchdog.h>
30#include <command.h>
31
Zachary P. Landaueacbd312006-01-26 17:35:56 -050032#ifdef CONFIG_M5271
33#include <asm/immap_5271.h>
34#include <asm/m5271.h>
35#endif
36
wdenkbf9e3b32004-02-12 00:47:09 +000037#ifdef CONFIG_M5272
38#include <asm/immap_5272.h>
39#include <asm/m5272.h>
40#endif
41
42#ifdef CONFIG_M5282
Heiko Schocher9acb6262006-04-20 08:42:42 +020043#include <asm/m5282.h>
44#include <asm/immap_5282.h>
wdenkbf9e3b32004-02-12 00:47:09 +000045#endif
46
stroese8c725b92004-12-16 18:09:49 +000047#ifdef CONFIG_M5249
48#include <asm/m5249.h>
49#endif
50
Zachary P. Landaueacbd312006-01-26 17:35:56 -050051#ifdef CONFIG_M5271
52int checkcpu (void)
53{
Marian Balakowiczb75ef852006-05-09 11:45:31 +020054 char buf[32];
55
56 printf ("CPU: Freescale Coldfire MCF5271 at %s MHz\n", strmhz(buf, CFG_CLK));
Zachary P. Landaueacbd312006-01-26 17:35:56 -050057 return 0;
58}
59
60int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]) {
61 mbar_writeByte(MCF_RCM_RCR,
62 MCF_RCM_RCR_SOFTRST | MCF_RCM_RCR_FRCRSTOUT);
63 return 0;
64};
65
66#if defined(CONFIG_WATCHDOG)
67void watchdog_reset (void)
68{
69 mbar_writeShort(MCF_WTM_WSR, 0x5555);
70 mbar_writeShort(MCF_WTM_WSR, 0xAAAA);
71}
72
73int watchdog_disable (void)
74{
75 mbar_writeShort(MCF_WTM_WCR, 0);
76 return (0);
77}
78
79int watchdog_init (void)
80{
Zachary P. Landaueacbd312006-01-26 17:35:56 -050081 mbar_writeShort(MCF_WTM_WCR, MCF_WTM_WCR_EN);
82 return (0);
83}
84#endif /* #ifdef CONFIG_WATCHDOG */
85
86#endif
wdenkbf9e3b32004-02-12 00:47:09 +000087
88#ifdef CONFIG_M5272
89int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]) {
90 volatile wdog_t * wdp = (wdog_t *)(CFG_MBAR + MCFSIM_WRRR);
91
92 wdp->wdog_wrrr = 0;
93 udelay (1000);
94
95 /* enable watchdog, set timeout to 0 and wait */
96 wdp->wdog_wrrr = 1;
97 while (1);
98
99 /* we don't return! */
100 return 0;
101};
102
103int checkcpu(void) {
104 ulong *dirp = (ulong *)(CFG_MBAR + MCFSIM_DIR);
105 uchar msk;
106 char *suf;
107
108 puts ("CPU: ");
109 msk = (*dirp > 28) & 0xf;
110 switch (msk) {
111 case 0x2: suf = "1K75N"; break;
112 case 0x4: suf = "3K75N"; break;
113 default:
114 suf = NULL;
Marian Balakowiczb75ef852006-05-09 11:45:31 +0200115 printf ("Freescale MCF5272 (Mask:%01x)\n", msk);
wdenkbf9e3b32004-02-12 00:47:09 +0000116 break;
117 }
118
119 if (suf)
Marian Balakowiczb75ef852006-05-09 11:45:31 +0200120 printf ("Freescale MCF5272 %s\n", suf);
wdenkbf9e3b32004-02-12 00:47:09 +0000121 return 0;
122};
123
wdenkbf9e3b32004-02-12 00:47:09 +0000124#if defined(CONFIG_WATCHDOG)
125/* Called by macro WATCHDOG_RESET */
126void watchdog_reset (void)
127{
128 volatile immap_t * regp = (volatile immap_t *)CFG_MBAR;
129 regp->wdog_reg.wdog_wcr = 0;
130}
131
132int watchdog_disable (void)
133{
134 volatile immap_t *regp = (volatile immap_t *)CFG_MBAR;
135
136 regp->wdog_reg.wdog_wcr = 0; /* reset watchdog counter */
137 regp->wdog_reg.wdog_wirr = 0; /* disable watchdog interrupt */
138 regp->wdog_reg.wdog_wrrr = 0; /* disable watchdog timer */
139
140 puts ("WATCHDOG:disabled\n");
141 return (0);
142}
143
144int watchdog_init (void)
145{
146 volatile immap_t *regp = (volatile immap_t *)CFG_MBAR;
147
148 regp->wdog_reg.wdog_wirr = 0; /* disable watchdog interrupt */
149
150 /* set timeout and enable watchdog */
151 regp->wdog_reg.wdog_wrrr = ((CONFIG_WATCHDOG_TIMEOUT * CFG_HZ) / (32768 * 1000)) - 1;
152 regp->wdog_reg.wdog_wcr = 0; /* reset watchdog counter */
153
154 puts ("WATCHDOG:enabled\n");
155 return (0);
156}
157#endif /* #ifdef CONFIG_WATCHDOG */
158
159#endif /* #ifdef CONFIG_M5272 */
160
161
162#ifdef CONFIG_M5282
163int checkcpu (void)
164{
Wolfgang Denk4176c792006-06-10 19:27:47 +0200165 unsigned char resetsource = MCFRESET_RSR;
Heiko Schocher9acb6262006-04-20 08:42:42 +0200166
Wolfgang Denk4176c792006-06-10 19:27:47 +0200167 printf ("CPU: Freescale Coldfire MCF5282 (PIN: %2.2x REV: %2.2x)\n",
Heiko Schocher9acb6262006-04-20 08:42:42 +0200168 MCFCCM_CIR>>8,MCFCCM_CIR & MCFCCM_CIR_PRN_MASK);
Wolfgang Denk4176c792006-06-10 19:27:47 +0200169 printf ("Reset:%s%s%s%s%s%s%s\n",
170 (resetsource & MCFRESET_RSR_LOL) ? " Loss of Lock" : "",
171 (resetsource & MCFRESET_RSR_LOC) ? " Loss of Clock" : "",
172 (resetsource & MCFRESET_RSR_EXT) ? " External" : "",
173 (resetsource & MCFRESET_RSR_POR) ? " Power On" : "",
174 (resetsource & MCFRESET_RSR_WDR) ? " Watchdog" : "",
175 (resetsource & MCFRESET_RSR_SOFT) ? " Software" : "",
176 (resetsource & MCFRESET_RSR_LVD) ? " Low Voltage" : ""
177 );
wdenkbf9e3b32004-02-12 00:47:09 +0000178 return 0;
179}
180
Heiko Schocher9acb6262006-04-20 08:42:42 +0200181int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
182{
183 MCFRESET_RCR = MCFRESET_RCR_SOFTRST;
wdenkbf9e3b32004-02-12 00:47:09 +0000184 return 0;
185};
186#endif
stroese8c725b92004-12-16 18:09:49 +0000187
188#ifdef CONFIG_M5249 /* test-only: todo... */
189int checkcpu (void)
190{
191 char buf[32];
192
Marian Balakowiczb75ef852006-05-09 11:45:31 +0200193 printf ("CPU: Freescale Coldfire MCF5249 at %s MHz\n", strmhz(buf, CFG_CLK));
stroese8c725b92004-12-16 18:09:49 +0000194 return 0;
195}
196
197int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]) {
198 /* enable watchdog, set timeout to 0 and wait */
199 mbar_writeByte(MCFSIM_SYPCR, 0xc0);
200 while (1);
201
202 /* we don't return! */
203 return 0;
204};
205#endif