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