common: Drop net.h from common header
[pandora-u-boot.git] / arch / m68k / cpu / mcf52x2 / cpu.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2003
4  * Josef Baumgartner <josef.baumgartner@telex.de>
5  *
6  * MCF5282 additionals
7  * (C) Copyright 2005
8  * BuS Elektronik GmbH & Co. KG <esw@bus-elektronik.de>
9  *
10  * MCF5275 additions
11  * Copyright (C) 2008 Arthur Shipkowski (art@videon-central.com)
12  *
13  * Copyright (C) 2012 Freescale Semiconductor, Inc. All Rights Reserved.
14  */
15
16 #include <common.h>
17 #include <net.h>
18 #include <vsprintf.h>
19 #include <watchdog.h>
20 #include <command.h>
21 #include <asm/immap.h>
22 #include <asm/io.h>
23 #include <netdev.h>
24 #include "cpu.h"
25
26 DECLARE_GLOBAL_DATA_PTR;
27
28 #ifdef  CONFIG_M5208
29 int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
30 {
31         rcm_t *rcm = (rcm_t *)(MMAP_RCM);
32
33         udelay(1000);
34
35         out_8(&rcm->rcr, RCM_RCR_SOFTRST);
36
37         /* we don't return! */
38         return 0;
39 };
40
41 #if defined(CONFIG_DISPLAY_CPUINFO)
42 int print_cpuinfo(void)
43 {
44         char buf1[32], buf2[32];
45
46         printf("CPU:   Freescale Coldfire MCF5208\n"
47                "       CPU CLK %s MHz BUS CLK %s MHz\n",
48                strmhz(buf1, gd->cpu_clk),
49                strmhz(buf2, gd->bus_clk));
50         return 0;
51 };
52 #endif /* CONFIG_DISPLAY_CPUINFO */
53
54 #if defined(CONFIG_WATCHDOG)
55 /* Called by macro WATCHDOG_RESET */
56 void watchdog_reset(void)
57 {
58         wdog_t *wdt = (wdog_t *)(MMAP_WDOG);
59
60         out_be16(&wdt->sr, 0x5555);
61         out_be16(&wdt->sr, 0xaaaa);
62 }
63
64 int watchdog_disable(void)
65 {
66         wdog_t *wdt = (wdog_t *)(MMAP_WDOG);
67
68         /* reset watchdog counter */
69         out_be16(&wdt->sr, 0x5555);
70         out_be16(&wdt->sr, 0xaaaa);
71         /* disable watchdog timer */
72         out_be16(&wdt->cr, 0);
73
74         puts("WATCHDOG:disabled\n");
75         return (0);
76 }
77
78 int watchdog_init(void)
79 {
80         wdog_t *wdt = (wdog_t *)(MMAP_WDOG);
81
82         /* disable watchdog */
83         out_be16(&wdt->cr, 0);
84
85         /* set timeout and enable watchdog */
86         out_be16(&wdt->mr,
87                 (CONFIG_WATCHDOG_TIMEOUT * CONFIG_SYS_HZ) / (32768 * 1000) - 1);
88
89         /* reset watchdog counter */
90         out_be16(&wdt->sr, 0x5555);
91         out_be16(&wdt->sr, 0xaaaa);
92
93         puts("WATCHDOG:enabled\n");
94         return (0);
95 }
96 #endif                          /* #ifdef CONFIG_WATCHDOG */
97 #endif                          /* #ifdef CONFIG_M5208 */
98
99 #ifdef  CONFIG_M5271
100 #if defined(CONFIG_DISPLAY_CPUINFO)
101 /*
102  * Both MCF5270 and MCF5271 are members of the MPC5271 family. Try to
103  * determine which one we are running on, based on the Chip Identification
104  * Register (CIR).
105  */
106 int print_cpuinfo(void)
107 {
108         char buf[32];
109         unsigned short cir;     /* Chip Identification Register */
110         unsigned short pin;     /* Part identification number */
111         unsigned char prn;      /* Part revision number */
112         char *cpu_model;
113
114         cir = mbar_readShort(MCF_CCM_CIR);
115         pin = cir >> MCF_CCM_CIR_PIN_LEN;
116         prn = cir & MCF_CCM_CIR_PRN_MASK;
117
118         switch (pin) {
119         case MCF_CCM_CIR_PIN_MCF5270:
120                 cpu_model = "5270";
121                 break;
122         case MCF_CCM_CIR_PIN_MCF5271:
123                 cpu_model = "5271";
124                 break;
125         default:
126                 cpu_model = NULL;
127                 break;
128         }
129
130         if (cpu_model)
131                 printf("CPU:   Freescale ColdFire MCF%s rev. %hu, at %s MHz\n",
132                        cpu_model, prn, strmhz(buf, CONFIG_SYS_CLK));
133         else
134                 printf("CPU:   Unknown - Freescale ColdFire MCF5271 family"
135                        " (PIN: 0x%x) rev. %hu, at %s MHz\n",
136                        pin, prn, strmhz(buf, CONFIG_SYS_CLK));
137
138         return 0;
139 }
140 #endif /* CONFIG_DISPLAY_CPUINFO */
141
142 int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
143 {
144         /* Call the board specific reset actions first. */
145         if(board_reset) {
146                 board_reset();
147         }
148
149         mbar_writeByte(MCF_RCM_RCR,
150                        MCF_RCM_RCR_SOFTRST | MCF_RCM_RCR_FRCRSTOUT);
151         return 0;
152 };
153
154 #if defined(CONFIG_WATCHDOG)
155 void watchdog_reset(void)
156 {
157         mbar_writeShort(MCF_WTM_WSR, 0x5555);
158         mbar_writeShort(MCF_WTM_WSR, 0xAAAA);
159 }
160
161 int watchdog_disable(void)
162 {
163         mbar_writeShort(MCF_WTM_WCR, 0);
164         return (0);
165 }
166
167 int watchdog_init(void)
168 {
169         mbar_writeShort(MCF_WTM_WCR, MCF_WTM_WCR_EN);
170         return (0);
171 }
172 #endif                          /* #ifdef CONFIG_WATCHDOG */
173
174 #endif
175
176 #ifdef  CONFIG_M5272
177 int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
178 {
179         wdog_t *wdp = (wdog_t *) (MMAP_WDOG);
180
181         out_be16(&wdp->wdog_wrrr, 0);
182         udelay(1000);
183
184         /* enable watchdog, set timeout to 0 and wait */
185         out_be16(&wdp->wdog_wrrr, 1);
186         while (1) ;
187
188         /* we don't return! */
189         return 0;
190 };
191
192 #if defined(CONFIG_DISPLAY_CPUINFO)
193 int print_cpuinfo(void)
194 {
195         sysctrl_t *sysctrl = (sysctrl_t *) (MMAP_CFG);
196         uchar msk;
197         char *suf;
198
199         puts("CPU:   ");
200         msk = (in_be32(&sysctrl->sc_dir) > 28) & 0xf;
201         switch (msk) {
202         case 0x2:
203                 suf = "1K75N";
204                 break;
205         case 0x4:
206                 suf = "3K75N";
207                 break;
208         default:
209                 suf = NULL;
210                 printf("Freescale MCF5272 (Mask:%01x)\n", msk);
211                 break;
212         }
213
214         if (suf)
215                 printf("Freescale MCF5272 %s\n", suf);
216         return 0;
217 };
218 #endif /* CONFIG_DISPLAY_CPUINFO */
219
220 #if defined(CONFIG_WATCHDOG)
221 /* Called by macro WATCHDOG_RESET */
222 void watchdog_reset(void)
223 {
224         wdog_t *wdt = (wdog_t *)(MMAP_WDOG);
225
226         out_be16(&wdt->wdog_wcr, 0);
227 }
228
229 int watchdog_disable(void)
230 {
231         wdog_t *wdt = (wdog_t *)(MMAP_WDOG);
232
233         /* reset watchdog counter */
234         out_be16(&wdt->wdog_wcr, 0);
235         /* disable watchdog interrupt */
236         out_be16(&wdt->wdog_wirr, 0);
237         /* disable watchdog timer */
238         out_be16(&wdt->wdog_wrrr, 0);
239
240         puts("WATCHDOG:disabled\n");
241         return (0);
242 }
243
244 int watchdog_init(void)
245 {
246         wdog_t *wdt = (wdog_t *)(MMAP_WDOG);
247
248         /* disable watchdog interrupt */
249         out_be16(&wdt->wdog_wirr, 0);
250
251         /* set timeout and enable watchdog */
252         out_be16(&wdt->wdog_wrrr,
253                 (CONFIG_WATCHDOG_TIMEOUT * CONFIG_SYS_HZ) / (32768 * 1000) - 1);
254
255         /* reset watchdog counter */
256         out_be16(&wdt->wdog_wcr, 0);
257
258         puts("WATCHDOG:enabled\n");
259         return (0);
260 }
261 #endif                          /* #ifdef CONFIG_WATCHDOG */
262
263 #endif                          /* #ifdef CONFIG_M5272 */
264
265 #ifdef  CONFIG_M5275
266 int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
267 {
268         rcm_t *rcm = (rcm_t *)(MMAP_RCM);
269
270         udelay(1000);
271
272         out_8(&rcm->rcr, RCM_RCR_SOFTRST);
273
274         /* we don't return! */
275         return 0;
276 };
277
278 #if defined(CONFIG_DISPLAY_CPUINFO)
279 int print_cpuinfo(void)
280 {
281         char buf[32];
282
283         printf("CPU:   Freescale Coldfire MCF5275 at %s MHz\n",
284                         strmhz(buf, CONFIG_SYS_CLK));
285         return 0;
286 };
287 #endif /* CONFIG_DISPLAY_CPUINFO */
288
289 #if defined(CONFIG_WATCHDOG)
290 /* Called by macro WATCHDOG_RESET */
291 void watchdog_reset(void)
292 {
293         wdog_t *wdt = (wdog_t *)(MMAP_WDOG);
294
295         out_be16(&wdt->wsr, 0x5555);
296         out_be16(&wdt->wsr, 0xaaaa);
297 }
298
299 int watchdog_disable(void)
300 {
301         wdog_t *wdt = (wdog_t *)(MMAP_WDOG);
302
303         /* reset watchdog counter */
304         out_be16(&wdt->wsr, 0x5555);
305         out_be16(&wdt->wsr, 0xaaaa);
306
307         /* disable watchdog timer */
308         out_be16(&wdt->wcr, 0);
309
310         puts("WATCHDOG:disabled\n");
311         return (0);
312 }
313
314 int watchdog_init(void)
315 {
316         wdog_t *wdt = (wdog_t *)(MMAP_WDOG);
317
318         /* disable watchdog */
319         out_be16(&wdt->wcr, 0);
320
321         /* set timeout and enable watchdog */
322         out_be16(&wdt->wmr,
323                 (CONFIG_WATCHDOG_TIMEOUT * CONFIG_SYS_HZ) / (32768 * 1000) - 1);
324
325         /* reset watchdog counter */
326         out_be16(&wdt->wsr, 0x5555);
327         out_be16(&wdt->wsr, 0xaaaa);
328
329         puts("WATCHDOG:enabled\n");
330         return (0);
331 }
332 #endif                          /* #ifdef CONFIG_WATCHDOG */
333
334 #endif                          /* #ifdef CONFIG_M5275 */
335
336 #ifdef  CONFIG_M5282
337 #if defined(CONFIG_DISPLAY_CPUINFO)
338 int print_cpuinfo(void)
339 {
340         unsigned char resetsource = MCFRESET_RSR;
341
342         printf("CPU:   Freescale Coldfire MCF5282 (PIN: %2.2x REV: %2.2x)\n",
343                MCFCCM_CIR >> 8, MCFCCM_CIR & MCFCCM_CIR_PRN_MASK);
344         printf("Reset:%s%s%s%s%s%s%s\n",
345                (resetsource & MCFRESET_RSR_LOL) ? " Loss of Lock" : "",
346                (resetsource & MCFRESET_RSR_LOC) ? " Loss of Clock" : "",
347                (resetsource & MCFRESET_RSR_EXT) ? " External" : "",
348                (resetsource & MCFRESET_RSR_POR) ? " Power On" : "",
349                (resetsource & MCFRESET_RSR_WDR) ? " Watchdog" : "",
350                (resetsource & MCFRESET_RSR_SOFT) ? " Software" : "",
351                (resetsource & MCFRESET_RSR_LVD) ? " Low Voltage" : "");
352         return 0;
353 }
354 #endif /* CONFIG_DISPLAY_CPUINFO */
355
356 int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
357 {
358         MCFRESET_RCR = MCFRESET_RCR_SOFTRST;
359         return 0;
360 };
361 #endif
362
363 #ifdef CONFIG_M5249
364 #if defined(CONFIG_DISPLAY_CPUINFO)
365 int print_cpuinfo(void)
366 {
367         char buf[32];
368
369         printf("CPU:   Freescale Coldfire MCF5249 at %s MHz\n",
370                strmhz(buf, CONFIG_SYS_CLK));
371         return 0;
372 }
373 #endif /* CONFIG_DISPLAY_CPUINFO */
374
375 int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
376 {
377         /* enable watchdog, set timeout to 0 and wait */
378         mbar_writeByte(MCFSIM_SYPCR, 0xc0);
379         while (1) ;
380
381         /* we don't return! */
382         return 0;
383 };
384 #endif
385
386 #ifdef CONFIG_M5253
387 #if defined(CONFIG_DISPLAY_CPUINFO)
388 int print_cpuinfo(void)
389 {
390         char buf[32];
391
392         unsigned char resetsource = mbar_readLong(SIM_RSR);
393         printf("CPU:   Freescale Coldfire MCF5253 at %s MHz\n",
394                strmhz(buf, CONFIG_SYS_CLK));
395
396         if ((resetsource & SIM_RSR_HRST) || (resetsource & SIM_RSR_SWTR)) {
397                 printf("Reset:%s%s\n",
398                        (resetsource & SIM_RSR_HRST) ? " Hardware/ System Reset"
399                        : "",
400                        (resetsource & SIM_RSR_SWTR) ? " Software Watchdog" :
401                        "");
402         }
403         return 0;
404 }
405 #endif /* CONFIG_DISPLAY_CPUINFO */
406
407 int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
408 {
409         /* enable watchdog, set timeout to 0 and wait */
410         mbar_writeByte(SIM_SYPCR, 0xc0);
411         while (1) ;
412
413         /* we don't return! */
414         return 0;
415 };
416 #endif
417
418 #if defined(CONFIG_MCFFEC)
419 /* Default initializations for MCFFEC controllers.  To override,
420  * create a board-specific function called:
421  *      int board_eth_init(bd_t *bis)
422  */
423
424 int cpu_eth_init(bd_t *bis)
425 {
426         return mcffec_initialize(bis);
427 }
428 #endif