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