wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2003 |
| 3 | * Martin Winistoerfer, martinwinistoerfer@gmx.ch. |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 20 | * Foundation, |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | /* |
| 24 | * File: cpu.c |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 25 | * |
| 26 | * Discription: Some cpu specific function for watchdog, |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 27 | * cpu version test, clock setting ... |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 28 | * |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 29 | */ |
| 30 | |
| 31 | |
| 32 | #include <common.h> |
| 33 | #include <watchdog.h> |
| 34 | #include <command.h> |
| 35 | #include <mpc5xx.h> |
| 36 | |
| 37 | |
| 38 | #if (defined(CONFIG_MPC555)) |
| 39 | # define ID_STR "MPC555/556" |
| 40 | |
| 41 | /* |
| 42 | * Check version of cpu with Processor Version Register (PVR) |
| 43 | */ |
| 44 | static int check_cpu_version (long clock, uint pvr, uint immr) |
| 45 | { |
| 46 | char buf[32]; |
| 47 | /* The highest 16 bits should be 0x0002 for a MPC555/556 */ |
| 48 | if ((pvr >> 16) == 0x0002) { |
| 49 | printf (" " ID_STR " Version %x", (pvr >> 16)); |
| 50 | printf (" at %s MHz:", strmhz (buf, clock)); |
| 51 | } else { |
| 52 | printf ("Not supported cpu version"); |
| 53 | return -1; |
| 54 | } |
| 55 | return 0; |
| 56 | } |
| 57 | #endif /* CONFIG_MPC555 */ |
| 58 | |
| 59 | |
| 60 | /* |
| 61 | * Check version of mpc5xx |
| 62 | */ |
| 63 | int checkcpu (void) |
| 64 | { |
| 65 | DECLARE_GLOBAL_DATA_PTR; |
| 66 | |
| 67 | ulong clock = gd->cpu_clk; |
| 68 | uint immr = get_immr (0); /* Return full IMMR contents */ |
| 69 | uint pvr = get_pvr (); /* Retrieve PVR register */ |
| 70 | |
| 71 | puts ("CPU: "); |
| 72 | |
| 73 | return check_cpu_version (clock, pvr, immr); |
| 74 | } |
| 75 | |
| 76 | /* |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 77 | * Called by macro WATCHDOG_RESET |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 78 | */ |
| 79 | #if defined(CONFIG_WATCHDOG) |
| 80 | void watchdog_reset (void) |
| 81 | { |
| 82 | int re_enable = disable_interrupts (); |
| 83 | |
| 84 | reset_5xx_watchdog ((immap_t *) CFG_IMMR); |
| 85 | if (re_enable) |
| 86 | enable_interrupts (); |
| 87 | } |
| 88 | |
| 89 | /* |
| 90 | * Will clear software reset |
| 91 | */ |
| 92 | void reset_5xx_watchdog (volatile immap_t * immr) |
| 93 | { |
| 94 | /* Use the MPC5xx Internal Watchdog */ |
| 95 | immr->im_siu_conf.sc_swsr = 0x556c; /* Prevent SW time-out */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 96 | immr->im_siu_conf.sc_swsr = 0xaa39; |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | #endif /* CONFIG_WATCHDOG */ |
| 100 | |
| 101 | |
| 102 | /* |
| 103 | * Get timebase clock frequency |
| 104 | */ |
| 105 | unsigned long get_tbclk (void) |
| 106 | { |
| 107 | DECLARE_GLOBAL_DATA_PTR; |
| 108 | volatile immap_t *immr = (volatile immap_t *) CFG_IMMR; |
| 109 | ulong oscclk, factor; |
| 110 | |
| 111 | if (immr->im_clkrst.car_sccr & SCCR_TBS) { |
| 112 | return (gd->cpu_clk / 16); |
| 113 | } |
| 114 | |
| 115 | factor = (((CFG_PLPRCR) & PLPRCR_MF_MSK) >> PLPRCR_MF_SHIFT) + 1; |
| 116 | |
| 117 | oscclk = gd->cpu_clk / factor; |
| 118 | |
| 119 | if ((immr->im_clkrst.car_sccr & SCCR_RTSEL) == 0 || factor > 2) { |
| 120 | return (oscclk / 4); |
| 121 | } |
| 122 | return (oscclk / 16); |
| 123 | } |
| 124 | |
wdenk | b6e4c40 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 125 | void dcache_enable (void) |
| 126 | { |
| 127 | return; |
| 128 | } |
| 129 | |
| 130 | void dcache_disable (void) |
| 131 | { |
| 132 | return; |
| 133 | } |
| 134 | |
| 135 | int dcache_status (void) |
| 136 | { |
| 137 | return 0; /* always off */ |
| 138 | } |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 139 | |
| 140 | /* |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 141 | * Reset board |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 142 | */ |
| 143 | int do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) |
| 144 | { |
wdenk | b6e4c40 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 145 | #if defined(CONFIG_PATI) |
| 146 | volatile ulong *addr = (ulong *) CFG_RESET_ADDRESS; |
| 147 | *addr = 1; |
| 148 | #else |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 149 | ulong addr; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 150 | |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 151 | /* Interrupts off, enable reset */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 152 | __asm__ volatile (" mtspr 81, %r0 \n\t" |
wdenk | cceb871 | 2003-06-23 18:12:28 +0000 | [diff] [blame] | 153 | " mfmsr %r3 \n\t" |
| 154 | " rlwinm %r31,%r3,0,25,23\n\t" |
| 155 | " mtmsr %r31 \n\t"); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 156 | /* |
| 157 | * Trying to execute the next instruction at a non-existing address |
| 158 | * should cause a machine check, resulting in reset |
| 159 | */ |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 160 | #ifdef CFG_RESET_ADDRESS |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 161 | addr = CFG_RESET_ADDRESS; |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 162 | #else |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 163 | /* |
| 164 | * note: when CFG_MONITOR_BASE points to a RAM address, CFG_MONITOR_BASE * - sizeof (ulong) is usually a valid address. Better pick an address |
| 165 | * known to be invalid on your system and assign it to CFG_RESET_ADDRESS. |
| 166 | * "(ulong)-1" used to be a good choice for many systems... |
| 167 | */ |
| 168 | addr = CFG_MONITOR_BASE - sizeof (ulong); |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 169 | #endif |
| 170 | ((void (*) (void)) addr) (); |
wdenk | b6e4c40 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 171 | #endif /* #if defined(CONFIG_PATI) */ |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 172 | return 1; |
| 173 | } |