wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1 | /* |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 2 | * Copyright 2004 Freescale Semiconductor. |
wdenk | 9c53f40 | 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 | 148e26a | 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 | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 37 | |
| 38 | int checkcpu (void) |
| 39 | { |
wdenk | a445ddf | 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 | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 44 | uint fam; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 45 | uint ver; |
| 46 | uint major, minor; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 47 | |
wdenk | a445ddf | 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 | 3f3262b | 2005-03-15 22:56:53 +0000 | [diff] [blame] | 53 | puts("CPU: "); |
wdenk | a445ddf | 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 | 77a4f6e | 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; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 73 | default: |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 74 | puts("Unknown"); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 75 | break; |
| 76 | } |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 77 | printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 78 | |
wdenk | 3f3262b | 2005-03-15 22:56:53 +0000 | [diff] [blame] | 79 | pvr = get_pvr(); |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 80 | fam = PVR_FAM(pvr); |
wdenk | 3f3262b | 2005-03-15 22:56:53 +0000 | [diff] [blame] | 81 | ver = PVR_VER(pvr); |
| 82 | major = PVR_MAJ(pvr); |
| 83 | minor = PVR_MIN(pvr); |
| 84 | |
| 85 | printf("Core: "); |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 86 | switch (fam) { |
| 87 | case PVR_FAM(PVR_85xx): |
wdenk | 3f3262b | 2005-03-15 22:56:53 +0000 | [diff] [blame] | 88 | puts("E500"); |
| 89 | break; |
| 90 | default: |
| 91 | puts("Unknown"); |
| 92 | break; |
| 93 | } |
| 94 | printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr); |
| 95 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 96 | get_sys_info(&sysinfo); |
| 97 | |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 98 | puts("Clock Configuration:\n"); |
wdenk | 3f3262b | 2005-03-15 22:56:53 +0000 | [diff] [blame] | 99 | printf(" CPU:%4lu MHz, ", sysinfo.freqProcessor / 1000000); |
| 100 | printf("CCB:%4lu MHz,\n", sysinfo.freqSystemBus / 1000000); |
| 101 | printf(" DDR:%4lu MHz, ", sysinfo.freqSystemBus / 2000000); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 102 | |
| 103 | #if defined(CFG_LBC_LCRR) |
| 104 | lcrr = CFG_LBC_LCRR; |
| 105 | #else |
| 106 | { |
| 107 | volatile immap_t *immap = (immap_t *)CFG_IMMR; |
| 108 | volatile ccsr_lbc_t *lbc= &immap->im_lbc; |
| 109 | |
| 110 | lcrr = lbc->lcrr; |
| 111 | } |
| 112 | #endif |
| 113 | clkdiv = lcrr & 0x0f; |
| 114 | if (clkdiv == 2 || clkdiv == 4 || clkdiv == 8) { |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 115 | #ifdef CONFIG_MPC8548 |
| 116 | /* |
| 117 | * Yes, the entire PQ38 family use the same |
| 118 | * bit-representation for twice the clock divider values. |
| 119 | */ |
| 120 | clkdiv *= 2; |
| 121 | #endif |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 122 | printf("LBC:%4lu MHz\n", |
| 123 | sysinfo.freqSystemBus / 1000000 / clkdiv); |
| 124 | } else { |
wdenk | 3f3262b | 2005-03-15 22:56:53 +0000 | [diff] [blame] | 125 | printf("LBC: unknown (lcrr: 0x%08x)\n", lcrr); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | if (ver == SVR_8560) { |
wdenk | 3f3262b | 2005-03-15 22:56:53 +0000 | [diff] [blame] | 129 | printf("CPM: %lu Mhz\n", |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 130 | sysinfo.freqSystemBus / 1000000); |
| 131 | } |
| 132 | |
wdenk | 3f3262b | 2005-03-15 22:56:53 +0000 | [diff] [blame] | 133 | puts("L1: D-cache 32 kB enabled\n I-cache 32 kB enabled\n"); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 134 | |
| 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | |
| 139 | /* ------------------------------------------------------------------------- */ |
| 140 | |
| 141 | int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]) |
| 142 | { |
Zang Roy-r61911 | 395478d | 2006-12-05 16:42:30 +0800 | [diff] [blame^] | 143 | uint pvr; |
| 144 | uint ver; |
| 145 | pvr = get_pvr(); |
| 146 | ver = PVR_VER(pvr); |
| 147 | if (ver & 1){ |
| 148 | /* e500 v2 core has reset control register */ |
| 149 | volatile unsigned int * rstcr; |
| 150 | rstcr = (volatile unsigned int *)(CFG_IMMR + 0xE00B0); |
| 151 | *rstcr = 0x2; /* HRESET_REQ */ |
| 152 | }else{ |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 153 | /* |
| 154 | * Initiate hard reset in debug control register DBCR0 |
| 155 | * Make sure MSR[DE] = 1 |
| 156 | */ |
Zang Roy-r61911 | 395478d | 2006-12-05 16:42:30 +0800 | [diff] [blame^] | 157 | unsigned long val; |
| 158 | val = mfspr(DBCR0); |
| 159 | val |= 0x70000000; |
| 160 | mtspr(DBCR0,val); |
| 161 | } |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 162 | return 1; |
| 163 | } |
| 164 | |
| 165 | |
| 166 | /* |
| 167 | * Get timebase clock frequency |
| 168 | */ |
| 169 | unsigned long get_tbclk (void) |
| 170 | { |
| 171 | |
| 172 | sys_info_t sys_info; |
| 173 | |
| 174 | get_sys_info(&sys_info); |
wdenk | d0245fc | 2005-04-13 10:02:42 +0000 | [diff] [blame] | 175 | return ((sys_info.freqSystemBus + 7L) / 8L); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | |
| 179 | #if defined(CONFIG_WATCHDOG) |
| 180 | void |
| 181 | watchdog_reset(void) |
| 182 | { |
| 183 | int re_enable = disable_interrupts(); |
| 184 | reset_85xx_watchdog(); |
| 185 | if (re_enable) enable_interrupts(); |
| 186 | } |
| 187 | |
| 188 | void |
| 189 | reset_85xx_watchdog(void) |
| 190 | { |
| 191 | /* |
| 192 | * Clear TSR(WIS) bit by writing 1 |
| 193 | */ |
| 194 | unsigned long val; |
| 195 | val = mfspr(tsr); |
| 196 | val |= 0x40000000; |
| 197 | mtspr(tsr, val); |
| 198 | } |
| 199 | #endif /* CONFIG_WATCHDOG */ |
| 200 | |
| 201 | #if defined(CONFIG_DDR_ECC) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 202 | void dma_init(void) { |
| 203 | volatile immap_t *immap = (immap_t *)CFG_IMMR; |
| 204 | volatile ccsr_dma_t *dma = &immap->im_dma; |
| 205 | |
| 206 | dma->satr0 = 0x02c40000; |
| 207 | dma->datr0 = 0x02c40000; |
| 208 | asm("sync; isync; msync"); |
| 209 | return; |
| 210 | } |
| 211 | |
| 212 | uint dma_check(void) { |
| 213 | volatile immap_t *immap = (immap_t *)CFG_IMMR; |
| 214 | volatile ccsr_dma_t *dma = &immap->im_dma; |
| 215 | volatile uint status = dma->sr0; |
| 216 | |
| 217 | /* While the channel is busy, spin */ |
| 218 | while((status & 4) == 4) { |
| 219 | status = dma->sr0; |
| 220 | } |
| 221 | |
| 222 | if (status != 0) { |
| 223 | printf ("DMA Error: status = %x\n", status); |
| 224 | } |
| 225 | return status; |
| 226 | } |
| 227 | |
| 228 | int dma_xfer(void *dest, uint count, void *src) { |
| 229 | volatile immap_t *immap = (immap_t *)CFG_IMMR; |
| 230 | volatile ccsr_dma_t *dma = &immap->im_dma; |
| 231 | |
| 232 | dma->dar0 = (uint) dest; |
| 233 | dma->sar0 = (uint) src; |
| 234 | dma->bcr0 = count; |
| 235 | dma->mr0 = 0xf000004; |
| 236 | asm("sync;isync;msync"); |
| 237 | dma->mr0 = 0xf000005; |
| 238 | asm("sync;isync;msync"); |
| 239 | return dma_check(); |
| 240 | } |
| 241 | #endif |
Matthew McClintock | 148e26a | 2006-06-28 10:43:36 -0500 | [diff] [blame] | 242 | |
| 243 | |
| 244 | #ifdef CONFIG_OF_FLAT_TREE |
| 245 | void |
| 246 | ft_cpu_setup(void *blob, bd_t *bd) |
| 247 | { |
| 248 | u32 *p; |
| 249 | ulong clock; |
| 250 | int len; |
| 251 | |
| 252 | clock = bd->bi_busfreq; |
| 253 | p = ft_get_prop(blob, "/cpus/" OF_CPU "/bus-frequency", &len); |
| 254 | if (p != NULL) |
| 255 | *p = cpu_to_be32(clock); |
| 256 | |
| 257 | p = ft_get_prop(blob, "/" OF_SOC "/serial@4500/clock-frequency", &len); |
| 258 | if (p != NULL) |
| 259 | *p = cpu_to_be32(clock); |
| 260 | |
| 261 | p = ft_get_prop(blob, "/" OF_SOC "/serial@4600/clock-frequency", &len); |
| 262 | if (p != NULL) |
| 263 | *p = cpu_to_be32(clock); |
| 264 | |
| 265 | #if defined(CONFIG_MPC85XX_TSEC1) |
| 266 | p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/mac-address", &len); |
| 267 | memcpy(p, bd->bi_enetaddr, 6); |
| 268 | #endif |
| 269 | |
| 270 | #if defined(CONFIG_HAS_ETH1) |
| 271 | p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/mac-address", &len); |
| 272 | memcpy(p, bd->bi_enet1addr, 6); |
| 273 | #endif |
| 274 | |
| 275 | #if defined(CONFIG_HAS_ETH2) |
| 276 | p = ft_get_prop(blob, "/" OF_SOC "/ethernet@26000/mac-address", &len); |
| 277 | memcpy(p, bd->bi_enet2addr, 6); |
| 278 | #endif |
| 279 | |
| 280 | #if defined(CONFIG_HAS_ETH3) |
| 281 | p = ft_get_prop(blob, "/" OF_SOC "/ethernet@27000/mac-address", &len); |
| 282 | memcpy(p, bd->bi_enet3addr, 6); |
| 283 | #endif |
| 284 | |
| 285 | } |
| 286 | #endif |