blob: 67879c7d6af92693b8f347385b31eaa3cb9f4a6e [file] [log] [blame]
TsiChungLiew4a442d32007-08-16 19:23:50 -05001/*
2 *
3 * (C) Copyright 2000-2003
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 *
Alison Wangc6d88632012-03-26 21:49:06 +00006 * Copyright (C) 2004-2007, 2012 Freescale Semiconductor, Inc.
TsiChungLiew4a442d32007-08-16 19:23:50 -05007 * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
8 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02009 * SPDX-License-Identifier: GPL-2.0+
TsiChungLiew4a442d32007-08-16 19:23:50 -050010 */
11
12#include <common.h>
13#include <watchdog.h>
14#include <command.h>
Ben Warren89973f82008-08-31 22:22:04 -070015#include <netdev.h>
TsiChungLiew4a442d32007-08-16 19:23:50 -050016
17#include <asm/immap.h>
Alison Wangc6d88632012-03-26 21:49:06 +000018#include <asm/io.h>
TsiChungLiew4a442d32007-08-16 19:23:50 -050019
20DECLARE_GLOBAL_DATA_PTR;
21
Mike Frysinger882b7d72010-10-20 03:41:17 -040022int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
TsiChungLiew4a442d32007-08-16 19:23:50 -050023{
Alison Wangc6d88632012-03-26 21:49:06 +000024 ccm_t *ccm = (ccm_t *) MMAP_CCM;
TsiChungLiew4a442d32007-08-16 19:23:50 -050025
Alison Wangc6d88632012-03-26 21:49:06 +000026 out_8(&ccm->rcr, CCM_RCR_SOFTRST);
TsiChungLiew4a442d32007-08-16 19:23:50 -050027 /* we don't return! */
28 return 0;
Alison Wangc6d88632012-03-26 21:49:06 +000029}
TsiChungLiew4a442d32007-08-16 19:23:50 -050030
31int checkcpu(void)
32{
Alison Wangc6d88632012-03-26 21:49:06 +000033 ccm_t *ccm = (ccm_t *) MMAP_CCM;
TsiChungLiew4a442d32007-08-16 19:23:50 -050034 u16 msk;
35 u16 id = 0;
36 u8 ver;
37
38 puts("CPU: ");
Alison Wangc6d88632012-03-26 21:49:06 +000039 msk = (in_be16(&ccm->cir) >> 6);
40 ver = (in_be16(&ccm->cir) & 0x003f);
TsiChungLiew4a442d32007-08-16 19:23:50 -050041 switch (msk) {
42 case 0x31:
43 id = 5235;
44 break;
45 }
46
47 if (id) {
Wolfgang Denk08ef89e2008-10-19 02:35:49 +020048 char buf1[32], buf2[32];
49
TsiChungLiew4a442d32007-08-16 19:23:50 -050050 printf("Freescale MCF%d (Mask:%01x Version:%x)\n", id, msk,
51 ver);
Wolfgang Denk08ef89e2008-10-19 02:35:49 +020052 printf(" CPU CLK %s MHz BUS CLK %s MHz\n",
TsiChung Liew1b270842008-10-22 11:55:30 +000053 strmhz(buf1, gd->cpu_clk),
54 strmhz(buf2, gd->bus_clk));
TsiChungLiew4a442d32007-08-16 19:23:50 -050055 }
56
57 return 0;
58};
59
60#if defined(CONFIG_WATCHDOG)
61/* Called by macro WATCHDOG_RESET */
62void watchdog_reset(void)
63{
Alison Wangc6d88632012-03-26 21:49:06 +000064 wdog_t *wdp = (wdog_t *) (MMAP_WDOG);
TsiChungLiew4a442d32007-08-16 19:23:50 -050065
Alison Wangc6d88632012-03-26 21:49:06 +000066 /* Count register */
67 out_be16(&wdp->sr, 0x5555);
TsiChungLiew4a442d32007-08-16 19:23:50 -050068 asm("nop");
Alison Wangc6d88632012-03-26 21:49:06 +000069 out_be16(&wdp->sr, 0xaaaa);
TsiChungLiew4a442d32007-08-16 19:23:50 -050070}
71
72int watchdog_disable(void)
73{
Alison Wangc6d88632012-03-26 21:49:06 +000074 wdog_t *wdp = (wdog_t *) (MMAP_WDOG);
TsiChungLiew4a442d32007-08-16 19:23:50 -050075
76 /* UserManual, once the wdog is disabled, wdog cannot be re-enabled */
Alison Wangc6d88632012-03-26 21:49:06 +000077 /* halted watchdog timer */
78 setbits_be16(&wdp->cr, WTM_WCR_HALTED);
TsiChungLiew4a442d32007-08-16 19:23:50 -050079
80 puts("WATCHDOG:disabled\n");
81 return (0);
82}
83
84int watchdog_init(void)
85{
Alison Wangc6d88632012-03-26 21:49:06 +000086 wdog_t *wdp = (wdog_t *) (MMAP_WDOG);
TsiChungLiew4a442d32007-08-16 19:23:50 -050087 u32 wdog_module = 0;
88
89 /* set timeout and enable watchdog */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020090 wdog_module = ((CONFIG_SYS_CLK / CONFIG_SYS_HZ) * CONFIG_WATCHDOG_TIMEOUT);
TsiChungLiew4a442d32007-08-16 19:23:50 -050091 wdog_module |= (wdog_module / 8192);
Alison Wangc6d88632012-03-26 21:49:06 +000092 out_be16(&wdp->mr, wdog_module);
TsiChungLiew4a442d32007-08-16 19:23:50 -050093
Alison Wangc6d88632012-03-26 21:49:06 +000094 out_be16(&wdp->cr, WTM_WCR_EN);
TsiChungLiew4a442d32007-08-16 19:23:50 -050095 puts("WATCHDOG:enabled\n");
96
97 return (0);
98}
99#endif /* CONFIG_WATCHDOG */
Ben Warren86882b82008-08-26 22:16:25 -0700100
101#if defined(CONFIG_MCFFEC)
102/* Default initializations for MCFFEC controllers. To override,
103 * create a board-specific function called:
104 * int board_eth_init(bd_t *bis)
105 */
106
Ben Warren86882b82008-08-26 22:16:25 -0700107int cpu_eth_init(bd_t *bis)
108{
109 return mcffec_initialize(bis);
110}
111#endif