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 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 33 | int checkcpu (void) |
| 34 | { |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 35 | sys_info_t sysinfo; |
| 36 | uint lcrr; /* local bus clock ratio register */ |
| 37 | uint clkdiv; /* clock divider portion of lcrr */ |
| 38 | uint pvr, svr; |
Jon Loeliger | d9b94f2 | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 39 | uint fam; |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 40 | uint ver; |
| 41 | uint major, minor; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 42 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 43 | svr = get_svr(); |
| 44 | ver = SVR_VER(svr); |
| 45 | major = SVR_MAJ(svr); |
| 46 | minor = SVR_MIN(svr); |
| 47 | |
wdenk | 6c9e789 | 2005-03-15 22:56:53 +0000 | [diff] [blame] | 48 | puts("CPU: "); |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 49 | switch (ver) { |
| 50 | case SVR_8540: |
| 51 | puts("8540"); |
| 52 | break; |
| 53 | case SVR_8541: |
| 54 | puts("8541"); |
| 55 | break; |
| 56 | case SVR_8555: |
| 57 | puts("8555"); |
| 58 | break; |
| 59 | case SVR_8560: |
| 60 | puts("8560"); |
| 61 | break; |
Jon Loeliger | d9b94f2 | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 62 | case SVR_8548: |
| 63 | puts("8548"); |
| 64 | break; |
| 65 | case SVR_8548_E: |
| 66 | puts("8548_E"); |
| 67 | break; |
Andy Fleming | 151d5d9 | 2007-04-23 01:32:22 -0500 | [diff] [blame] | 68 | case SVR_8544: |
Wolfgang Denk | 2f15278 | 2007-05-05 18:23:11 +0200 | [diff] [blame] | 69 | puts("8544"); |
| 70 | break; |
| 71 | case SVR_8544_E: |
| 72 | puts("8544_E"); |
| 73 | break; |
| 74 | case SVR_8568_E: |
| 75 | puts("8568_E"); |
| 76 | break; |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 77 | default: |
| 78 | puts("Unknown"); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 79 | break; |
| 80 | } |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 81 | printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 82 | |
wdenk | 6c9e789 | 2005-03-15 22:56:53 +0000 | [diff] [blame] | 83 | pvr = get_pvr(); |
Jon Loeliger | d9b94f2 | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 84 | fam = PVR_FAM(pvr); |
wdenk | 6c9e789 | 2005-03-15 22:56:53 +0000 | [diff] [blame] | 85 | ver = PVR_VER(pvr); |
| 86 | major = PVR_MAJ(pvr); |
| 87 | minor = PVR_MIN(pvr); |
| 88 | |
| 89 | printf("Core: "); |
Jon Loeliger | d9b94f2 | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 90 | switch (fam) { |
| 91 | case PVR_FAM(PVR_85xx): |
wdenk | 6c9e789 | 2005-03-15 22:56:53 +0000 | [diff] [blame] | 92 | puts("E500"); |
| 93 | break; |
| 94 | default: |
| 95 | puts("Unknown"); |
| 96 | break; |
| 97 | } |
| 98 | printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr); |
| 99 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 100 | get_sys_info(&sysinfo); |
| 101 | |
Jon Loeliger | d9b94f2 | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 102 | puts("Clock Configuration:\n"); |
wdenk | 6c9e789 | 2005-03-15 22:56:53 +0000 | [diff] [blame] | 103 | printf(" CPU:%4lu MHz, ", sysinfo.freqProcessor / 1000000); |
| 104 | printf("CCB:%4lu MHz,\n", sysinfo.freqSystemBus / 1000000); |
| 105 | printf(" DDR:%4lu MHz, ", sysinfo.freqSystemBus / 2000000); |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 106 | |
| 107 | #if defined(CFG_LBC_LCRR) |
| 108 | lcrr = CFG_LBC_LCRR; |
| 109 | #else |
| 110 | { |
Kumar Gala | 04db400 | 2007-11-29 02:10:09 -0600 | [diff] [blame^] | 111 | volatile ccsr_lbc_t *lbc = (void *)(CFG_MPC85xx_LBC_ADDR); |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 112 | |
| 113 | lcrr = lbc->lcrr; |
| 114 | } |
| 115 | #endif |
| 116 | clkdiv = lcrr & 0x0f; |
| 117 | if (clkdiv == 2 || clkdiv == 4 || clkdiv == 8) { |
Andy Fleming | 151d5d9 | 2007-04-23 01:32:22 -0500 | [diff] [blame] | 118 | #if defined(CONFIG_MPC8548) || defined(CONFIG_MPC8544) |
Jon Loeliger | d9b94f2 | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 119 | /* |
| 120 | * Yes, the entire PQ38 family use the same |
| 121 | * bit-representation for twice the clock divider values. |
| 122 | */ |
| 123 | clkdiv *= 2; |
| 124 | #endif |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 125 | printf("LBC:%4lu MHz\n", |
| 126 | sysinfo.freqSystemBus / 1000000 / clkdiv); |
| 127 | } else { |
wdenk | 6c9e789 | 2005-03-15 22:56:53 +0000 | [diff] [blame] | 128 | printf("LBC: unknown (lcrr: 0x%08x)\n", lcrr); |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | if (ver == SVR_8560) { |
wdenk | 6c9e789 | 2005-03-15 22:56:53 +0000 | [diff] [blame] | 132 | printf("CPM: %lu Mhz\n", |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 133 | sysinfo.freqSystemBus / 1000000); |
| 134 | } |
| 135 | |
wdenk | 6c9e789 | 2005-03-15 22:56:53 +0000 | [diff] [blame] | 136 | 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] | 137 | |
| 138 | return 0; |
| 139 | } |
| 140 | |
| 141 | |
| 142 | /* ------------------------------------------------------------------------- */ |
| 143 | |
| 144 | int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]) |
| 145 | { |
Zang Roy-r61911 | 96629cb | 2006-12-05 16:42:30 +0800 | [diff] [blame] | 146 | uint pvr; |
| 147 | uint ver; |
| 148 | pvr = get_pvr(); |
| 149 | ver = PVR_VER(pvr); |
| 150 | if (ver & 1){ |
| 151 | /* e500 v2 core has reset control register */ |
| 152 | volatile unsigned int * rstcr; |
| 153 | rstcr = (volatile unsigned int *)(CFG_IMMR + 0xE00B0); |
Wolfgang Denk | 2f15278 | 2007-05-05 18:23:11 +0200 | [diff] [blame] | 154 | *rstcr = 0x2; /* HRESET_REQ */ |
Zang Roy-r61911 | 96629cb | 2006-12-05 16:42:30 +0800 | [diff] [blame] | 155 | }else{ |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 156 | /* |
| 157 | * Initiate hard reset in debug control register DBCR0 |
| 158 | * Make sure MSR[DE] = 1 |
| 159 | */ |
urwithsughosh@gmail.com | df90968 | 2007-09-24 13:32:13 -0400 | [diff] [blame] | 160 | unsigned long val, msr; |
| 161 | |
| 162 | msr = mfmsr (); |
| 163 | msr |= MSR_DE; |
| 164 | mtmsr (msr); |
| 165 | |
Zang Roy-r61911 | 96629cb | 2006-12-05 16:42:30 +0800 | [diff] [blame] | 166 | val = mfspr(DBCR0); |
| 167 | val |= 0x70000000; |
| 168 | mtspr(DBCR0,val); |
| 169 | } |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 170 | return 1; |
| 171 | } |
| 172 | |
| 173 | |
| 174 | /* |
| 175 | * Get timebase clock frequency |
| 176 | */ |
| 177 | unsigned long get_tbclk (void) |
| 178 | { |
| 179 | |
| 180 | sys_info_t sys_info; |
| 181 | |
| 182 | get_sys_info(&sys_info); |
wdenk | 2a8af18 | 2005-04-13 10:02:42 +0000 | [diff] [blame] | 183 | return ((sys_info.freqSystemBus + 7L) / 8L); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | |
| 187 | #if defined(CONFIG_WATCHDOG) |
| 188 | void |
| 189 | watchdog_reset(void) |
| 190 | { |
| 191 | int re_enable = disable_interrupts(); |
| 192 | reset_85xx_watchdog(); |
| 193 | if (re_enable) enable_interrupts(); |
| 194 | } |
| 195 | |
| 196 | void |
| 197 | reset_85xx_watchdog(void) |
| 198 | { |
| 199 | /* |
| 200 | * Clear TSR(WIS) bit by writing 1 |
| 201 | */ |
| 202 | unsigned long val; |
Andy Fleming | 03b81b4 | 2007-04-23 01:44:44 -0500 | [diff] [blame] | 203 | val = mfspr(SPRN_TSR); |
| 204 | val |= TSR_WIS; |
| 205 | mtspr(SPRN_TSR, val); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 206 | } |
| 207 | #endif /* CONFIG_WATCHDOG */ |
| 208 | |
| 209 | #if defined(CONFIG_DDR_ECC) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 210 | void dma_init(void) { |
Kumar Gala | 04db400 | 2007-11-29 02:10:09 -0600 | [diff] [blame^] | 211 | volatile ccsr_dma_t *dma = (void *)(CFG_MPC85xx_DMA_ADDR); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 212 | |
| 213 | dma->satr0 = 0x02c40000; |
| 214 | dma->datr0 = 0x02c40000; |
Andy Fleming | 03b81b4 | 2007-04-23 01:44:44 -0500 | [diff] [blame] | 215 | dma->sr0 = 0xfffffff; /* clear any errors */ |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 216 | asm("sync; isync; msync"); |
| 217 | return; |
| 218 | } |
| 219 | |
| 220 | uint dma_check(void) { |
Kumar Gala | 04db400 | 2007-11-29 02:10:09 -0600 | [diff] [blame^] | 221 | volatile ccsr_dma_t *dma = (void *)(CFG_MPC85xx_DMA_ADDR); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 222 | volatile uint status = dma->sr0; |
| 223 | |
| 224 | /* While the channel is busy, spin */ |
| 225 | while((status & 4) == 4) { |
| 226 | status = dma->sr0; |
| 227 | } |
| 228 | |
Andy Fleming | 03b81b4 | 2007-04-23 01:44:44 -0500 | [diff] [blame] | 229 | /* clear MR0[CS] channel start bit */ |
| 230 | dma->mr0 &= 0x00000001; |
| 231 | asm("sync;isync;msync"); |
| 232 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 233 | if (status != 0) { |
| 234 | printf ("DMA Error: status = %x\n", status); |
| 235 | } |
| 236 | return status; |
| 237 | } |
| 238 | |
| 239 | int dma_xfer(void *dest, uint count, void *src) { |
Kumar Gala | 04db400 | 2007-11-29 02:10:09 -0600 | [diff] [blame^] | 240 | volatile ccsr_dma_t *dma = (void *)(CFG_MPC85xx_DMA_ADDR); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 241 | |
| 242 | dma->dar0 = (uint) dest; |
| 243 | dma->sar0 = (uint) src; |
| 244 | dma->bcr0 = count; |
| 245 | dma->mr0 = 0xf000004; |
| 246 | asm("sync;isync;msync"); |
| 247 | dma->mr0 = 0xf000005; |
| 248 | asm("sync;isync;msync"); |
| 249 | return dma_check(); |
| 250 | } |
| 251 | #endif |