blob: 72bfdf056bfa96015fdaf85168304996fcb4dc9f [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
TsiChung Liewf6afe722007-06-18 13:50:13 -05002/*
3 *
4 * (C) Copyright 2000-2003
5 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6 *
Alison Wang35d23df2012-03-26 21:49:05 +00007 * Copyright (C) 2004-2008, 2012 Freescale Semiconductor, Inc.
TsiChung Liewf6afe722007-06-18 13:50:13 -05008 * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
TsiChung Liewf6afe722007-06-18 13:50:13 -05009 */
10
11#include <common.h>
Simon Glass97589732020-05-10 11:40:02 -060012#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -060013#include <net.h>
Simon Glassf5c208d2019-11-14 12:57:20 -070014#include <vsprintf.h>
TsiChung Liewf6afe722007-06-18 13:50:13 -050015#include <watchdog.h>
16#include <command.h>
Ben Warren2f2b6b62008-08-31 22:22:04 -070017#include <netdev.h>
Simon Glassdbd79542020-05-10 11:40:11 -060018#include <linux/delay.h>
TsiChung Liewf6afe722007-06-18 13:50:13 -050019
TsiChungLiewfb661742007-07-05 23:01:22 -050020#include <asm/immap.h>
Alison Wang35d23df2012-03-26 21:49:05 +000021#include <asm/io.h>
TsiChung Liewf6afe722007-06-18 13:50:13 -050022
Wolfgang Denkd112a2c2007-09-15 20:48:41 +020023DECLARE_GLOBAL_DATA_PTR;
24
Simon Glassed38aef2020-05-10 11:40:03 -060025int do_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
TsiChung Liewf6afe722007-06-18 13:50:13 -050026{
Alison Wang35d23df2012-03-26 21:49:05 +000027 rcm_t *rcm = (rcm_t *) (MMAP_RCM);
TsiChung Liewf6afe722007-06-18 13:50:13 -050028
TsiChung Liewf6afe722007-06-18 13:50:13 -050029 udelay(1000);
Alison Wang35d23df2012-03-26 21:49:05 +000030 setbits_8(&rcm->rcr, RCM_RCR_SOFTRST);
TsiChung Liewf6afe722007-06-18 13:50:13 -050031
32 /* we don't return! */
33 return 0;
34};
35
Angelo Dureghello3146b4d2017-08-20 00:01:55 +020036#if defined(CONFIG_DISPLAY_CPUINFO)
37int print_cpuinfo(void)
TsiChung Liewf6afe722007-06-18 13:50:13 -050038{
Alison Wang35d23df2012-03-26 21:49:05 +000039 ccm_t *ccm = (ccm_t *) MMAP_CCM;
TsiChung Liewf6afe722007-06-18 13:50:13 -050040 u16 msk;
41 u16 id = 0;
42 u8 ver;
43
44 puts("CPU: ");
Alison Wang35d23df2012-03-26 21:49:05 +000045 msk = (in_be16(&ccm->cir) >> 6);
46 ver = (in_be16(&ccm->cir) & 0x003f);
TsiChung Liewf6afe722007-06-18 13:50:13 -050047 switch (msk) {
TsiChung Liewe7e4fc82008-10-22 11:38:21 +000048#ifdef CONFIG_MCF5301x
49 case 0x78:
50 id = 53010;
51 break;
52 case 0x77:
53 id = 53012;
54 break;
55 case 0x76:
56 id = 53015;
57 break;
58 case 0x74:
59 id = 53011;
60 break;
61 case 0x73:
62 id = 53013;
63 break;
64#endif
65#ifdef CONFIG_MCF532x
TsiChung Liewf6afe722007-06-18 13:50:13 -050066 case 0x54:
67 id = 5329;
68 break;
69 case 0x59:
70 id = 5328;
71 break;
72 case 0x61:
73 id = 5327;
74 break;
TsiChungLiew6f8a0a32008-01-14 17:23:08 -060075 case 0x65:
76 id = 5373;
77 break;
78 case 0x68:
79 id = 53721;
80 break;
81 case 0x69:
82 id = 5372;
83 break;
84 case 0x6B:
85 id = 5372;
86 break;
TsiChung Liewe7e4fc82008-10-22 11:38:21 +000087#endif
TsiChung Liewf6afe722007-06-18 13:50:13 -050088 }
89
90 if (id) {
Wolfgang Denk20591042008-10-19 02:35:49 +020091 char buf1[32], buf2[32];
92
TsiChung Liewf6afe722007-06-18 13:50:13 -050093 printf("Freescale MCF%d (Mask:%01x Version:%x)\n", id, msk,
94 ver);
Wolfgang Denk20591042008-10-19 02:35:49 +020095 printf(" CPU CLK %s MHz BUS CLK %s MHz\n",
TsiChung Liew10e9a6e2008-10-22 11:55:30 +000096 strmhz(buf1, gd->cpu_clk),
97 strmhz(buf2, gd->bus_clk));
TsiChung Liewf6afe722007-06-18 13:50:13 -050098 }
99
100 return 0;
101};
Angelo Dureghello3146b4d2017-08-20 00:01:55 +0200102#endif /* CONFIG_DISPLAY_CPUINFO */
TsiChung Liewf6afe722007-06-18 13:50:13 -0500103
104#if defined(CONFIG_WATCHDOG)
105/* Called by macro WATCHDOG_RESET */
106void watchdog_reset(void)
107{
Alison Wang35d23df2012-03-26 21:49:05 +0000108 wdog_t *wdp = (wdog_t *) (MMAP_WDOG);
TsiChung Liewf6afe722007-06-18 13:50:13 -0500109
Alison Wang35d23df2012-03-26 21:49:05 +0000110 /* Count register */
111 out_be16(&wdp->sr, 0x5555);
112 out_be16(&wdp->sr, 0xaaaa);
TsiChung Liewf6afe722007-06-18 13:50:13 -0500113}
114
115int watchdog_disable(void)
116{
Alison Wang35d23df2012-03-26 21:49:05 +0000117 wdog_t *wdp = (wdog_t *) (MMAP_WDOG);
TsiChung Liewf6afe722007-06-18 13:50:13 -0500118
119 /* UserManual, once the wdog is disabled, wdog cannot be re-enabled */
Alison Wang35d23df2012-03-26 21:49:05 +0000120 /* halted watchdog timer */
121 setbits_be16(&wdp->cr, WTM_WCR_HALTED);
TsiChung Liewf6afe722007-06-18 13:50:13 -0500122
123 puts("WATCHDOG:disabled\n");
124 return (0);
125}
126
127int watchdog_init(void)
128{
Alison Wang35d23df2012-03-26 21:49:05 +0000129 wdog_t *wdp = (wdog_t *) (MMAP_WDOG);
TsiChung Liewf6afe722007-06-18 13:50:13 -0500130 u32 wdog_module = 0;
131
132 /* set timeout and enable watchdog */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200133 wdog_module = ((CONFIG_SYS_CLK / 1000) * CONFIG_WATCHDOG_TIMEOUT);
TsiChungLiew6f8a0a32008-01-14 17:23:08 -0600134#ifdef CONFIG_M5329
Alison Wang35d23df2012-03-26 21:49:05 +0000135 out_be16(&wdp->mr, wdog_module / 8192);
TsiChungLiew6f8a0a32008-01-14 17:23:08 -0600136#else
Alison Wang35d23df2012-03-26 21:49:05 +0000137 out_be16(&wdp->mr, wdog_module / 4096);
TsiChungLiew6f8a0a32008-01-14 17:23:08 -0600138#endif
TsiChung Liewf6afe722007-06-18 13:50:13 -0500139
Alison Wang35d23df2012-03-26 21:49:05 +0000140 out_be16(&wdp->cr, WTM_WCR_EN);
TsiChung Liewf6afe722007-06-18 13:50:13 -0500141 puts("WATCHDOG:enabled\n");
142
143 return (0);
144}
TsiChungLiewfb661742007-07-05 23:01:22 -0500145#endif /* CONFIG_WATCHDOG */
Ben Warren90c96db2008-08-26 22:16:25 -0700146
147#if defined(CONFIG_MCFFEC)
148/* Default initializations for MCFFEC controllers. To override,
149 * create a board-specific function called:
150 * int board_eth_init(bd_t *bis)
151 */
Ben Warren90c96db2008-08-26 22:16:25 -0700152int cpu_eth_init(bd_t *bis)
153{
154 return mcffec_initialize(bis);
155}
156#endif