Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 2 | /* |
| 3 | * |
| 4 | * (C) Copyright 2000-2003 |
| 5 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 6 | * |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 7 | * Copyright (C) 2004-2007, 2012 Freescale Semiconductor, Inc. |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 8 | * TsiChung Liew (Tsi-Chung.Liew@freescale.com) |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <common.h> |
Simon Glass | f5c208d | 2019-11-14 12:57:20 -0700 | [diff] [blame] | 12 | #include <vsprintf.h> |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 13 | #include <watchdog.h> |
| 14 | #include <command.h> |
Ben Warren | 2f2b6b6 | 2008-08-31 22:22:04 -0700 | [diff] [blame] | 15 | #include <netdev.h> |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 16 | |
| 17 | #include <asm/immap.h> |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 18 | #include <asm/io.h> |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 19 | |
| 20 | DECLARE_GLOBAL_DATA_PTR; |
| 21 | |
Mike Frysinger | 6d1f698 | 2010-10-20 03:41:17 -0400 | [diff] [blame] | 22 | int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 23 | { |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 24 | ccm_t *ccm = (ccm_t *) MMAP_CCM; |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 25 | |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 26 | out_8(&ccm->rcr, CCM_RCR_SOFTRST); |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 27 | /* we don't return! */ |
| 28 | return 0; |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 29 | } |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 30 | |
Angelo Dureghello | 3146b4d | 2017-08-20 00:01:55 +0200 | [diff] [blame] | 31 | #if defined(CONFIG_DISPLAY_CPUINFO) |
| 32 | int print_cpuinfo(void) |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 33 | { |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 34 | ccm_t *ccm = (ccm_t *) MMAP_CCM; |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 35 | u16 msk; |
| 36 | u16 id = 0; |
| 37 | u8 ver; |
| 38 | |
| 39 | puts("CPU: "); |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 40 | msk = (in_be16(&ccm->cir) >> 6); |
| 41 | ver = (in_be16(&ccm->cir) & 0x003f); |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 42 | switch (msk) { |
| 43 | case 0x31: |
| 44 | id = 5235; |
| 45 | break; |
| 46 | } |
| 47 | |
| 48 | if (id) { |
Wolfgang Denk | 2059104 | 2008-10-19 02:35:49 +0200 | [diff] [blame] | 49 | char buf1[32], buf2[32]; |
| 50 | |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 51 | printf("Freescale MCF%d (Mask:%01x Version:%x)\n", id, msk, |
| 52 | ver); |
Wolfgang Denk | 2059104 | 2008-10-19 02:35:49 +0200 | [diff] [blame] | 53 | printf(" CPU CLK %s MHz BUS CLK %s MHz\n", |
TsiChung Liew | 10e9a6e | 2008-10-22 11:55:30 +0000 | [diff] [blame] | 54 | strmhz(buf1, gd->cpu_clk), |
| 55 | strmhz(buf2, gd->bus_clk)); |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | return 0; |
| 59 | }; |
Angelo Dureghello | 3146b4d | 2017-08-20 00:01:55 +0200 | [diff] [blame] | 60 | #endif /* CONFIG_DISPLAY_CPUINFO */ |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 61 | |
| 62 | #if defined(CONFIG_WATCHDOG) |
| 63 | /* Called by macro WATCHDOG_RESET */ |
| 64 | void watchdog_reset(void) |
| 65 | { |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 66 | wdog_t *wdp = (wdog_t *) (MMAP_WDOG); |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 67 | |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 68 | /* Count register */ |
| 69 | out_be16(&wdp->sr, 0x5555); |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 70 | asm("nop"); |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 71 | out_be16(&wdp->sr, 0xaaaa); |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | int watchdog_disable(void) |
| 75 | { |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 76 | wdog_t *wdp = (wdog_t *) (MMAP_WDOG); |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 77 | |
| 78 | /* UserManual, once the wdog is disabled, wdog cannot be re-enabled */ |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 79 | /* halted watchdog timer */ |
| 80 | setbits_be16(&wdp->cr, WTM_WCR_HALTED); |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 81 | |
| 82 | puts("WATCHDOG:disabled\n"); |
| 83 | return (0); |
| 84 | } |
| 85 | |
| 86 | int watchdog_init(void) |
| 87 | { |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 88 | wdog_t *wdp = (wdog_t *) (MMAP_WDOG); |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 89 | u32 wdog_module = 0; |
| 90 | |
| 91 | /* set timeout and enable watchdog */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 92 | wdog_module = ((CONFIG_SYS_CLK / CONFIG_SYS_HZ) * CONFIG_WATCHDOG_TIMEOUT); |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 93 | wdog_module |= (wdog_module / 8192); |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 94 | out_be16(&wdp->mr, wdog_module); |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 95 | |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 96 | out_be16(&wdp->cr, WTM_WCR_EN); |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 97 | puts("WATCHDOG:enabled\n"); |
| 98 | |
| 99 | return (0); |
| 100 | } |
| 101 | #endif /* CONFIG_WATCHDOG */ |
Ben Warren | 90c96db | 2008-08-26 22:16:25 -0700 | [diff] [blame] | 102 | |
| 103 | #if defined(CONFIG_MCFFEC) |
| 104 | /* Default initializations for MCFFEC controllers. To override, |
| 105 | * create a board-specific function called: |
| 106 | * int board_eth_init(bd_t *bis) |
| 107 | */ |
| 108 | |
Ben Warren | 90c96db | 2008-08-26 22:16:25 -0700 | [diff] [blame] | 109 | int cpu_eth_init(bd_t *bis) |
| 110 | { |
| 111 | return mcffec_initialize(bis); |
| 112 | } |
| 113 | #endif |