Add support for Freescale M5271 processor
[oweals/u-boot.git] / cpu / mcf52x2 / cpu.c
1 /*
2  * (C) Copyright 2003
3  * Josef Baumgartner <josef.baumgartner@telex.de>
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA
22  */
23
24 #include <common.h>
25 #include <watchdog.h>
26 #include <command.h>
27
28 #ifdef  CONFIG_M5271
29 #include <asm/immap_5271.h>
30 #include <asm/m5271.h>
31 #endif
32
33 #ifdef  CONFIG_M5272
34 #include <asm/immap_5272.h>
35 #include <asm/m5272.h>
36 #endif
37
38 #ifdef  CONFIG_M5282
39
40 #endif
41
42 #ifdef  CONFIG_M5249
43 #include <asm/m5249.h>
44 #endif
45
46 #ifdef  CONFIG_M5271
47 int checkcpu (void)
48 {
49         puts ("CPU:   MOTOROLA Coldfire MCF5271\n");
50         return 0;
51 }
52
53 int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]) {
54         mbar_writeByte(MCF_RCM_RCR,
55                         MCF_RCM_RCR_SOFTRST | MCF_RCM_RCR_FRCRSTOUT);
56         return 0;
57 };
58
59 #if defined(CONFIG_WATCHDOG)
60 void watchdog_reset (void)
61 {
62         mbar_writeShort(MCF_WTM_WSR, 0x5555);
63         mbar_writeShort(MCF_WTM_WSR, 0xAAAA);
64 }
65
66 int watchdog_disable (void)
67 {
68         mbar_writeShort(MCF_WTM_WCR, 0);
69         return (0);
70 }
71
72 int watchdog_init (void)
73 {
74         mbar_writeShort(MCF_WTM_WCNTR, CONFIG_WATCHDOG_TIMEOUT);
75         mbar_writeShort(MCF_WTM_WCR, MCF_WTM_WCR_EN);
76         return (0);
77 }
78 #endif /* #ifdef CONFIG_WATCHDOG */
79
80 #endif
81
82 #ifdef  CONFIG_M5272
83 int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]) {
84         volatile wdog_t * wdp = (wdog_t *)(CFG_MBAR + MCFSIM_WRRR);
85
86         wdp->wdog_wrrr = 0;
87         udelay (1000);
88
89         /* enable watchdog, set timeout to 0 and wait */
90         wdp->wdog_wrrr = 1;
91         while (1);
92
93         /* we don't return! */
94         return 0;
95 };
96
97 int checkcpu(void) {
98         ulong *dirp = (ulong *)(CFG_MBAR + MCFSIM_DIR);
99         uchar msk;
100         char  *suf;
101
102         puts ("CPU:   ");
103         msk = (*dirp > 28) & 0xf;
104         switch (msk) {
105                 case 0x2: suf = "1K75N"; break;
106                 case 0x4: suf = "3K75N"; break;
107                 default:
108                         suf = NULL;
109                         printf ("MOTOROLA MCF5272 (Mask:%01x)\n", msk);
110                         break;
111                 }
112
113         if (suf)
114                 printf ("MOTOROLA MCF5272 %s\n", suf);
115         return 0;
116 };
117
118
119 #if defined(CONFIG_WATCHDOG)
120 /* Called by macro WATCHDOG_RESET */
121 void watchdog_reset (void)
122 {
123         volatile immap_t * regp = (volatile immap_t *)CFG_MBAR;
124         regp->wdog_reg.wdog_wcr = 0;
125 }
126
127 int watchdog_disable (void)
128 {
129         volatile immap_t *regp = (volatile immap_t *)CFG_MBAR;
130
131         regp->wdog_reg.wdog_wcr = 0;    /* reset watchdog counter */
132         regp->wdog_reg.wdog_wirr = 0;   /* disable watchdog interrupt */
133         regp->wdog_reg.wdog_wrrr = 0;   /* disable watchdog timer */
134
135         puts ("WATCHDOG:disabled\n");
136         return (0);
137 }
138
139 int watchdog_init (void)
140 {
141         volatile immap_t *regp = (volatile immap_t *)CFG_MBAR;
142
143         regp->wdog_reg.wdog_wirr = 0;   /* disable watchdog interrupt */
144
145         /* set timeout and enable watchdog */
146         regp->wdog_reg.wdog_wrrr = ((CONFIG_WATCHDOG_TIMEOUT * CFG_HZ) / (32768 * 1000)) - 1;
147         regp->wdog_reg.wdog_wcr = 0;    /* reset watchdog counter */
148
149         puts ("WATCHDOG:enabled\n");
150         return (0);
151 }
152 #endif /* #ifdef CONFIG_WATCHDOG */
153
154 #endif /* #ifdef CONFIG_M5272 */
155
156
157 #ifdef  CONFIG_M5282
158 int checkcpu (void)
159 {
160         puts ("CPU:   MOTOROLA Coldfire MCF5282\n");
161         return 0;
162 }
163
164 int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]) {
165         return 0;
166 };
167 #endif
168
169 #ifdef CONFIG_M5249 /* test-only: todo... */
170 int checkcpu (void)
171 {
172         char buf[32];
173
174         printf ("CPU:   MOTOROLA Coldfire MCF5249 at %s MHz\n", strmhz(buf, CFG_CLK));
175         return 0;
176 }
177
178 int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]) {
179         /* enable watchdog, set timeout to 0 and wait */
180         mbar_writeByte(MCFSIM_SYPCR, 0xc0);
181         while (1);
182
183         /* we don't return! */
184         return 0;
185 };
186 #endif