blob: 5ec760933844188a37abde860492d857195bdf60 [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 *
Alison Wang32dbaaf2012-03-26 21:49:04 +000012 * Copyright (C) 2012 Freescale Semiconductor, Inc. All Rights Reserved.
13 *
Wolfgang Denk1a459662013-07-08 09:37:19 +020014 * SPDX-License-Identifier: GPL-2.0+
wdenkbf9e3b32004-02-12 00:47:09 +000015 */
16
17#include <common.h>
18#include <watchdog.h>
19#include <command.h>
TsiChungLiew83ec20b2007-08-15 19:21:21 -050020#include <asm/immap.h>
Alison Wang32dbaaf2012-03-26 21:49:04 +000021#include <asm/io.h>
Ben Warren89973f82008-08-31 22:22:04 -070022#include <netdev.h>
Richard Retanubunbb907ab2009-10-26 14:19:17 -040023#include "cpu.h"
wdenkbf9e3b32004-02-12 00:47:09 +000024
TsiChung Liewbf9a5212009-06-12 11:29:00 +000025DECLARE_GLOBAL_DATA_PTR;
26
27#ifdef CONFIG_M5208
Mike Frysinger882b7d72010-10-20 03:41:17 -040028int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
TsiChung Liewbf9a5212009-06-12 11:29:00 +000029{
Alison Wang32dbaaf2012-03-26 21:49:04 +000030 rcm_t *rcm = (rcm_t *)(MMAP_RCM);
TsiChung Liewbf9a5212009-06-12 11:29:00 +000031
32 udelay(1000);
33
Alison Wang32dbaaf2012-03-26 21:49:04 +000034 out_8(&rcm->rcr, RCM_RCR_SOFTRST);
TsiChung Liewbf9a5212009-06-12 11:29:00 +000035
36 /* we don't return! */
37 return 0;
38};
39
40int checkcpu(void)
41{
42 char buf1[32], buf2[32];
43
44 printf("CPU: Freescale Coldfire MCF5208\n"
45 " CPU CLK %s MHz BUS CLK %s MHz\n",
46 strmhz(buf1, gd->cpu_clk),
47 strmhz(buf2, gd->bus_clk));
48 return 0;
49};
50
51#if defined(CONFIG_WATCHDOG)
52/* Called by macro WATCHDOG_RESET */
53void watchdog_reset(void)
54{
Alison Wang32dbaaf2012-03-26 21:49:04 +000055 wdog_t *wdt = (wdog_t *)(MMAP_WDOG);
56
57 out_be16(&wdt->sr, 0x5555);
58 out_be16(&wdt->sr, 0xaaaa);
TsiChung Liewbf9a5212009-06-12 11:29:00 +000059}
60
61int watchdog_disable(void)
62{
Alison Wang32dbaaf2012-03-26 21:49:04 +000063 wdog_t *wdt = (wdog_t *)(MMAP_WDOG);
TsiChung Liewbf9a5212009-06-12 11:29:00 +000064
Alison Wang32dbaaf2012-03-26 21:49:04 +000065 /* reset watchdog counter */
66 out_be16(&wdt->sr, 0x5555);
67 out_be16(&wdt->sr, 0xaaaa);
68 /* disable watchdog timer */
69 out_be16(&wdt->cr, 0);
TsiChung Liewbf9a5212009-06-12 11:29:00 +000070
71 puts("WATCHDOG:disabled\n");
72 return (0);
73}
74
75int watchdog_init(void)
76{
Alison Wang32dbaaf2012-03-26 21:49:04 +000077 wdog_t *wdt = (wdog_t *)(MMAP_WDOG);
TsiChung Liewbf9a5212009-06-12 11:29:00 +000078
Alison Wang32dbaaf2012-03-26 21:49:04 +000079 /* disable watchdog */
80 out_be16(&wdt->cr, 0);
TsiChung Liewbf9a5212009-06-12 11:29:00 +000081
82 /* set timeout and enable watchdog */
Alison Wang32dbaaf2012-03-26 21:49:04 +000083 out_be16(&wdt->mr,
84 (CONFIG_WATCHDOG_TIMEOUT * CONFIG_SYS_HZ) / (32768 * 1000) - 1);
85
86 /* reset watchdog counter */
87 out_be16(&wdt->sr, 0x5555);
88 out_be16(&wdt->sr, 0xaaaa);
TsiChung Liewbf9a5212009-06-12 11:29:00 +000089
90 puts("WATCHDOG:enabled\n");
91 return (0);
92}
93#endif /* #ifdef CONFIG_WATCHDOG */
94#endif /* #ifdef CONFIG_M5208 */
95
Zachary P. Landaueacbd312006-01-26 17:35:56 -050096#ifdef CONFIG_M5271
Bartlomiej Sieka363d1d82007-01-23 13:25:22 +010097/*
98 * Both MCF5270 and MCF5271 are members of the MPC5271 family. Try to
99 * determine which one we are running on, based on the Chip Identification
100 * Register (CIR).
101 */
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500102int checkcpu(void)
Zachary P. Landaueacbd312006-01-26 17:35:56 -0500103{
Marian Balakowiczb75ef852006-05-09 11:45:31 +0200104 char buf[32];
Bartlomiej Sieka363d1d82007-01-23 13:25:22 +0100105 unsigned short cir; /* Chip Identification Register */
106 unsigned short pin; /* Part identification number */
107 unsigned char prn; /* Part revision number */
108 char *cpu_model;
Marian Balakowiczb75ef852006-05-09 11:45:31 +0200109
Bartlomiej Sieka363d1d82007-01-23 13:25:22 +0100110 cir = mbar_readShort(MCF_CCM_CIR);
111 pin = cir >> MCF_CCM_CIR_PIN_LEN;
112 prn = cir & MCF_CCM_CIR_PRN_MASK;
113
114 switch (pin) {
115 case MCF_CCM_CIR_PIN_MCF5270:
116 cpu_model = "5270";
117 break;
118 case MCF_CCM_CIR_PIN_MCF5271:
119 cpu_model = "5271";
120 break;
121 default:
122 cpu_model = NULL;
123 break;
124 }
125
126 if (cpu_model)
127 printf("CPU: Freescale ColdFire MCF%s rev. %hu, at %s MHz\n",
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200128 cpu_model, prn, strmhz(buf, CONFIG_SYS_CLK));
Bartlomiej Sieka363d1d82007-01-23 13:25:22 +0100129 else
130 printf("CPU: Unknown - Freescale ColdFire MCF5271 family"
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500131 " (PIN: 0x%x) rev. %hu, at %s MHz\n",
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200132 pin, prn, strmhz(buf, CONFIG_SYS_CLK));
Bartlomiej Sieka363d1d82007-01-23 13:25:22 +0100133
Zachary P. Landaueacbd312006-01-26 17:35:56 -0500134 return 0;
135}
136
Mike Frysinger882b7d72010-10-20 03:41:17 -0400137int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500138{
Richard Retanubunbb907ab2009-10-26 14:19:17 -0400139 /* Call the board specific reset actions first. */
140 if(board_reset) {
141 board_reset();
142 }
143
Zachary P. Landaueacbd312006-01-26 17:35:56 -0500144 mbar_writeByte(MCF_RCM_RCR,
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500145 MCF_RCM_RCR_SOFTRST | MCF_RCM_RCR_FRCRSTOUT);
Zachary P. Landaueacbd312006-01-26 17:35:56 -0500146 return 0;
147};
148
149#if defined(CONFIG_WATCHDOG)
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500150void watchdog_reset(void)
Zachary P. Landaueacbd312006-01-26 17:35:56 -0500151{
152 mbar_writeShort(MCF_WTM_WSR, 0x5555);
153 mbar_writeShort(MCF_WTM_WSR, 0xAAAA);
154}
155
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500156int watchdog_disable(void)
Zachary P. Landaueacbd312006-01-26 17:35:56 -0500157{
158 mbar_writeShort(MCF_WTM_WCR, 0);
159 return (0);
160}
161
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500162int watchdog_init(void)
Zachary P. Landaueacbd312006-01-26 17:35:56 -0500163{
Zachary P. Landaueacbd312006-01-26 17:35:56 -0500164 mbar_writeShort(MCF_WTM_WCR, MCF_WTM_WCR_EN);
165 return (0);
166}
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500167#endif /* #ifdef CONFIG_WATCHDOG */
Zachary P. Landaueacbd312006-01-26 17:35:56 -0500168
169#endif
wdenkbf9e3b32004-02-12 00:47:09 +0000170
171#ifdef CONFIG_M5272
Mike Frysinger882b7d72010-10-20 03:41:17 -0400172int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500173{
Alison Wang32dbaaf2012-03-26 21:49:04 +0000174 wdog_t *wdp = (wdog_t *) (MMAP_WDOG);
wdenkbf9e3b32004-02-12 00:47:09 +0000175
Alison Wang32dbaaf2012-03-26 21:49:04 +0000176 out_be16(&wdp->wdog_wrrr, 0);
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500177 udelay(1000);
wdenkbf9e3b32004-02-12 00:47:09 +0000178
179 /* enable watchdog, set timeout to 0 and wait */
Alison Wang32dbaaf2012-03-26 21:49:04 +0000180 out_be16(&wdp->wdog_wrrr, 1);
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500181 while (1) ;
wdenkbf9e3b32004-02-12 00:47:09 +0000182
183 /* we don't return! */
184 return 0;
185};
186
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500187int checkcpu(void)
188{
Alison Wang32dbaaf2012-03-26 21:49:04 +0000189 sysctrl_t *sysctrl = (sysctrl_t *) (MMAP_CFG);
wdenkbf9e3b32004-02-12 00:47:09 +0000190 uchar msk;
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500191 char *suf;
wdenkbf9e3b32004-02-12 00:47:09 +0000192
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500193 puts("CPU: ");
Alison Wang32dbaaf2012-03-26 21:49:04 +0000194 msk = (in_be32(&sysctrl->sc_dir) > 28) & 0xf;
wdenkbf9e3b32004-02-12 00:47:09 +0000195 switch (msk) {
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500196 case 0x2:
197 suf = "1K75N";
198 break;
199 case 0x4:
200 suf = "3K75N";
201 break;
202 default:
203 suf = NULL;
204 printf("Freescale MCF5272 (Mask:%01x)\n", msk);
205 break;
206 }
wdenkbf9e3b32004-02-12 00:47:09 +0000207
208 if (suf)
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500209 printf("Freescale MCF5272 %s\n", suf);
wdenkbf9e3b32004-02-12 00:47:09 +0000210 return 0;
211};
212
wdenkbf9e3b32004-02-12 00:47:09 +0000213#if defined(CONFIG_WATCHDOG)
214/* Called by macro WATCHDOG_RESET */
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500215void watchdog_reset(void)
wdenkbf9e3b32004-02-12 00:47:09 +0000216{
Alison Wang32dbaaf2012-03-26 21:49:04 +0000217 wdog_t *wdt = (wdog_t *)(MMAP_WDOG);
218
219 out_be16(&wdt->wdog_wcr, 0);
wdenkbf9e3b32004-02-12 00:47:09 +0000220}
221
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500222int watchdog_disable(void)
wdenkbf9e3b32004-02-12 00:47:09 +0000223{
Alison Wang32dbaaf2012-03-26 21:49:04 +0000224 wdog_t *wdt = (wdog_t *)(MMAP_WDOG);
wdenkbf9e3b32004-02-12 00:47:09 +0000225
Alison Wang32dbaaf2012-03-26 21:49:04 +0000226 /* reset watchdog counter */
227 out_be16(&wdt->wdog_wcr, 0);
228 /* disable watchdog interrupt */
229 out_be16(&wdt->wdog_wirr, 0);
230 /* disable watchdog timer */
231 out_be16(&wdt->wdog_wrrr, 0);
wdenkbf9e3b32004-02-12 00:47:09 +0000232
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500233 puts("WATCHDOG:disabled\n");
wdenkbf9e3b32004-02-12 00:47:09 +0000234 return (0);
235}
236
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500237int watchdog_init(void)
wdenkbf9e3b32004-02-12 00:47:09 +0000238{
Alison Wang32dbaaf2012-03-26 21:49:04 +0000239 wdog_t *wdt = (wdog_t *)(MMAP_WDOG);
wdenkbf9e3b32004-02-12 00:47:09 +0000240
Alison Wang32dbaaf2012-03-26 21:49:04 +0000241 /* disable watchdog interrupt */
242 out_be16(&wdt->wdog_wirr, 0);
wdenkbf9e3b32004-02-12 00:47:09 +0000243
244 /* set timeout and enable watchdog */
Alison Wang32dbaaf2012-03-26 21:49:04 +0000245 out_be16(&wdt->wdog_wrrr,
246 (CONFIG_WATCHDOG_TIMEOUT * CONFIG_SYS_HZ) / (32768 * 1000) - 1);
247
248 /* reset watchdog counter */
249 out_be16(&wdt->wdog_wcr, 0);
wdenkbf9e3b32004-02-12 00:47:09 +0000250
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500251 puts("WATCHDOG:enabled\n");
wdenkbf9e3b32004-02-12 00:47:09 +0000252 return (0);
253}
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500254#endif /* #ifdef CONFIG_WATCHDOG */
wdenkbf9e3b32004-02-12 00:47:09 +0000255
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500256#endif /* #ifdef CONFIG_M5272 */
wdenkbf9e3b32004-02-12 00:47:09 +0000257
Matthew Fettkef71d9d92008-02-04 15:38:20 -0600258#ifdef CONFIG_M5275
Mike Frysinger882b7d72010-10-20 03:41:17 -0400259int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Matthew Fettkef71d9d92008-02-04 15:38:20 -0600260{
Alison Wang32dbaaf2012-03-26 21:49:04 +0000261 rcm_t *rcm = (rcm_t *)(MMAP_RCM);
Matthew Fettkef71d9d92008-02-04 15:38:20 -0600262
263 udelay(1000);
264
Alison Wang32dbaaf2012-03-26 21:49:04 +0000265 out_8(&rcm->rcr, RCM_RCR_SOFTRST);
Matthew Fettkef71d9d92008-02-04 15:38:20 -0600266
267 /* we don't return! */
268 return 0;
269};
270
271int checkcpu(void)
272{
273 char buf[32];
274
275 printf("CPU: Freescale Coldfire MCF5275 at %s MHz\n",
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200276 strmhz(buf, CONFIG_SYS_CLK));
Matthew Fettkef71d9d92008-02-04 15:38:20 -0600277 return 0;
278};
279
280
281#if defined(CONFIG_WATCHDOG)
282/* Called by macro WATCHDOG_RESET */
283void watchdog_reset(void)
284{
Alison Wang32dbaaf2012-03-26 21:49:04 +0000285 wdog_t *wdt = (wdog_t *)(MMAP_WDOG);
286
287 out_be16(&wdt->wsr, 0x5555);
288 out_be16(&wdt->wsr, 0xaaaa);
Matthew Fettkef71d9d92008-02-04 15:38:20 -0600289}
290
291int watchdog_disable(void)
292{
Alison Wang32dbaaf2012-03-26 21:49:04 +0000293 wdog_t *wdt = (wdog_t *)(MMAP_WDOG);
Matthew Fettkef71d9d92008-02-04 15:38:20 -0600294
Alison Wang32dbaaf2012-03-26 21:49:04 +0000295 /* reset watchdog counter */
296 out_be16(&wdt->wsr, 0x5555);
297 out_be16(&wdt->wsr, 0xaaaa);
298
299 /* disable watchdog timer */
300 out_be16(&wdt->wcr, 0);
Matthew Fettkef71d9d92008-02-04 15:38:20 -0600301
302 puts("WATCHDOG:disabled\n");
303 return (0);
304}
305
306int watchdog_init(void)
307{
Alison Wang32dbaaf2012-03-26 21:49:04 +0000308 wdog_t *wdt = (wdog_t *)(MMAP_WDOG);
Matthew Fettkef71d9d92008-02-04 15:38:20 -0600309
Alison Wang32dbaaf2012-03-26 21:49:04 +0000310 /* disable watchdog */
311 out_be16(&wdt->wcr, 0);
Matthew Fettkef71d9d92008-02-04 15:38:20 -0600312
313 /* set timeout and enable watchdog */
Alison Wang32dbaaf2012-03-26 21:49:04 +0000314 out_be16(&wdt->wmr,
315 (CONFIG_WATCHDOG_TIMEOUT * CONFIG_SYS_HZ) / (32768 * 1000) - 1);
316
317 /* reset watchdog counter */
318 out_be16(&wdt->wsr, 0x5555);
319 out_be16(&wdt->wsr, 0xaaaa);
Matthew Fettkef71d9d92008-02-04 15:38:20 -0600320
321 puts("WATCHDOG:enabled\n");
322 return (0);
323}
324#endif /* #ifdef CONFIG_WATCHDOG */
325
326#endif /* #ifdef CONFIG_M5275 */
327
wdenkbf9e3b32004-02-12 00:47:09 +0000328#ifdef CONFIG_M5282
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500329int checkcpu(void)
wdenkbf9e3b32004-02-12 00:47:09 +0000330{
Wolfgang Denk4176c792006-06-10 19:27:47 +0200331 unsigned char resetsource = MCFRESET_RSR;
Heiko Schocher9acb6262006-04-20 08:42:42 +0200332
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500333 printf("CPU: Freescale Coldfire MCF5282 (PIN: %2.2x REV: %2.2x)\n",
334 MCFCCM_CIR >> 8, MCFCCM_CIR & MCFCCM_CIR_PRN_MASK);
335 printf("Reset:%s%s%s%s%s%s%s\n",
336 (resetsource & MCFRESET_RSR_LOL) ? " Loss of Lock" : "",
337 (resetsource & MCFRESET_RSR_LOC) ? " Loss of Clock" : "",
338 (resetsource & MCFRESET_RSR_EXT) ? " External" : "",
339 (resetsource & MCFRESET_RSR_POR) ? " Power On" : "",
340 (resetsource & MCFRESET_RSR_WDR) ? " Watchdog" : "",
341 (resetsource & MCFRESET_RSR_SOFT) ? " Software" : "",
342 (resetsource & MCFRESET_RSR_LVD) ? " Low Voltage" : "");
wdenkbf9e3b32004-02-12 00:47:09 +0000343 return 0;
344}
345
Mike Frysinger882b7d72010-10-20 03:41:17 -0400346int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Heiko Schocher9acb6262006-04-20 08:42:42 +0200347{
348 MCFRESET_RCR = MCFRESET_RCR_SOFTRST;
wdenkbf9e3b32004-02-12 00:47:09 +0000349 return 0;
350};
351#endif
stroese8c725b92004-12-16 18:09:49 +0000352
TsiChungLiewa1436a82007-08-16 13:20:50 -0500353#ifdef CONFIG_M5249
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500354int checkcpu(void)
stroese8c725b92004-12-16 18:09:49 +0000355{
356 char buf[32];
357
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500358 printf("CPU: Freescale Coldfire MCF5249 at %s MHz\n",
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200359 strmhz(buf, CONFIG_SYS_CLK));
stroese8c725b92004-12-16 18:09:49 +0000360 return 0;
361}
362
Mike Frysinger882b7d72010-10-20 03:41:17 -0400363int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500364{
stroese8c725b92004-12-16 18:09:49 +0000365 /* enable watchdog, set timeout to 0 and wait */
366 mbar_writeByte(MCFSIM_SYPCR, 0xc0);
TsiChungLiew83ec20b2007-08-15 19:21:21 -0500367 while (1) ;
stroese8c725b92004-12-16 18:09:49 +0000368
369 /* we don't return! */
370 return 0;
371};
372#endif
TsiChungLiewa1436a82007-08-16 13:20:50 -0500373
374#ifdef CONFIG_M5253
375int checkcpu(void)
376{
377 char buf[32];
378
379 unsigned char resetsource = mbar_readLong(SIM_RSR);
380 printf("CPU: Freescale Coldfire MCF5253 at %s MHz\n",
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200381 strmhz(buf, CONFIG_SYS_CLK));
TsiChungLiewa1436a82007-08-16 13:20:50 -0500382
383 if ((resetsource & SIM_RSR_HRST) || (resetsource & SIM_RSR_SWTR)) {
384 printf("Reset:%s%s\n",
385 (resetsource & SIM_RSR_HRST) ? " Hardware/ System Reset"
386 : "",
387 (resetsource & SIM_RSR_SWTR) ? " Software Watchdog" :
388 "");
389 }
390 return 0;
391}
392
Mike Frysinger882b7d72010-10-20 03:41:17 -0400393int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
TsiChungLiewa1436a82007-08-16 13:20:50 -0500394{
395 /* enable watchdog, set timeout to 0 and wait */
396 mbar_writeByte(SIM_SYPCR, 0xc0);
397 while (1) ;
398
399 /* we don't return! */
400 return 0;
401};
402#endif
Ben Warren86882b82008-08-26 22:16:25 -0700403
404#if defined(CONFIG_MCFFEC)
405/* Default initializations for MCFFEC controllers. To override,
406 * create a board-specific function called:
407 * int board_eth_init(bd_t *bis)
408 */
409
Ben Warren86882b82008-08-26 22:16:25 -0700410int cpu_eth_init(bd_t *bis)
411{
412 return mcffec_initialize(bis);
413}
414#endif