wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2001 |
| 3 | * Josh Huber <huber@mclx.com>, Mission Critical Linux, Inc. |
| 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 |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | /* |
| 25 | * cpu.c |
| 26 | * |
| 27 | * CPU specific code |
| 28 | * |
| 29 | * written or collected and sometimes rewritten by |
| 30 | * Magnus Damm <damm@bitsmart.com> |
| 31 | * |
| 32 | * minor modifications by |
| 33 | * Wolfgang Denk <wd@denx.de> |
| 34 | * |
| 35 | * more modifications by |
| 36 | * Josh Huber <huber@mclx.com> |
| 37 | * added support for the 74xx series of cpus |
| 38 | * added support for the 7xx series of cpus |
| 39 | * made the code a little less hard-coded, and more auto-detectish |
| 40 | */ |
| 41 | |
| 42 | #include <common.h> |
| 43 | #include <command.h> |
| 44 | #include <74xx_7xx.h> |
| 45 | #include <asm/cache.h> |
| 46 | |
wdenk | 452cfd6 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 47 | #ifdef CONFIG_AMIGAONEG3SE |
| 48 | #include "../board/MAI/AmigaOneG3SE/via686.h" |
| 49 | #include "../board/MAI/AmigaOneG3SE/memio.h" |
| 50 | #endif |
| 51 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 52 | DECLARE_GLOBAL_DATA_PTR; |
| 53 | |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 54 | cpu_t |
| 55 | get_cpu_type(void) |
| 56 | { |
| 57 | uint pvr = get_pvr(); |
| 58 | cpu_t type; |
| 59 | |
| 60 | type = CPU_UNKNOWN; |
| 61 | |
| 62 | switch (PVR_VER(pvr)) { |
| 63 | case 0x000c: |
| 64 | type = CPU_7400; |
| 65 | break; |
| 66 | case 0x0008: |
| 67 | type = CPU_750; |
| 68 | |
wdenk | aaf48a9 | 2003-06-20 23:10:58 +0000 | [diff] [blame] | 69 | if (((pvr >> 8) & 0xff) == 0x01) { |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 70 | type = CPU_750CX; /* old CX (80100 and 8010x?)*/ |
| 71 | } else if (((pvr >> 8) & 0xff) == 0x22) { |
| 72 | type = CPU_750CX; /* CX (82201,82202) and CXe (82214) */ |
| 73 | } else if (((pvr >> 8) & 0xff) == 0x33) { |
| 74 | type = CPU_750CX; /* CXe (83311) */ |
| 75 | } else if (((pvr >> 12) & 0xF) == 0x3) { |
| 76 | type = CPU_755; |
wdenk | aaf48a9 | 2003-06-20 23:10:58 +0000 | [diff] [blame] | 77 | } |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 78 | break; |
| 79 | |
wdenk | aaf48a9 | 2003-06-20 23:10:58 +0000 | [diff] [blame] | 80 | case 0x7000: |
| 81 | type = CPU_750FX; |
| 82 | break; |
| 83 | |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 84 | case 0x7002: |
| 85 | type = CPU_750GX; |
| 86 | break; |
| 87 | |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 88 | case 0x800C: |
| 89 | type = CPU_7410; |
| 90 | break; |
| 91 | |
wdenk | aaf48a9 | 2003-06-20 23:10:58 +0000 | [diff] [blame] | 92 | case 0x8000: |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 93 | type = CPU_7450; |
| 94 | break; |
| 95 | |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 96 | case 0x8001: |
| 97 | type = CPU_7455; |
| 98 | break; |
| 99 | |
| 100 | case 0x8002: |
| 101 | type = CPU_7457; |
| 102 | break; |
| 103 | |
Stefan Roese | 45993ea | 2006-11-29 15:42:37 +0100 | [diff] [blame] | 104 | case 0x8004: |
| 105 | type = CPU_7448; |
| 106 | break; |
| 107 | |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 108 | default: |
| 109 | break; |
| 110 | } |
| 111 | |
| 112 | return type; |
| 113 | } |
| 114 | |
| 115 | /* ------------------------------------------------------------------------- */ |
| 116 | |
| 117 | #if !defined(CONFIG_BAB7xx) |
| 118 | int checkcpu (void) |
| 119 | { |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 120 | uint type = get_cpu_type(); |
| 121 | uint pvr = get_pvr(); |
| 122 | ulong clock = gd->cpu_clk; |
| 123 | char buf[32]; |
| 124 | char *str; |
| 125 | |
| 126 | puts ("CPU: "); |
| 127 | |
| 128 | switch (type) { |
| 129 | case CPU_750CX: |
| 130 | printf ("750CX%s v%d.%d", (pvr&0xf0)?"e":"", |
| 131 | (pvr>>8) & 0xf, |
| 132 | pvr & 0xf); |
| 133 | goto PR_CLK; |
| 134 | |
| 135 | case CPU_750: |
| 136 | str = "750"; |
| 137 | break; |
| 138 | |
wdenk | aaf48a9 | 2003-06-20 23:10:58 +0000 | [diff] [blame] | 139 | case CPU_750FX: |
| 140 | str = "750FX"; |
| 141 | break; |
| 142 | |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 143 | case CPU_750GX: |
| 144 | str = "750GX"; |
| 145 | break; |
| 146 | |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 147 | case CPU_755: |
| 148 | str = "755"; |
| 149 | break; |
| 150 | |
| 151 | case CPU_7400: |
| 152 | str = "MPC7400"; |
| 153 | break; |
| 154 | |
wdenk | aaf48a9 | 2003-06-20 23:10:58 +0000 | [diff] [blame] | 155 | case CPU_7410: |
| 156 | str = "MPC7410"; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 157 | break; |
| 158 | |
Stefan Roese | 45993ea | 2006-11-29 15:42:37 +0100 | [diff] [blame] | 159 | case CPU_7448: |
| 160 | str = "MPC7448"; |
| 161 | break; |
| 162 | |
wdenk | aaf48a9 | 2003-06-20 23:10:58 +0000 | [diff] [blame] | 163 | case CPU_7450: |
| 164 | str = "MPC7450"; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 165 | break; |
| 166 | |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 167 | case CPU_7455: |
| 168 | str = "MPC7455"; |
| 169 | break; |
| 170 | |
| 171 | case CPU_7457: |
| 172 | str = "MPC7457"; |
| 173 | break; |
| 174 | |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 175 | default: |
wdenk | aaf48a9 | 2003-06-20 23:10:58 +0000 | [diff] [blame] | 176 | printf("Unknown CPU -- PVR: 0x%08x\n", pvr); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 177 | return -1; |
| 178 | } |
| 179 | |
| 180 | printf ("%s v%d.%d", str, (pvr >> 8) & 0xFF, pvr & 0xFF); |
| 181 | PR_CLK: |
| 182 | printf (" @ %s MHz\n", strmhz(buf, clock)); |
| 183 | |
| 184 | return (0); |
| 185 | } |
| 186 | #endif |
| 187 | /* these two functions are unimplemented currently [josh] */ |
| 188 | |
wdenk | aaf48a9 | 2003-06-20 23:10:58 +0000 | [diff] [blame] | 189 | /* -------------------------------------------------------------------- */ |
| 190 | /* L1 i-cache */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 191 | |
| 192 | int |
| 193 | checkicache(void) |
| 194 | { |
| 195 | return 0; /* XXX */ |
| 196 | } |
| 197 | |
wdenk | aaf48a9 | 2003-06-20 23:10:58 +0000 | [diff] [blame] | 198 | /* -------------------------------------------------------------------- */ |
| 199 | /* L1 d-cache */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 200 | |
| 201 | int |
| 202 | checkdcache(void) |
| 203 | { |
| 204 | return 0; /* XXX */ |
| 205 | } |
| 206 | |
wdenk | aaf48a9 | 2003-06-20 23:10:58 +0000 | [diff] [blame] | 207 | /* -------------------------------------------------------------------- */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 208 | |
| 209 | static inline void |
| 210 | soft_restart(unsigned long addr) |
| 211 | { |
| 212 | /* SRR0 has system reset vector, SRR1 has default MSR value */ |
| 213 | /* rfi restores MSR from SRR1 and sets the PC to the SRR0 value */ |
| 214 | |
| 215 | __asm__ __volatile__ ("mtspr 26, %0" :: "r" (addr)); |
| 216 | __asm__ __volatile__ ("li 4, (1 << 6)" ::: "r4"); |
| 217 | __asm__ __volatile__ ("mtspr 27, 4"); |
| 218 | __asm__ __volatile__ ("rfi"); |
| 219 | |
| 220 | while(1); /* not reached */ |
| 221 | } |
| 222 | |
| 223 | |
| 224 | #if !defined(CONFIG_PCIPPC2) && \ |
| 225 | !defined(CONFIG_BAB7xx) && \ |
Heiko Schocher | d7f77fb | 2006-06-19 11:02:41 +0200 | [diff] [blame] | 226 | !defined(CONFIG_ELPPC) && \ |
| 227 | !defined(CONFIG_PPMC7XX) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 228 | /* no generic way to do board reset. simply call soft_reset. */ |
| 229 | void |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 230 | do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 231 | { |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 232 | ulong addr; |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 233 | /* flush and disable I/D cache */ |
| 234 | __asm__ __volatile__ ("mfspr 3, 1008" ::: "r3"); |
| 235 | __asm__ __volatile__ ("ori 5, 5, 0xcc00" ::: "r5"); |
| 236 | __asm__ __volatile__ ("ori 4, 3, 0xc00" ::: "r4"); |
| 237 | __asm__ __volatile__ ("andc 5, 3, 5" ::: "r5"); |
| 238 | __asm__ __volatile__ ("sync"); |
| 239 | __asm__ __volatile__ ("mtspr 1008, 4"); |
| 240 | __asm__ __volatile__ ("isync"); |
| 241 | __asm__ __volatile__ ("sync"); |
| 242 | __asm__ __volatile__ ("mtspr 1008, 5"); |
| 243 | __asm__ __volatile__ ("isync"); |
| 244 | __asm__ __volatile__ ("sync"); |
| 245 | |
| 246 | #ifdef CFG_RESET_ADDRESS |
| 247 | addr = CFG_RESET_ADDRESS; |
| 248 | #else |
| 249 | /* |
| 250 | * note: when CFG_MONITOR_BASE points to a RAM address, |
| 251 | * CFG_MONITOR_BASE - sizeof (ulong) is usually a valid |
| 252 | * address. Better pick an address known to be invalid on your |
| 253 | * system and assign it to CFG_RESET_ADDRESS. |
| 254 | */ |
| 255 | addr = CFG_MONITOR_BASE - sizeof (ulong); |
| 256 | #endif |
| 257 | soft_restart(addr); |
| 258 | while(1); /* not reached */ |
| 259 | } |
| 260 | #endif |
| 261 | |
| 262 | /* ------------------------------------------------------------------------- */ |
| 263 | |
| 264 | /* |
| 265 | * For the 7400 the TB clock runs at 1/4 the cpu bus speed. |
| 266 | */ |
wdenk | 452cfd6 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 267 | #ifdef CONFIG_AMIGAONEG3SE |
| 268 | unsigned long get_tbclk(void) |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 269 | { |
wdenk | 452cfd6 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 270 | return (gd->bus_clk / 4); |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 271 | } |
wdenk | 452cfd6 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 272 | #else /* ! CONFIG_AMIGAONEG3SE */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 273 | |
wdenk | 452cfd6 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 274 | unsigned long get_tbclk (void) |
| 275 | { |
| 276 | return CFG_BUS_HZ / 4; |
| 277 | } |
| 278 | #endif /* CONFIG_AMIGAONEG3SE */ |
wdenk | 1df49e2 | 2002-09-17 21:37:55 +0000 | [diff] [blame] | 279 | /* ------------------------------------------------------------------------- */ |
| 280 | |
| 281 | #if defined(CONFIG_WATCHDOG) |
| 282 | #if !defined(CONFIG_PCIPPC2) && !defined(CONFIG_BAB7xx) |
| 283 | void |
| 284 | watchdog_reset(void) |
| 285 | { |
| 286 | |
| 287 | } |
| 288 | #endif /* !CONFIG_PCIPPC2 && !CONFIG_BAB7xx */ |
| 289 | #endif /* CONFIG_WATCHDOG */ |
| 290 | |
| 291 | /* ------------------------------------------------------------------------- */ |