Merge tag 'u-boot-atmel-fixes-2020.07-a' of https://gitlab.denx.de/u-boot/custodians...
[oweals/u-boot.git] / arch / m68k / cpu / mcf523x / 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         ccm_t *ccm = (ccm_t *) MMAP_CCM;
27
28         out_8(&ccm->rcr, CCM_RCR_SOFTRST);
29         /* we don't return! */
30         return 0;
31 }
32
33 #if defined(CONFIG_DISPLAY_CPUINFO)
34 int print_cpuinfo(void)
35 {
36         ccm_t *ccm = (ccm_t *) MMAP_CCM;
37         u16 msk;
38         u16 id = 0;
39         u8 ver;
40
41         puts("CPU:   ");
42         msk = (in_be16(&ccm->cir) >> 6);
43         ver = (in_be16(&ccm->cir) & 0x003f);
44         switch (msk) {
45         case 0x31:
46                 id = 5235;
47                 break;
48         }
49
50         if (id) {
51                 char buf1[32], buf2[32];
52
53                 printf("Freescale MCF%d (Mask:%01x Version:%x)\n", id, msk,
54                        ver);
55                 printf("       CPU CLK %s MHz BUS CLK %s MHz\n",
56                        strmhz(buf1, gd->cpu_clk),
57                        strmhz(buf2, gd->bus_clk));
58         }
59
60         return 0;
61 };
62 #endif /* CONFIG_DISPLAY_CPUINFO */
63
64 #if defined(CONFIG_WATCHDOG)
65 /* Called by macro WATCHDOG_RESET */
66 void watchdog_reset(void)
67 {
68         wdog_t *wdp = (wdog_t *) (MMAP_WDOG);
69
70         /* Count register */
71         out_be16(&wdp->sr, 0x5555);
72         asm("nop");
73         out_be16(&wdp->sr, 0xaaaa);
74 }
75
76 int watchdog_disable(void)
77 {
78         wdog_t *wdp = (wdog_t *) (MMAP_WDOG);
79
80         /* UserManual, once the wdog is disabled, wdog cannot be re-enabled */
81         /* halted watchdog timer */
82         setbits_be16(&wdp->cr, WTM_WCR_HALTED);
83
84         puts("WATCHDOG:disabled\n");
85         return (0);
86 }
87
88 int watchdog_init(void)
89 {
90         wdog_t *wdp = (wdog_t *) (MMAP_WDOG);
91         u32 wdog_module = 0;
92
93         /* set timeout and enable watchdog */
94         wdog_module = ((CONFIG_SYS_CLK / CONFIG_SYS_HZ) * CONFIG_WATCHDOG_TIMEOUT);
95         wdog_module |= (wdog_module / 8192);
96         out_be16(&wdp->mr, wdog_module);
97
98         out_be16(&wdp->cr, WTM_WCR_EN);
99         puts("WATCHDOG:enabled\n");
100
101         return (0);
102 }
103 #endif                          /* CONFIG_WATCHDOG */
104
105 #if defined(CONFIG_MCFFEC)
106 /* Default initializations for MCFFEC controllers.  To override,
107  * create a board-specific function called:
108  *      int board_eth_init(bd_t *bis)
109  */
110
111 int cpu_eth_init(bd_t *bis)
112 {
113         return mcffec_initialize(bis);
114 }
115 #endif