wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1 | /* |
Andy Fleming | 151d5d9 | 2007-04-23 01:32:22 -0500 | [diff] [blame] | 2 | * Copyright 2004,2007 Freescale Semiconductor, Inc. |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 3 | * (C) Copyright 2002, 2003 Motorola Inc. |
| 4 | * Xianghua Xiao (X.Xiao@motorola.com) |
| 5 | * |
| 6 | * (C) Copyright 2000 |
| 7 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 8 | * |
| 9 | * See file CREDITS for list of people who contributed to this |
| 10 | * project. |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License as |
| 14 | * published by the Free Software Foundation; either version 2 of |
| 15 | * the License, or (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 25 | * MA 02111-1307 USA |
| 26 | */ |
| 27 | |
| 28 | #include <common.h> |
| 29 | #include <watchdog.h> |
| 30 | #include <command.h> |
| 31 | #include <asm/cache.h> |
| 32 | |
Matthew McClintock | 40d5fa3 | 2006-06-28 10:43:36 -0500 | [diff] [blame] | 33 | #if defined(CONFIG_OF_FLAT_TREE) |
| 34 | #include <ft_build.h> |
| 35 | #endif |
| 36 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 37 | |
| 38 | int checkcpu (void) |
| 39 | { |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 40 | sys_info_t sysinfo; |
| 41 | uint lcrr; /* local bus clock ratio register */ |
| 42 | uint clkdiv; /* clock divider portion of lcrr */ |
| 43 | uint pvr, svr; |
Jon Loeliger | d9b94f2 | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 44 | uint fam; |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 45 | uint ver; |
| 46 | uint major, minor; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 47 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 48 | svr = get_svr(); |
| 49 | ver = SVR_VER(svr); |
| 50 | major = SVR_MAJ(svr); |
| 51 | minor = SVR_MIN(svr); |
| 52 | |
wdenk | 6c9e789 | 2005-03-15 22:56:53 +0000 | [diff] [blame] | 53 | puts("CPU: "); |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 54 | switch (ver) { |
| 55 | case SVR_8540: |
| 56 | puts("8540"); |
| 57 | break; |
| 58 | case SVR_8541: |
| 59 | puts("8541"); |
| 60 | break; |
| 61 | case SVR_8555: |
| 62 | puts("8555"); |
| 63 | break; |
| 64 | case SVR_8560: |
| 65 | puts("8560"); |
| 66 | break; |
Jon Loeliger | d9b94f2 | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 67 | case SVR_8548: |
| 68 | puts("8548"); |
| 69 | break; |
| 70 | case SVR_8548_E: |
| 71 | puts("8548_E"); |
| 72 | break; |
Andy Fleming | 151d5d9 | 2007-04-23 01:32:22 -0500 | [diff] [blame] | 73 | case SVR_8544: |
| 74 | puts("8544"); |
| 75 | break; |
| 76 | case SVR_8544_E: |
| 77 | puts("8544_E"); |
| 78 | break; |
Andy Fleming | 6743105 | 2007-04-23 02:54:25 -0500 | [diff] [blame^] | 79 | case SVR_8568_E: |
| 80 | puts("8568_E"); |
| 81 | break; |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 82 | default: |
| 83 | puts("Unknown"); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 84 | break; |
| 85 | } |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 86 | printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 87 | |
wdenk | 6c9e789 | 2005-03-15 22:56:53 +0000 | [diff] [blame] | 88 | pvr = get_pvr(); |
Jon Loeliger | d9b94f2 | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 89 | fam = PVR_FAM(pvr); |
wdenk | 6c9e789 | 2005-03-15 22:56:53 +0000 | [diff] [blame] | 90 | ver = PVR_VER(pvr); |
| 91 | major = PVR_MAJ(pvr); |
| 92 | minor = PVR_MIN(pvr); |
| 93 | |
| 94 | printf("Core: "); |
Jon Loeliger | d9b94f2 | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 95 | switch (fam) { |
| 96 | case PVR_FAM(PVR_85xx): |
wdenk | 6c9e789 | 2005-03-15 22:56:53 +0000 | [diff] [blame] | 97 | puts("E500"); |
| 98 | break; |
| 99 | default: |
| 100 | puts("Unknown"); |
| 101 | break; |
| 102 | } |
| 103 | printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr); |
| 104 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 105 | get_sys_info(&sysinfo); |
| 106 | |
Jon Loeliger | d9b94f2 | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 107 | puts("Clock Configuration:\n"); |
wdenk | 6c9e789 | 2005-03-15 22:56:53 +0000 | [diff] [blame] | 108 | printf(" CPU:%4lu MHz, ", sysinfo.freqProcessor / 1000000); |
| 109 | printf("CCB:%4lu MHz,\n", sysinfo.freqSystemBus / 1000000); |
| 110 | printf(" DDR:%4lu MHz, ", sysinfo.freqSystemBus / 2000000); |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 111 | |
| 112 | #if defined(CFG_LBC_LCRR) |
| 113 | lcrr = CFG_LBC_LCRR; |
| 114 | #else |
| 115 | { |
| 116 | volatile immap_t *immap = (immap_t *)CFG_IMMR; |
| 117 | volatile ccsr_lbc_t *lbc= &immap->im_lbc; |
| 118 | |
| 119 | lcrr = lbc->lcrr; |
| 120 | } |
| 121 | #endif |
| 122 | clkdiv = lcrr & 0x0f; |
| 123 | if (clkdiv == 2 || clkdiv == 4 || clkdiv == 8) { |
Andy Fleming | 151d5d9 | 2007-04-23 01:32:22 -0500 | [diff] [blame] | 124 | #if defined(CONFIG_MPC8548) || defined(CONFIG_MPC8544) |
Jon Loeliger | d9b94f2 | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 125 | /* |
| 126 | * Yes, the entire PQ38 family use the same |
| 127 | * bit-representation for twice the clock divider values. |
| 128 | */ |
| 129 | clkdiv *= 2; |
| 130 | #endif |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 131 | printf("LBC:%4lu MHz\n", |
| 132 | sysinfo.freqSystemBus / 1000000 / clkdiv); |
| 133 | } else { |
wdenk | 6c9e789 | 2005-03-15 22:56:53 +0000 | [diff] [blame] | 134 | printf("LBC: unknown (lcrr: 0x%08x)\n", lcrr); |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | if (ver == SVR_8560) { |
wdenk | 6c9e789 | 2005-03-15 22:56:53 +0000 | [diff] [blame] | 138 | printf("CPM: %lu Mhz\n", |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 139 | sysinfo.freqSystemBus / 1000000); |
| 140 | } |
| 141 | |
wdenk | 6c9e789 | 2005-03-15 22:56:53 +0000 | [diff] [blame] | 142 | puts("L1: D-cache 32 kB enabled\n I-cache 32 kB enabled\n"); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 143 | |
| 144 | return 0; |
| 145 | } |
| 146 | |
| 147 | |
| 148 | /* ------------------------------------------------------------------------- */ |
| 149 | |
| 150 | int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]) |
| 151 | { |
Zang Roy-r61911 | 96629cb | 2006-12-05 16:42:30 +0800 | [diff] [blame] | 152 | uint pvr; |
| 153 | uint ver; |
| 154 | pvr = get_pvr(); |
| 155 | ver = PVR_VER(pvr); |
| 156 | if (ver & 1){ |
| 157 | /* e500 v2 core has reset control register */ |
| 158 | volatile unsigned int * rstcr; |
| 159 | rstcr = (volatile unsigned int *)(CFG_IMMR + 0xE00B0); |
| 160 | *rstcr = 0x2; /* HRESET_REQ */ |
| 161 | }else{ |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 162 | /* |
| 163 | * Initiate hard reset in debug control register DBCR0 |
| 164 | * Make sure MSR[DE] = 1 |
| 165 | */ |
Zang Roy-r61911 | 96629cb | 2006-12-05 16:42:30 +0800 | [diff] [blame] | 166 | unsigned long val; |
| 167 | val = mfspr(DBCR0); |
| 168 | val |= 0x70000000; |
| 169 | mtspr(DBCR0,val); |
| 170 | } |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 171 | return 1; |
| 172 | } |
| 173 | |
| 174 | |
| 175 | /* |
| 176 | * Get timebase clock frequency |
| 177 | */ |
| 178 | unsigned long get_tbclk (void) |
| 179 | { |
| 180 | |
| 181 | sys_info_t sys_info; |
| 182 | |
| 183 | get_sys_info(&sys_info); |
wdenk | 2a8af18 | 2005-04-13 10:02:42 +0000 | [diff] [blame] | 184 | return ((sys_info.freqSystemBus + 7L) / 8L); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | |
| 188 | #if defined(CONFIG_WATCHDOG) |
| 189 | void |
| 190 | watchdog_reset(void) |
| 191 | { |
| 192 | int re_enable = disable_interrupts(); |
| 193 | reset_85xx_watchdog(); |
| 194 | if (re_enable) enable_interrupts(); |
| 195 | } |
| 196 | |
| 197 | void |
| 198 | reset_85xx_watchdog(void) |
| 199 | { |
| 200 | /* |
| 201 | * Clear TSR(WIS) bit by writing 1 |
| 202 | */ |
| 203 | unsigned long val; |
Andy Fleming | 03b81b4 | 2007-04-23 01:44:44 -0500 | [diff] [blame] | 204 | val = mfspr(SPRN_TSR); |
| 205 | val |= TSR_WIS; |
| 206 | mtspr(SPRN_TSR, val); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 207 | } |
| 208 | #endif /* CONFIG_WATCHDOG */ |
| 209 | |
| 210 | #if defined(CONFIG_DDR_ECC) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 211 | void dma_init(void) { |
| 212 | volatile immap_t *immap = (immap_t *)CFG_IMMR; |
| 213 | volatile ccsr_dma_t *dma = &immap->im_dma; |
| 214 | |
| 215 | dma->satr0 = 0x02c40000; |
| 216 | dma->datr0 = 0x02c40000; |
Andy Fleming | 03b81b4 | 2007-04-23 01:44:44 -0500 | [diff] [blame] | 217 | dma->sr0 = 0xfffffff; /* clear any errors */ |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 218 | asm("sync; isync; msync"); |
| 219 | return; |
| 220 | } |
| 221 | |
| 222 | uint dma_check(void) { |
| 223 | volatile immap_t *immap = (immap_t *)CFG_IMMR; |
| 224 | volatile ccsr_dma_t *dma = &immap->im_dma; |
| 225 | volatile uint status = dma->sr0; |
| 226 | |
| 227 | /* While the channel is busy, spin */ |
| 228 | while((status & 4) == 4) { |
| 229 | status = dma->sr0; |
| 230 | } |
| 231 | |
Andy Fleming | 03b81b4 | 2007-04-23 01:44:44 -0500 | [diff] [blame] | 232 | /* clear MR0[CS] channel start bit */ |
| 233 | dma->mr0 &= 0x00000001; |
| 234 | asm("sync;isync;msync"); |
| 235 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 236 | if (status != 0) { |
| 237 | printf ("DMA Error: status = %x\n", status); |
| 238 | } |
| 239 | return status; |
| 240 | } |
| 241 | |
| 242 | int dma_xfer(void *dest, uint count, void *src) { |
| 243 | volatile immap_t *immap = (immap_t *)CFG_IMMR; |
| 244 | volatile ccsr_dma_t *dma = &immap->im_dma; |
| 245 | |
| 246 | dma->dar0 = (uint) dest; |
| 247 | dma->sar0 = (uint) src; |
| 248 | dma->bcr0 = count; |
| 249 | dma->mr0 = 0xf000004; |
| 250 | asm("sync;isync;msync"); |
| 251 | dma->mr0 = 0xf000005; |
| 252 | asm("sync;isync;msync"); |
| 253 | return dma_check(); |
| 254 | } |
| 255 | #endif |
Matthew McClintock | 40d5fa3 | 2006-06-28 10:43:36 -0500 | [diff] [blame] | 256 | |
| 257 | |
| 258 | #ifdef CONFIG_OF_FLAT_TREE |
| 259 | void |
| 260 | ft_cpu_setup(void *blob, bd_t *bd) |
| 261 | { |
| 262 | u32 *p; |
| 263 | ulong clock; |
| 264 | int len; |
| 265 | |
| 266 | clock = bd->bi_busfreq; |
| 267 | p = ft_get_prop(blob, "/cpus/" OF_CPU "/bus-frequency", &len); |
| 268 | if (p != NULL) |
| 269 | *p = cpu_to_be32(clock); |
| 270 | |
Andy Fleming | 6743105 | 2007-04-23 02:54:25 -0500 | [diff] [blame^] | 271 | p = ft_get_prop(blob, "/qe@e0080000/" OF_CPU "/bus-frequency", &len); |
| 272 | if (p != NULL) |
| 273 | *p = cpu_to_be32(clock); |
| 274 | |
Matthew McClintock | 40d5fa3 | 2006-06-28 10:43:36 -0500 | [diff] [blame] | 275 | p = ft_get_prop(blob, "/" OF_SOC "/serial@4500/clock-frequency", &len); |
| 276 | if (p != NULL) |
| 277 | *p = cpu_to_be32(clock); |
| 278 | |
| 279 | p = ft_get_prop(blob, "/" OF_SOC "/serial@4600/clock-frequency", &len); |
| 280 | if (p != NULL) |
| 281 | *p = cpu_to_be32(clock); |
| 282 | |
| 283 | #if defined(CONFIG_MPC85XX_TSEC1) |
| 284 | p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/mac-address", &len); |
Timur Tabi | 85e7c7a | 2007-02-12 13:34:55 -0600 | [diff] [blame] | 285 | if (p) |
| 286 | memcpy(p, bd->bi_enetaddr, 6); |
| 287 | |
| 288 | p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/local-mac-address", &len); |
| 289 | if (p) |
Matthew McClintock | 40d5fa3 | 2006-06-28 10:43:36 -0500 | [diff] [blame] | 290 | memcpy(p, bd->bi_enetaddr, 6); |
| 291 | #endif |
| 292 | |
| 293 | #if defined(CONFIG_HAS_ETH1) |
| 294 | p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/mac-address", &len); |
Timur Tabi | 85e7c7a | 2007-02-12 13:34:55 -0600 | [diff] [blame] | 295 | if (p) |
| 296 | memcpy(p, bd->bi_enet1addr, 6); |
| 297 | |
| 298 | p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/local-mac-address", &len); |
| 299 | if (p) |
Matthew McClintock | 40d5fa3 | 2006-06-28 10:43:36 -0500 | [diff] [blame] | 300 | memcpy(p, bd->bi_enet1addr, 6); |
| 301 | #endif |
| 302 | |
| 303 | #if defined(CONFIG_HAS_ETH2) |
| 304 | p = ft_get_prop(blob, "/" OF_SOC "/ethernet@26000/mac-address", &len); |
Timur Tabi | 85e7c7a | 2007-02-12 13:34:55 -0600 | [diff] [blame] | 305 | if (p) |
| 306 | memcpy(p, bd->bi_enet2addr, 6); |
| 307 | |
| 308 | p = ft_get_prop(blob, "/" OF_SOC "/ethernet@26000/local-mac-address", &len); |
| 309 | if (p) |
Matthew McClintock | 40d5fa3 | 2006-06-28 10:43:36 -0500 | [diff] [blame] | 310 | memcpy(p, bd->bi_enet2addr, 6); |
| 311 | #endif |
| 312 | |
| 313 | #if defined(CONFIG_HAS_ETH3) |
| 314 | p = ft_get_prop(blob, "/" OF_SOC "/ethernet@27000/mac-address", &len); |
Timur Tabi | 85e7c7a | 2007-02-12 13:34:55 -0600 | [diff] [blame] | 315 | if (p) |
| 316 | memcpy(p, bd->bi_enet3addr, 6); |
| 317 | |
| 318 | p = ft_get_prop(blob, "/" OF_SOC "/ethernet@27000/local-mac-address", &len); |
| 319 | if (p) |
Matthew McClintock | 40d5fa3 | 2006-06-28 10:43:36 -0500 | [diff] [blame] | 320 | memcpy(p, bd->bi_enet3addr, 6); |
| 321 | #endif |
| 322 | |
| 323 | } |
| 324 | #endif |