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 | 4d3d729 | 2006-05-31 11:24:28 -0500 | [diff] [blame] | 35 | #ifdef CONFIG_MPC8641HPCN |
| 36 | extern void mpc8641_reset_board(cmd_tbl_t *cmdtp, int flag, |
| 37 | int argc, char *argv[]); |
| 38 | #endif |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 39 | |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 40 | |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 41 | int checkcpu (void) |
| 42 | { |
| 43 | sys_info_t sysinfo; |
| 44 | uint pvr, svr; |
| 45 | uint ver; |
| 46 | uint major, minor; |
| 47 | uint lcrr; /* local bus clock ratio register */ |
| 48 | uint clkdiv; /* clock divider portion of lcrr */ |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 49 | |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 50 | puts("Freescale PowerPC\n"); |
| 51 | |
| 52 | pvr = get_pvr(); |
| 53 | ver = PVR_VER(pvr); |
| 54 | major = PVR_MAJ(pvr); |
| 55 | minor = PVR_MIN(pvr); |
| 56 | |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 57 | puts("CPU:\n"); |
Jon Loeliger | cb5965f | 2006-05-31 12:44:44 -0500 | [diff] [blame^] | 58 | puts(" Core: "); |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 59 | |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 60 | switch (ver) { |
| 61 | case PVR_VER(PVR_86xx): |
| 62 | puts("E600"); |
| 63 | break; |
| 64 | default: |
| 65 | puts("Unknown"); |
| 66 | break; |
| 67 | } |
| 68 | printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr); |
| 69 | |
| 70 | svr = get_svr(); |
| 71 | ver = SVR_VER(svr); |
| 72 | major = SVR_MAJ(svr); |
| 73 | minor = SVR_MIN(svr); |
| 74 | |
| 75 | puts(" System: "); |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 76 | switch (ver) { |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 77 | case SVR_8641: |
| 78 | puts("8641"); |
| 79 | break; |
| 80 | case SVR_8641D: |
| 81 | puts("8641D"); |
| 82 | break; |
| 83 | default: |
| 84 | puts("Unknown"); |
| 85 | break; |
| 86 | } |
| 87 | printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr); |
| 88 | |
| 89 | get_sys_info(&sysinfo); |
| 90 | |
| 91 | puts(" Clocks: "); |
| 92 | printf("CPU:%4lu MHz, ", sysinfo.freqProcessor / 1000000); |
| 93 | printf("MPX:%4lu MHz, ", sysinfo.freqSystemBus / 1000000); |
| 94 | printf("DDR:%4lu MHz, ", sysinfo.freqSystemBus / 2000000); |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 95 | |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 96 | #if defined(CFG_LBC_LCRR) |
| 97 | lcrr = CFG_LBC_LCRR; |
| 98 | #else |
| 99 | { |
| 100 | volatile immap_t *immap = (immap_t *)CFG_IMMR; |
| 101 | volatile ccsr_lbc_t *lbc= &immap->im_lbc; |
| 102 | |
| 103 | lcrr = lbc->lcrr; |
| 104 | } |
| 105 | #endif |
| 106 | clkdiv = lcrr & 0x0f; |
| 107 | if (clkdiv == 2 || clkdiv == 4 || clkdiv == 8) { |
| 108 | printf("LBC:%4lu MHz\n", |
| 109 | sysinfo.freqSystemBus / 1000000 / clkdiv); |
| 110 | } else { |
| 111 | printf(" LBC: unknown (lcrr: 0x%08x)\n", lcrr); |
| 112 | } |
| 113 | |
Jon Loeliger | cb5965f | 2006-05-31 12:44:44 -0500 | [diff] [blame^] | 114 | puts(" L2: "); |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 115 | if (get_l2cr() & 0x80000000) |
Jon Loeliger | cb5965f | 2006-05-31 12:44:44 -0500 | [diff] [blame^] | 116 | puts("Enabled\n"); |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 117 | else |
Jon Loeliger | cb5965f | 2006-05-31 12:44:44 -0500 | [diff] [blame^] | 118 | puts("Disabled\n"); |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 119 | |
| 120 | return 0; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 124 | static inline void |
| 125 | soft_restart(unsigned long addr) |
| 126 | { |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 127 | #ifndef CONFIG_MPC8641HPCN |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 128 | |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 129 | /* SRR0 has system reset vector, SRR1 has default MSR value */ |
| 130 | /* rfi restores MSR from SRR1 and sets the PC to the SRR0 value */ |
| 131 | |
| 132 | __asm__ __volatile__ ("mtspr 26, %0" :: "r" (addr)); |
| 133 | __asm__ __volatile__ ("li 4, (1 << 6)" ::: "r4"); |
| 134 | __asm__ __volatile__ ("mtspr 27, 4"); |
| 135 | __asm__ __volatile__ ("rfi"); |
| 136 | |
| 137 | #else /* CONFIG_MPC8641HPCN */ |
Jon Loeliger | cb5965f | 2006-05-31 12:44:44 -0500 | [diff] [blame^] | 138 | |
| 139 | out8(PIXIS_BASE + PIXIS_RST, 0); |
| 140 | |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 141 | #endif /* !CONFIG_MPC8641HPCN */ |
Jon Loeliger | cb5965f | 2006-05-31 12:44:44 -0500 | [diff] [blame^] | 142 | |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 143 | while(1); /* not reached */ |
| 144 | } |
| 145 | |
| 146 | |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 147 | /* |
| 148 | * No generic way to do board reset. Simply call soft_reset. |
| 149 | */ |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 150 | void |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 151 | do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 152 | { |
Jon Loeliger | cb5965f | 2006-05-31 12:44:44 -0500 | [diff] [blame^] | 153 | #ifndef CONFIG_MPC8641HPCN |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 154 | |
| 155 | #ifdef CFG_RESET_ADDRESS |
Jon Loeliger | cb5965f | 2006-05-31 12:44:44 -0500 | [diff] [blame^] | 156 | ulong addr = CFG_RESET_ADDRESS; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 157 | #else |
| 158 | /* |
| 159 | * note: when CFG_MONITOR_BASE points to a RAM address, |
| 160 | * CFG_MONITOR_BASE - sizeof (ulong) is usually a valid |
| 161 | * address. Better pick an address known to be invalid on your |
| 162 | * system and assign it to CFG_RESET_ADDRESS. |
| 163 | */ |
Jon Loeliger | cb5965f | 2006-05-31 12:44:44 -0500 | [diff] [blame^] | 164 | ulong addr = CFG_MONITOR_BASE - sizeof(ulong); |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 165 | #endif |
| 166 | |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 167 | /* flush and disable I/D cache */ |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 168 | __asm__ __volatile__ ("mfspr 3, 1008" ::: "r3"); |
| 169 | __asm__ __volatile__ ("ori 5, 5, 0xcc00" ::: "r5"); |
| 170 | __asm__ __volatile__ ("ori 4, 3, 0xc00" ::: "r4"); |
| 171 | __asm__ __volatile__ ("andc 5, 3, 5" ::: "r5"); |
| 172 | __asm__ __volatile__ ("sync"); |
| 173 | __asm__ __volatile__ ("mtspr 1008, 4"); |
| 174 | __asm__ __volatile__ ("isync"); |
| 175 | __asm__ __volatile__ ("sync"); |
| 176 | __asm__ __volatile__ ("mtspr 1008, 5"); |
| 177 | __asm__ __volatile__ ("isync"); |
| 178 | __asm__ __volatile__ ("sync"); |
| 179 | |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 180 | soft_restart(addr); |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 181 | |
| 182 | #else /* CONFIG_MPC8641HPCN */ |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 183 | |
Jon Loeliger | 4d3d729 | 2006-05-31 11:24:28 -0500 | [diff] [blame] | 184 | mpc8641_reset_board(cmdtp, flag, argc, argv); |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 185 | |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 186 | #endif /* !CONFIG_MPC8641HPCN */ |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 187 | |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 188 | while(1); /* not reached */ |
| 189 | } |
| 190 | |
| 191 | |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 192 | /* |
| 193 | * Get timebase clock frequency |
| 194 | */ |
| 195 | unsigned long get_tbclk(void) |
| 196 | { |
| 197 | sys_info_t sys_info; |
| 198 | |
| 199 | get_sys_info(&sys_info); |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 200 | return (sys_info.freqSystemBus + 3L) / 4L; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 201 | } |
| 202 | |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 203 | |
| 204 | #if defined(CONFIG_WATCHDOG) |
| 205 | void |
| 206 | watchdog_reset(void) |
| 207 | { |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 208 | } |
| 209 | #endif /* CONFIG_WATCHDOG */ |
| 210 | |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 211 | |
| 212 | #if defined(CONFIG_DDR_ECC) |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 213 | void dma_init(void) |
| 214 | { |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 215 | volatile immap_t *immap = (immap_t *)CFG_IMMR; |
| 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 | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 223 | uint dma_check(void) |
| 224 | { |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 225 | volatile immap_t *immap = (immap_t *)CFG_IMMR; |
| 226 | volatile ccsr_dma_t *dma = &immap->im_dma; |
| 227 | volatile uint status = dma->sr0; |
| 228 | |
| 229 | /* While the channel is busy, spin */ |
| 230 | while((status & 4) == 4) { |
| 231 | status = dma->sr0; |
| 232 | } |
| 233 | |
| 234 | if (status != 0) { |
| 235 | printf ("DMA Error: status = %x\n", status); |
| 236 | } |
| 237 | return status; |
| 238 | } |
| 239 | |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 240 | int dma_xfer(void *dest, uint count, void *src) |
| 241 | { |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 242 | volatile immap_t *immap = (immap_t *)CFG_IMMR; |
| 243 | volatile ccsr_dma_t *dma = &immap->im_dma; |
| 244 | |
| 245 | dma->dar0 = (uint) dest; |
| 246 | dma->sar0 = (uint) src; |
| 247 | dma->bcr0 = count; |
| 248 | dma->mr0 = 0xf000004; |
| 249 | asm("sync;isync"); |
| 250 | dma->mr0 = 0xf000005; |
| 251 | asm("sync;isync"); |
| 252 | return dma_check(); |
| 253 | } |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 254 | |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 255 | #endif /* CONFIG_DDR_ECC */ |
| 256 | |
| 257 | |
| 258 | #ifdef CONFIG_OF_FLAT_TREE |
| 259 | void ft_cpu_setup(void *blob, bd_t *bd) |
| 260 | { |
| 261 | u32 *p; |
| 262 | ulong clock; |
| 263 | int len; |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 264 | |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 265 | clock = bd->bi_busfreq; |
| 266 | p = ft_get_prop(blob, "/cpus/" OF_CPU "/bus-frequency", &len); |
| 267 | if (p != NULL) |
| 268 | *p = cpu_to_be32(clock); |
| 269 | |
| 270 | p = ft_get_prop(blob, "/" OF_SOC "/serial@4500/clock-frequency", &len); |
| 271 | if (p != NULL) |
| 272 | *p = cpu_to_be32(clock); |
| 273 | |
| 274 | p = ft_get_prop(blob, "/" OF_SOC "/serial@4600/clock-frequency", &len); |
| 275 | if (p != NULL) |
| 276 | *p = cpu_to_be32(clock); |
| 277 | |
| 278 | #if defined(CONFIG_MPC86XX_TSEC1) |
| 279 | p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/address", &len); |
| 280 | memcpy(p, bd->bi_enetaddr, 6); |
| 281 | #endif |
Jon Loeliger | 5c9efb3 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 282 | |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 283 | #if defined(CONFIG_MPC86XX_TSEC2) |
| 284 | p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/address", &len); |
| 285 | memcpy(p, bd->bi_enet1addr, 6); |
| 286 | #endif |
| 287 | |
| 288 | #if defined(CONFIG_MPC86XX_TSEC3) |
| 289 | p = ft_get_prop(blob, "/" OF_SOC "/ethernet@26000/address", &len); |
| 290 | memcpy(p, bd->bi_enet2addr, 6); |
| 291 | #endif |
| 292 | |
| 293 | #if defined(CONFIG_MPC86XX_TSEC4) |
| 294 | p = ft_get_prop(blob, "/" OF_SOC "/ethernet@27000/address", &len); |
| 295 | memcpy(p, bd->bi_enet3addr, 6); |
| 296 | #endif |
| 297 | |
| 298 | } |
| 299 | #endif |