Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 1 | /* |
Jon Loeliger | cb5965f | 2006-05-31 12:44:44 -0500 | [diff] [blame] | 2 | * Copyright 2006 Freescale Semiconductor |
| 3 | * Jeff Brown |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 4 | * Srikanth Srinivasan (srikanth.srinivasan@freescale.com) |
| 5 | * |
| 6 | * See file CREDITS for list of people who contributed to this |
| 7 | * project. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License as |
| 11 | * published by the Free Software Foundation; either version 2 of |
| 12 | * the License, or (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 22 | * MA 02111-1307 USA |
| 23 | */ |
| 24 | |
| 25 | #include <common.h> |
| 26 | #include <watchdog.h> |
| 27 | #include <command.h> |
| 28 | #include <asm/cache.h> |
| 29 | #include <mpc86xx.h> |
| 30 | |
| 31 | #if defined(CONFIG_OF_FLAT_TREE) |
| 32 | #include <ft_build.h> |
| 33 | #endif |
| 34 | |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 35 | int |
| 36 | checkcpu(void) |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 37 | { |
| 38 | sys_info_t sysinfo; |
| 39 | uint pvr, svr; |
| 40 | uint ver; |
| 41 | uint major, minor; |
| 42 | uint lcrr; /* local bus clock ratio register */ |
| 43 | uint clkdiv; /* clock divider portion of lcrr */ |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 44 | |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 45 | puts("Freescale PowerPC\n"); |
| 46 | |
| 47 | pvr = get_pvr(); |
| 48 | ver = PVR_VER(pvr); |
| 49 | major = PVR_MAJ(pvr); |
| 50 | minor = PVR_MIN(pvr); |
| 51 | |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 52 | puts("CPU:\n"); |
Jon Loeliger | cb5965f | 2006-05-31 12:44:44 -0500 | [diff] [blame] | 53 | puts(" Core: "); |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 54 | |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 55 | switch (ver) { |
| 56 | case PVR_VER(PVR_86xx): |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 57 | puts("E600"); |
| 58 | break; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 59 | default: |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 60 | puts("Unknown"); |
| 61 | break; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 62 | } |
| 63 | printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr); |
| 64 | |
| 65 | svr = get_svr(); |
| 66 | ver = SVR_VER(svr); |
| 67 | major = SVR_MAJ(svr); |
| 68 | minor = SVR_MIN(svr); |
| 69 | |
| 70 | puts(" System: "); |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 71 | switch (ver) { |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 72 | case SVR_8641: |
Jon Loeliger | d14ba6a | 2006-09-14 08:40:36 -0500 | [diff] [blame] | 73 | if (SVR_SUBVER(svr) == 1) { |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 74 | puts("8641D"); |
Jon Loeliger | d14ba6a | 2006-09-14 08:40:36 -0500 | [diff] [blame] | 75 | } else { |
| 76 | puts("8641"); |
| 77 | } |
| 78 | break; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 79 | default: |
| 80 | puts("Unknown"); |
| 81 | break; |
| 82 | } |
| 83 | printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr); |
| 84 | |
| 85 | get_sys_info(&sysinfo); |
| 86 | |
| 87 | puts(" Clocks: "); |
| 88 | printf("CPU:%4lu MHz, ", sysinfo.freqProcessor / 1000000); |
| 89 | printf("MPX:%4lu MHz, ", sysinfo.freqSystemBus / 1000000); |
| 90 | printf("DDR:%4lu MHz, ", sysinfo.freqSystemBus / 2000000); |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 91 | |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 92 | #if defined(CFG_LBC_LCRR) |
| 93 | lcrr = CFG_LBC_LCRR; |
| 94 | #else |
| 95 | { |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 96 | volatile immap_t *immap = (immap_t *) CFG_IMMR; |
| 97 | volatile ccsr_lbc_t *lbc = &immap->im_lbc; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 98 | |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 99 | lcrr = lbc->lcrr; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 100 | } |
| 101 | #endif |
| 102 | clkdiv = lcrr & 0x0f; |
| 103 | if (clkdiv == 2 || clkdiv == 4 || clkdiv == 8) { |
| 104 | printf("LBC:%4lu MHz\n", |
| 105 | sysinfo.freqSystemBus / 1000000 / clkdiv); |
| 106 | } else { |
| 107 | printf(" LBC: unknown (lcrr: 0x%08x)\n", lcrr); |
| 108 | } |
| 109 | |
Jon Loeliger | cb5965f | 2006-05-31 12:44:44 -0500 | [diff] [blame] | 110 | puts(" L2: "); |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 111 | if (get_l2cr() & 0x80000000) |
Jon Loeliger | cb5965f | 2006-05-31 12:44:44 -0500 | [diff] [blame] | 112 | puts("Enabled\n"); |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 113 | else |
Jon Loeliger | cb5965f | 2006-05-31 12:44:44 -0500 | [diff] [blame] | 114 | puts("Disabled\n"); |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 115 | |
| 116 | return 0; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 120 | static inline void |
| 121 | soft_restart(unsigned long addr) |
| 122 | { |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 123 | #ifndef CONFIG_MPC8641HPCN |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 124 | |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 125 | /* |
| 126 | * SRR0 has system reset vector, SRR1 has default MSR value |
| 127 | * rfi restores MSR from SRR1 and sets the PC to the SRR0 value |
| 128 | */ |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 129 | |
| 130 | __asm__ __volatile__ ("mtspr 26, %0" :: "r" (addr)); |
| 131 | __asm__ __volatile__ ("li 4, (1 << 6)" ::: "r4"); |
| 132 | __asm__ __volatile__ ("mtspr 27, 4"); |
| 133 | __asm__ __volatile__ ("rfi"); |
| 134 | |
| 135 | #else /* CONFIG_MPC8641HPCN */ |
Jon Loeliger | cb5965f | 2006-05-31 12:44:44 -0500 | [diff] [blame] | 136 | |
| 137 | out8(PIXIS_BASE + PIXIS_RST, 0); |
| 138 | |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 139 | #endif /* !CONFIG_MPC8641HPCN */ |
Jon Loeliger | cb5965f | 2006-05-31 12:44:44 -0500 | [diff] [blame] | 140 | |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 141 | while (1) ; /* not reached */ |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 145 | /* |
| 146 | * No generic way to do board reset. Simply call soft_reset. |
| 147 | */ |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 148 | void |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 149 | do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 150 | { |
Jon Loeliger | cb5965f | 2006-05-31 12:44:44 -0500 | [diff] [blame] | 151 | #ifndef CONFIG_MPC8641HPCN |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 152 | |
| 153 | #ifdef CFG_RESET_ADDRESS |
Jon Loeliger | cb5965f | 2006-05-31 12:44:44 -0500 | [diff] [blame] | 154 | ulong addr = CFG_RESET_ADDRESS; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 155 | #else |
| 156 | /* |
| 157 | * note: when CFG_MONITOR_BASE points to a RAM address, |
| 158 | * CFG_MONITOR_BASE - sizeof (ulong) is usually a valid |
| 159 | * address. Better pick an address known to be invalid on your |
| 160 | * system and assign it to CFG_RESET_ADDRESS. |
| 161 | */ |
Jon Loeliger | cb5965f | 2006-05-31 12:44:44 -0500 | [diff] [blame] | 162 | ulong addr = CFG_MONITOR_BASE - sizeof(ulong); |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 163 | #endif |
| 164 | |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 165 | /* flush and disable I/D cache */ |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 166 | __asm__ __volatile__ ("mfspr 3, 1008" ::: "r3"); |
| 167 | __asm__ __volatile__ ("ori 5, 5, 0xcc00" ::: "r5"); |
| 168 | __asm__ __volatile__ ("ori 4, 3, 0xc00" ::: "r4"); |
| 169 | __asm__ __volatile__ ("andc 5, 3, 5" ::: "r5"); |
| 170 | __asm__ __volatile__ ("sync"); |
| 171 | __asm__ __volatile__ ("mtspr 1008, 4"); |
| 172 | __asm__ __volatile__ ("isync"); |
| 173 | __asm__ __volatile__ ("sync"); |
| 174 | __asm__ __volatile__ ("mtspr 1008, 5"); |
| 175 | __asm__ __volatile__ ("isync"); |
| 176 | __asm__ __volatile__ ("sync"); |
| 177 | |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 178 | soft_restart(addr); |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 179 | |
| 180 | #else /* CONFIG_MPC8641HPCN */ |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 181 | |
Haiying Wang | 3d98b85 | 2007-01-22 12:37:30 -0600 | [diff] [blame^] | 182 | out8(PIXIS_BASE + PIXIS_RST, 0); |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 183 | |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 184 | #endif /* !CONFIG_MPC8641HPCN */ |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 185 | |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 186 | while (1) ; /* not reached */ |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 190 | /* |
| 191 | * Get timebase clock frequency |
| 192 | */ |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 193 | unsigned long |
| 194 | get_tbclk(void) |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 195 | { |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 196 | sys_info_t sys_info; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 197 | |
| 198 | get_sys_info(&sys_info); |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 199 | return (sys_info.freqSystemBus + 3L) / 4L; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 200 | } |
| 201 | |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 202 | |
| 203 | #if defined(CONFIG_WATCHDOG) |
| 204 | void |
| 205 | watchdog_reset(void) |
| 206 | { |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 207 | } |
| 208 | #endif /* CONFIG_WATCHDOG */ |
| 209 | |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 210 | |
| 211 | #if defined(CONFIG_DDR_ECC) |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 212 | void |
| 213 | dma_init(void) |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 214 | { |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 215 | volatile immap_t *immap = (immap_t *) CFG_IMMR; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 216 | volatile ccsr_dma_t *dma = &immap->im_dma; |
| 217 | |
| 218 | dma->satr0 = 0x00040000; |
| 219 | dma->datr0 = 0x00040000; |
| 220 | asm("sync; isync"); |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 221 | } |
| 222 | |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 223 | uint |
| 224 | dma_check(void) |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 225 | { |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 226 | volatile immap_t *immap = (immap_t *) CFG_IMMR; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 227 | volatile ccsr_dma_t *dma = &immap->im_dma; |
| 228 | volatile uint status = dma->sr0; |
| 229 | |
| 230 | /* While the channel is busy, spin */ |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 231 | while ((status & 4) == 4) { |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 232 | status = dma->sr0; |
| 233 | } |
| 234 | |
| 235 | if (status != 0) { |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 236 | printf("DMA Error: status = %x\n", status); |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 237 | } |
| 238 | return status; |
| 239 | } |
| 240 | |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 241 | int |
| 242 | dma_xfer(void *dest, uint count, void *src) |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 243 | { |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 244 | volatile immap_t *immap = (immap_t *) CFG_IMMR; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 245 | volatile ccsr_dma_t *dma = &immap->im_dma; |
| 246 | |
| 247 | dma->dar0 = (uint) dest; |
| 248 | dma->sar0 = (uint) src; |
| 249 | dma->bcr0 = count; |
| 250 | dma->mr0 = 0xf000004; |
| 251 | asm("sync;isync"); |
| 252 | dma->mr0 = 0xf000005; |
| 253 | asm("sync;isync"); |
| 254 | return dma_check(); |
| 255 | } |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 256 | |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 257 | #endif /* CONFIG_DDR_ECC */ |
| 258 | |
| 259 | |
| 260 | #ifdef CONFIG_OF_FLAT_TREE |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 261 | void |
| 262 | ft_cpu_setup(void *blob, bd_t *bd) |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 263 | { |
| 264 | u32 *p; |
| 265 | ulong clock; |
| 266 | int len; |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 267 | |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 268 | clock = bd->bi_busfreq; |
| 269 | p = ft_get_prop(blob, "/cpus/" OF_CPU "/bus-frequency", &len); |
| 270 | if (p != NULL) |
| 271 | *p = cpu_to_be32(clock); |
| 272 | |
| 273 | p = ft_get_prop(blob, "/" OF_SOC "/serial@4500/clock-frequency", &len); |
| 274 | if (p != NULL) |
| 275 | *p = cpu_to_be32(clock); |
| 276 | |
| 277 | p = ft_get_prop(blob, "/" OF_SOC "/serial@4600/clock-frequency", &len); |
| 278 | if (p != NULL) |
| 279 | *p = cpu_to_be32(clock); |
| 280 | |
| 281 | #if defined(CONFIG_MPC86XX_TSEC1) |
Jon Loeliger | 709d307 | 2006-08-03 16:17:56 -0500 | [diff] [blame] | 282 | p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/mac-address", &len); |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 283 | memcpy(p, bd->bi_enetaddr, 6); |
| 284 | #endif |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 285 | |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 286 | #if defined(CONFIG_MPC86XX_TSEC2) |
Jon Loeliger | 709d307 | 2006-08-03 16:17:56 -0500 | [diff] [blame] | 287 | p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/mac-address", &len); |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 288 | memcpy(p, bd->bi_enet1addr, 6); |
| 289 | #endif |
| 290 | |
| 291 | #if defined(CONFIG_MPC86XX_TSEC3) |
Jon Loeliger | 709d307 | 2006-08-03 16:17:56 -0500 | [diff] [blame] | 292 | p = ft_get_prop(blob, "/" OF_SOC "/ethernet@26000/mac-address", &len); |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 293 | memcpy(p, bd->bi_enet2addr, 6); |
| 294 | #endif |
| 295 | |
| 296 | #if defined(CONFIG_MPC86XX_TSEC4) |
Jon Loeliger | 709d307 | 2006-08-03 16:17:56 -0500 | [diff] [blame] | 297 | p = ft_get_prop(blob, "/" OF_SOC "/ethernet@27000/mac-address", &len); |
Jon Loeliger | ffff3ae | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 298 | memcpy(p, bd->bi_enet3addr, 6); |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 299 | #endif |
| 300 | |
| 301 | } |
| 302 | #endif |