Merge tag 'u-boot-atmel-fixes-2020.07-a' of https://gitlab.denx.de/u-boot/custodians...
[oweals/u-boot.git] / arch / m68k / cpu / mcf547x_8x / cpu.c
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-2007, 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
19 #include <asm/immap.h>
20 #include <asm/io.h>
21
22 DECLARE_GLOBAL_DATA_PTR;
23
24 int do_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
25 {
26         gptmr_t *gptmr = (gptmr_t *) (MMAP_GPTMR);
27
28         out_be16(&gptmr->pre, 10);
29         out_be16(&gptmr->cnt, 1);
30
31         /* enable watchdog, set timeout to 0 and wait */
32         out_8(&gptmr->mode, GPT_TMS_SGPIO);
33         out_8(&gptmr->ctrl, GPT_CTRL_WDEN | GPT_CTRL_CE);
34
35         /* we don't return! */
36         return 1;
37 };
38
39 #if defined(CONFIG_DISPLAY_CPUINFO)
40 int print_cpuinfo(void)
41 {
42         siu_t *siu = (siu_t *) MMAP_SIU;
43         u16 id = 0;
44
45         puts("CPU:   ");
46
47         switch ((in_be32(&siu->jtagid) & 0x000FF000) >> 12) {
48         case 0x0C:
49                 id = 5485;
50                 break;
51         case 0x0D:
52                 id = 5484;
53                 break;
54         case 0x0E:
55                 id = 5483;
56                 break;
57         case 0x0F:
58                 id = 5482;
59                 break;
60         case 0x10:
61                 id = 5481;
62                 break;
63         case 0x11:
64                 id = 5480;
65                 break;
66         case 0x12:
67                 id = 5475;
68                 break;
69         case 0x13:
70                 id = 5474;
71                 break;
72         case 0x14:
73                 id = 5473;
74                 break;
75         case 0x15:
76                 id = 5472;
77                 break;
78         case 0x16:
79                 id = 5471;
80                 break;
81         case 0x17:
82                 id = 5470;
83                 break;
84         }
85
86         if (id) {
87                 char buf1[32], buf2[32];
88
89                 printf("Freescale MCF%d\n", id);
90                 printf("       CPU CLK %s MHz BUS CLK %s MHz\n",
91                        strmhz(buf1, gd->cpu_clk),
92                        strmhz(buf2, gd->bus_clk));
93         }
94
95         return 0;
96 };
97 #endif /* CONFIG_DISPLAY_CPUINFO */
98
99 #if defined(CONFIG_HW_WATCHDOG)
100 /* Called by macro WATCHDOG_RESET */
101 void hw_watchdog_reset(void)
102 {
103         gptmr_t *gptmr = (gptmr_t *) (MMAP_GPTMR);
104
105         out_8(&gptmr->ocpw, 0xa5);
106 }
107
108 int watchdog_disable(void)
109 {
110         gptmr_t *gptmr = (gptmr_t *) (MMAP_GPTMR);
111
112         /* UserManual, once the wdog is disabled, wdog cannot be re-enabled */
113         out_8(&gptmr->mode, 0);
114         out_8(&gptmr->ctrl, 0);
115
116         puts("WATCHDOG:disabled\n");
117
118         return (0);
119 }
120
121 int watchdog_init(void)
122 {
123         gptmr_t *gptmr = (gptmr_t *) (MMAP_GPTMR);
124
125         out_be16(&gptmr->pre, CONFIG_WATCHDOG_TIMEOUT);
126         out_be16(&gptmr->cnt, CONFIG_SYS_TIMER_PRESCALER * 1000);
127
128         out_8(&gptmr->mode, GPT_TMS_SGPIO);
129         out_8(&gptmr->ctrl, GPT_CTRL_CE | GPT_CTRL_WDEN);
130         puts("WATCHDOG:enabled\n");
131
132         return (0);
133 }
134 #endif                          /* CONFIG_HW_WATCHDOG */
135
136 #if defined(CONFIG_FSLDMAFEC) || defined(CONFIG_MCFFEC)
137 /* Default initializations for MCFFEC controllers.  To override,
138  * create a board-specific function called:
139  *      int board_eth_init(bd_t *bis)
140  */
141
142 int cpu_eth_init(bd_t *bis)
143 {
144 #if defined(CONFIG_FSLDMAFEC)
145         mcdmafec_initialize(bis);
146 #endif
147 #if defined(CONFIG_MCFFEC)
148         mcffec_initialize(bis);
149 #endif
150         return 0;
151 }
152 #endif