1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  *
4  * (C) Copyright 2000-2003
5  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6  *
7  * Copyright (C) 2004-2008, 2012 Freescale Semiconductor, Inc.
8  * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
9  */
10 
11 #include <common.h>
12 #include <init.h>
13 #include <net.h>
14 #include <vsprintf.h>
15 #include <watchdog.h>
16 #include <command.h>
17 #include <netdev.h>
18 #include <asm/global_data.h>
19 #include <linux/delay.h>
20 
21 #include <asm/immap.h>
22 #include <asm/io.h>
23 
24 DECLARE_GLOBAL_DATA_PTR;
25 
do_reset(struct cmd_tbl * cmdtp,int flag,int argc,char * const argv[])26 int do_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
27 {
28 	rcm_t *rcm = (rcm_t *) (MMAP_RCM);
29 
30 	udelay(1000);
31 	setbits_8(&rcm->rcr, RCM_RCR_SOFTRST);
32 
33 	/* we don't return! */
34 	return 0;
35 };
36 
37 #if defined(CONFIG_DISPLAY_CPUINFO)
print_cpuinfo(void)38 int print_cpuinfo(void)
39 {
40 	ccm_t *ccm = (ccm_t *) MMAP_CCM;
41 	u16 msk;
42 	u16 id = 0;
43 	u8 ver;
44 
45 	puts("CPU:   ");
46 	msk = (in_be16(&ccm->cir) >> 6);
47 	ver = (in_be16(&ccm->cir) & 0x003f);
48 	switch (msk) {
49 #ifdef CONFIG_MCF5301x
50 	case 0x78:
51 		id = 53010;
52 		break;
53 	case 0x77:
54 		id = 53012;
55 		break;
56 	case 0x76:
57 		id = 53015;
58 		break;
59 	case 0x74:
60 		id = 53011;
61 		break;
62 	case 0x73:
63 		id = 53013;
64 		break;
65 #endif
66 #ifdef CONFIG_MCF532x
67 	case 0x54:
68 		id = 5329;
69 		break;
70 	case 0x59:
71 		id = 5328;
72 		break;
73 	case 0x61:
74 		id = 5327;
75 		break;
76 	case 0x65:
77 		id = 5373;
78 		break;
79 	case 0x68:
80 		id = 53721;
81 		break;
82 	case 0x69:
83 		id = 5372;
84 		break;
85 	case 0x6B:
86 		id = 5372;
87 		break;
88 #endif
89 	}
90 
91 	if (id) {
92 		char buf1[32], buf2[32];
93 
94 		printf("Freescale MCF%d (Mask:%01x Version:%x)\n", id, msk,
95 		       ver);
96 		printf("       CPU CLK %s MHz BUS CLK %s MHz\n",
97 		       strmhz(buf1, gd->cpu_clk),
98 		       strmhz(buf2, gd->bus_clk));
99 	}
100 
101 	return 0;
102 };
103 #endif /* CONFIG_DISPLAY_CPUINFO */
104 
105 #if defined(CONFIG_WATCHDOG)
106 /* Called by macro WATCHDOG_RESET */
watchdog_reset(void)107 void watchdog_reset(void)
108 {
109 	wdog_t *wdp = (wdog_t *) (MMAP_WDOG);
110 
111 	/* Count register */
112 	out_be16(&wdp->sr, 0x5555);
113 	out_be16(&wdp->sr, 0xaaaa);
114 }
115 
watchdog_disable(void)116 int watchdog_disable(void)
117 {
118 	wdog_t *wdp = (wdog_t *) (MMAP_WDOG);
119 
120 	/* UserManual, once the wdog is disabled, wdog cannot be re-enabled */
121 	/* halted watchdog timer */
122 	setbits_be16(&wdp->cr, WTM_WCR_HALTED);
123 
124 	puts("WATCHDOG:disabled\n");
125 	return (0);
126 }
127 
watchdog_init(void)128 int watchdog_init(void)
129 {
130 	wdog_t *wdp = (wdog_t *) (MMAP_WDOG);
131 	u32 wdog_module = 0;
132 
133 	/* set timeout and enable watchdog */
134 	wdog_module = ((CONFIG_SYS_CLK / 1000) * CONFIG_WATCHDOG_TIMEOUT);
135 #ifdef CONFIG_M5329
136 	out_be16(&wdp->mr, wdog_module / 8192);
137 #else
138 	out_be16(&wdp->mr, wdog_module / 4096);
139 #endif
140 
141 	out_be16(&wdp->cr, WTM_WCR_EN);
142 	puts("WATCHDOG:enabled\n");
143 
144 	return (0);
145 }
146 #endif				/* CONFIG_WATCHDOG */
147 
148 #if defined(CONFIG_MCFFEC)
149 /* Default initializations for MCFFEC controllers.  To override,
150  * create a board-specific function called:
151  * 	int board_eth_init(struct bd_info *bis)
152  */
cpu_eth_init(struct bd_info * bis)153 int cpu_eth_init(struct bd_info *bis)
154 {
155 	return mcffec_initialize(bis);
156 }
157 #endif
158