wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2003 |
| 3 | * Martin Winistoerfer, martinwinistoerfer@gmx.ch. |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * File: cpu.c |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 10 | * |
| 11 | * Discription: Some cpu specific function for watchdog, |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 12 | * cpu version test, clock setting ... |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 13 | * |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | |
| 17 | #include <common.h> |
| 18 | #include <watchdog.h> |
| 19 | #include <command.h> |
| 20 | #include <mpc5xx.h> |
| 21 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 22 | DECLARE_GLOBAL_DATA_PTR; |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 23 | |
| 24 | #if (defined(CONFIG_MPC555)) |
| 25 | # define ID_STR "MPC555/556" |
| 26 | |
| 27 | /* |
| 28 | * Check version of cpu with Processor Version Register (PVR) |
| 29 | */ |
| 30 | static int check_cpu_version (long clock, uint pvr, uint immr) |
| 31 | { |
| 32 | char buf[32]; |
| 33 | /* The highest 16 bits should be 0x0002 for a MPC555/556 */ |
| 34 | if ((pvr >> 16) == 0x0002) { |
| 35 | printf (" " ID_STR " Version %x", (pvr >> 16)); |
| 36 | printf (" at %s MHz:", strmhz (buf, clock)); |
| 37 | } else { |
| 38 | printf ("Not supported cpu version"); |
| 39 | return -1; |
| 40 | } |
| 41 | return 0; |
| 42 | } |
| 43 | #endif /* CONFIG_MPC555 */ |
| 44 | |
| 45 | |
| 46 | /* |
| 47 | * Check version of mpc5xx |
| 48 | */ |
| 49 | int checkcpu (void) |
| 50 | { |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 51 | ulong clock = gd->cpu_clk; |
| 52 | uint immr = get_immr (0); /* Return full IMMR contents */ |
| 53 | uint pvr = get_pvr (); /* Retrieve PVR register */ |
| 54 | |
| 55 | puts ("CPU: "); |
| 56 | |
| 57 | return check_cpu_version (clock, pvr, immr); |
| 58 | } |
| 59 | |
| 60 | /* |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 61 | * Called by macro WATCHDOG_RESET |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 62 | */ |
| 63 | #if defined(CONFIG_WATCHDOG) |
| 64 | void watchdog_reset (void) |
| 65 | { |
| 66 | int re_enable = disable_interrupts (); |
| 67 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 68 | reset_5xx_watchdog ((immap_t *) CONFIG_SYS_IMMR); |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 69 | if (re_enable) |
| 70 | enable_interrupts (); |
| 71 | } |
| 72 | |
| 73 | /* |
| 74 | * Will clear software reset |
| 75 | */ |
| 76 | void reset_5xx_watchdog (volatile immap_t * immr) |
| 77 | { |
| 78 | /* Use the MPC5xx Internal Watchdog */ |
| 79 | immr->im_siu_conf.sc_swsr = 0x556c; /* Prevent SW time-out */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 80 | immr->im_siu_conf.sc_swsr = 0xaa39; |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | #endif /* CONFIG_WATCHDOG */ |
| 84 | |
| 85 | |
| 86 | /* |
| 87 | * Get timebase clock frequency |
| 88 | */ |
| 89 | unsigned long get_tbclk (void) |
| 90 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 91 | volatile immap_t *immr = (volatile immap_t *) CONFIG_SYS_IMMR; |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 92 | ulong oscclk, factor; |
| 93 | |
| 94 | if (immr->im_clkrst.car_sccr & SCCR_TBS) { |
| 95 | return (gd->cpu_clk / 16); |
| 96 | } |
| 97 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 98 | factor = (((CONFIG_SYS_PLPRCR) & PLPRCR_MF_MSK) >> PLPRCR_MF_SHIFT) + 1; |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 99 | |
| 100 | oscclk = gd->cpu_clk / factor; |
| 101 | |
| 102 | if ((immr->im_clkrst.car_sccr & SCCR_RTSEL) == 0 || factor > 2) { |
| 103 | return (oscclk / 4); |
| 104 | } |
| 105 | return (oscclk / 16); |
| 106 | } |
| 107 | |
wdenk | b6e4c40 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 108 | void dcache_enable (void) |
| 109 | { |
| 110 | return; |
| 111 | } |
| 112 | |
| 113 | void dcache_disable (void) |
| 114 | { |
| 115 | return; |
| 116 | } |
| 117 | |
| 118 | int dcache_status (void) |
| 119 | { |
| 120 | return 0; /* always off */ |
| 121 | } |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 122 | |
| 123 | /* |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 124 | * Reset board |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 125 | */ |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 126 | int do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 127 | { |
wdenk | b6e4c40 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 128 | #if defined(CONFIG_PATI) |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 129 | volatile ulong *addr = (ulong *) CONFIG_SYS_RESET_ADDRESS; |
wdenk | b6e4c40 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 130 | *addr = 1; |
| 131 | #else |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 132 | ulong addr; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 133 | |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 134 | /* Interrupts off, enable reset */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 135 | __asm__ volatile (" mtspr 81, %r0 \n\t" |
wdenk | cceb871 | 2003-06-23 18:12:28 +0000 | [diff] [blame] | 136 | " mfmsr %r3 \n\t" |
| 137 | " rlwinm %r31,%r3,0,25,23\n\t" |
| 138 | " mtmsr %r31 \n\t"); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 139 | /* |
| 140 | * Trying to execute the next instruction at a non-existing address |
| 141 | * should cause a machine check, resulting in reset |
| 142 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 143 | #ifdef CONFIG_SYS_RESET_ADDRESS |
| 144 | addr = CONFIG_SYS_RESET_ADDRESS; |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 145 | #else |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 146 | /* |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 147 | * note: when CONFIG_SYS_MONITOR_BASE points to a RAM address, CONFIG_SYS_MONITOR_BASE * - sizeof (ulong) is usually a valid address. Better pick an address |
| 148 | * known to be invalid on your system and assign it to CONFIG_SYS_RESET_ADDRESS. |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 149 | * "(ulong)-1" used to be a good choice for many systems... |
| 150 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 151 | addr = CONFIG_SYS_MONITOR_BASE - sizeof (ulong); |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 152 | #endif |
| 153 | ((void (*) (void)) addr) (); |
wdenk | b6e4c40 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 154 | #endif /* #if defined(CONFIG_PATI) */ |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 155 | return 1; |
| 156 | } |