blob: ce59d39cfab4f65f8db3968eaf87c3a6c88fb410 [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
Bartlomiej Sieka363d1d82007-01-23 13:25:22 +010052/*
53 * Both MCF5270 and MCF5271 are members of the MPC5271 family. Try to
54 * determine which one we are running on, based on the Chip Identification
55 * Register (CIR).
56 */
Zachary P. Landaueacbd312006-01-26 17:35:56 -050057int checkcpu (void)
58{
Marian Balakowiczb75ef852006-05-09 11:45:31 +020059 char buf[32];
Bartlomiej Sieka363d1d82007-01-23 13:25:22 +010060 unsigned short cir; /* Chip Identification Register */
61 unsigned short pin; /* Part identification number */
62 unsigned char prn; /* Part revision number */
63 char *cpu_model;
Marian Balakowiczb75ef852006-05-09 11:45:31 +020064
Bartlomiej Sieka363d1d82007-01-23 13:25:22 +010065 cir = mbar_readShort(MCF_CCM_CIR);
66 pin = cir >> MCF_CCM_CIR_PIN_LEN;
67 prn = cir & MCF_CCM_CIR_PRN_MASK;
68
69 switch (pin) {
70 case MCF_CCM_CIR_PIN_MCF5270:
71 cpu_model = "5270";
72 break;
73 case MCF_CCM_CIR_PIN_MCF5271:
74 cpu_model = "5271";
75 break;
76 default:
77 cpu_model = NULL;
78 break;
79 }
80
81 if (cpu_model)
82 printf("CPU: Freescale ColdFire MCF%s rev. %hu, at %s MHz\n",
83 cpu_model, prn, strmhz(buf, CFG_CLK));
84 else
85 printf("CPU: Unknown - Freescale ColdFire MCF5271 family"
86 " (PIN: 0x%x) rev. %hu, at %s MHz\n",
87 pin, prn, strmhz(buf, CFG_CLK));
88
Zachary P. Landaueacbd312006-01-26 17:35:56 -050089 return 0;
90}
91
92int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]) {
93 mbar_writeByte(MCF_RCM_RCR,
94 MCF_RCM_RCR_SOFTRST | MCF_RCM_RCR_FRCRSTOUT);
95 return 0;
96};
97
98#if defined(CONFIG_WATCHDOG)
99void watchdog_reset (void)
100{
101 mbar_writeShort(MCF_WTM_WSR, 0x5555);
102 mbar_writeShort(MCF_WTM_WSR, 0xAAAA);
103}
104
105int watchdog_disable (void)
106{
107 mbar_writeShort(MCF_WTM_WCR, 0);
108 return (0);
109}
110
111int watchdog_init (void)
112{
Zachary P. Landaueacbd312006-01-26 17:35:56 -0500113 mbar_writeShort(MCF_WTM_WCR, MCF_WTM_WCR_EN);
114 return (0);
115}
116#endif /* #ifdef CONFIG_WATCHDOG */
117
118#endif
wdenkbf9e3b32004-02-12 00:47:09 +0000119
120#ifdef CONFIG_M5272
121int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]) {
122 volatile wdog_t * wdp = (wdog_t *)(CFG_MBAR + MCFSIM_WRRR);
123
124 wdp->wdog_wrrr = 0;
125 udelay (1000);
126
127 /* enable watchdog, set timeout to 0 and wait */
128 wdp->wdog_wrrr = 1;
129 while (1);
130
131 /* we don't return! */
132 return 0;
133};
134
135int checkcpu(void) {
136 ulong *dirp = (ulong *)(CFG_MBAR + MCFSIM_DIR);
137 uchar msk;
138 char *suf;
139
140 puts ("CPU: ");
141 msk = (*dirp > 28) & 0xf;
142 switch (msk) {
143 case 0x2: suf = "1K75N"; break;
144 case 0x4: suf = "3K75N"; break;
145 default:
146 suf = NULL;
Marian Balakowiczb75ef852006-05-09 11:45:31 +0200147 printf ("Freescale MCF5272 (Mask:%01x)\n", msk);
wdenkbf9e3b32004-02-12 00:47:09 +0000148 break;
149 }
150
151 if (suf)
Marian Balakowiczb75ef852006-05-09 11:45:31 +0200152 printf ("Freescale MCF5272 %s\n", suf);
wdenkbf9e3b32004-02-12 00:47:09 +0000153 return 0;
154};
155
wdenkbf9e3b32004-02-12 00:47:09 +0000156#if defined(CONFIG_WATCHDOG)
157/* Called by macro WATCHDOG_RESET */
158void watchdog_reset (void)
159{
160 volatile immap_t * regp = (volatile immap_t *)CFG_MBAR;
161 regp->wdog_reg.wdog_wcr = 0;
162}
163
164int watchdog_disable (void)
165{
166 volatile immap_t *regp = (volatile immap_t *)CFG_MBAR;
167
168 regp->wdog_reg.wdog_wcr = 0; /* reset watchdog counter */
169 regp->wdog_reg.wdog_wirr = 0; /* disable watchdog interrupt */
170 regp->wdog_reg.wdog_wrrr = 0; /* disable watchdog timer */
171
172 puts ("WATCHDOG:disabled\n");
173 return (0);
174}
175
176int watchdog_init (void)
177{
178 volatile immap_t *regp = (volatile immap_t *)CFG_MBAR;
179
180 regp->wdog_reg.wdog_wirr = 0; /* disable watchdog interrupt */
181
182 /* set timeout and enable watchdog */
183 regp->wdog_reg.wdog_wrrr = ((CONFIG_WATCHDOG_TIMEOUT * CFG_HZ) / (32768 * 1000)) - 1;
184 regp->wdog_reg.wdog_wcr = 0; /* reset watchdog counter */
185
186 puts ("WATCHDOG:enabled\n");
187 return (0);
188}
189#endif /* #ifdef CONFIG_WATCHDOG */
190
191#endif /* #ifdef CONFIG_M5272 */
192
193
194#ifdef CONFIG_M5282
195int checkcpu (void)
196{
Wolfgang Denk4176c792006-06-10 19:27:47 +0200197 unsigned char resetsource = MCFRESET_RSR;
Heiko Schocher9acb6262006-04-20 08:42:42 +0200198
Wolfgang Denk4176c792006-06-10 19:27:47 +0200199 printf ("CPU: Freescale Coldfire MCF5282 (PIN: %2.2x REV: %2.2x)\n",
Heiko Schocher9acb6262006-04-20 08:42:42 +0200200 MCFCCM_CIR>>8,MCFCCM_CIR & MCFCCM_CIR_PRN_MASK);
Wolfgang Denk4176c792006-06-10 19:27:47 +0200201 printf ("Reset:%s%s%s%s%s%s%s\n",
202 (resetsource & MCFRESET_RSR_LOL) ? " Loss of Lock" : "",
203 (resetsource & MCFRESET_RSR_LOC) ? " Loss of Clock" : "",
204 (resetsource & MCFRESET_RSR_EXT) ? " External" : "",
205 (resetsource & MCFRESET_RSR_POR) ? " Power On" : "",
206 (resetsource & MCFRESET_RSR_WDR) ? " Watchdog" : "",
207 (resetsource & MCFRESET_RSR_SOFT) ? " Software" : "",
208 (resetsource & MCFRESET_RSR_LVD) ? " Low Voltage" : ""
209 );
wdenkbf9e3b32004-02-12 00:47:09 +0000210 return 0;
211}
212
Heiko Schocher9acb6262006-04-20 08:42:42 +0200213int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
214{
215 MCFRESET_RCR = MCFRESET_RCR_SOFTRST;
wdenkbf9e3b32004-02-12 00:47:09 +0000216 return 0;
217};
218#endif
stroese8c725b92004-12-16 18:09:49 +0000219
220#ifdef CONFIG_M5249 /* test-only: todo... */
221int checkcpu (void)
222{
223 char buf[32];
224
Marian Balakowiczb75ef852006-05-09 11:45:31 +0200225 printf ("CPU: Freescale Coldfire MCF5249 at %s MHz\n", strmhz(buf, CFG_CLK));
stroese8c725b92004-12-16 18:09:49 +0000226 return 0;
227}
228
229int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]) {
230 /* enable watchdog, set timeout to 0 and wait */
231 mbar_writeByte(MCFSIM_SYPCR, 0xc0);
232 while (1);
233
234 /* we don't return! */
235 return 0;
236};
237#endif