1*a47a12beSStefan Roese /* 2*a47a12beSStefan Roese * Copyright 2006,2009-2010 Freescale Semiconductor, Inc. 3*a47a12beSStefan Roese * Jeff Brown 4*a47a12beSStefan Roese * Srikanth Srinivasan (srikanth.srinivasan@freescale.com) 5*a47a12beSStefan Roese * 6*a47a12beSStefan Roese * See file CREDITS for list of people who contributed to this 7*a47a12beSStefan Roese * project. 8*a47a12beSStefan Roese * 9*a47a12beSStefan Roese * This program is free software; you can redistribute it and/or 10*a47a12beSStefan Roese * modify it under the terms of the GNU General Public License as 11*a47a12beSStefan Roese * published by the Free Software Foundation; either version 2 of 12*a47a12beSStefan Roese * the License, or (at your option) any later version. 13*a47a12beSStefan Roese * 14*a47a12beSStefan Roese * This program is distributed in the hope that it will be useful, 15*a47a12beSStefan Roese * but WITHOUT ANY WARRANTY; without even the implied warranty of 16*a47a12beSStefan Roese * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17*a47a12beSStefan Roese * GNU General Public License for more details. 18*a47a12beSStefan Roese * 19*a47a12beSStefan Roese * You should have received a copy of the GNU General Public License 20*a47a12beSStefan Roese * along with this program; if not, write to the Free Software 21*a47a12beSStefan Roese * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 22*a47a12beSStefan Roese * MA 02111-1307 USA 23*a47a12beSStefan Roese */ 24*a47a12beSStefan Roese 25*a47a12beSStefan Roese #include <common.h> 26*a47a12beSStefan Roese #include <watchdog.h> 27*a47a12beSStefan Roese #include <command.h> 28*a47a12beSStefan Roese #include <asm/cache.h> 29*a47a12beSStefan Roese #include <asm/mmu.h> 30*a47a12beSStefan Roese #include <mpc86xx.h> 31*a47a12beSStefan Roese #include <asm/fsl_law.h> 32*a47a12beSStefan Roese 33*a47a12beSStefan Roese DECLARE_GLOBAL_DATA_PTR; 34*a47a12beSStefan Roese 35*a47a12beSStefan Roese /* 36*a47a12beSStefan Roese * Default board reset function 37*a47a12beSStefan Roese */ 38*a47a12beSStefan Roese static void 39*a47a12beSStefan Roese __board_reset(void) 40*a47a12beSStefan Roese { 41*a47a12beSStefan Roese /* Do nothing */ 42*a47a12beSStefan Roese } 43*a47a12beSStefan Roese void board_reset(void) __attribute__((weak, alias("__board_reset"))); 44*a47a12beSStefan Roese 45*a47a12beSStefan Roese 46*a47a12beSStefan Roese int 47*a47a12beSStefan Roese checkcpu(void) 48*a47a12beSStefan Roese { 49*a47a12beSStefan Roese sys_info_t sysinfo; 50*a47a12beSStefan Roese uint pvr, svr; 51*a47a12beSStefan Roese uint ver; 52*a47a12beSStefan Roese uint major, minor; 53*a47a12beSStefan Roese char buf1[32], buf2[32]; 54*a47a12beSStefan Roese volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; 55*a47a12beSStefan Roese volatile ccsr_gur_t *gur = &immap->im_gur; 56*a47a12beSStefan Roese struct cpu_type *cpu; 57*a47a12beSStefan Roese uint msscr0 = mfspr(MSSCR0); 58*a47a12beSStefan Roese 59*a47a12beSStefan Roese svr = get_svr(); 60*a47a12beSStefan Roese ver = SVR_SOC_VER(svr); 61*a47a12beSStefan Roese major = SVR_MAJ(svr); 62*a47a12beSStefan Roese minor = SVR_MIN(svr); 63*a47a12beSStefan Roese 64*a47a12beSStefan Roese if (cpu_numcores() > 1) { 65*a47a12beSStefan Roese #ifndef CONFIG_MP 66*a47a12beSStefan Roese puts("Unicore software on multiprocessor system!!\n" 67*a47a12beSStefan Roese "To enable mutlticore build define CONFIG_MP\n"); 68*a47a12beSStefan Roese #endif 69*a47a12beSStefan Roese } 70*a47a12beSStefan Roese puts("CPU: "); 71*a47a12beSStefan Roese 72*a47a12beSStefan Roese cpu = gd->cpu; 73*a47a12beSStefan Roese 74*a47a12beSStefan Roese puts(cpu->name); 75*a47a12beSStefan Roese 76*a47a12beSStefan Roese printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr); 77*a47a12beSStefan Roese puts("Core: "); 78*a47a12beSStefan Roese 79*a47a12beSStefan Roese pvr = get_pvr(); 80*a47a12beSStefan Roese ver = PVR_E600_VER(pvr); 81*a47a12beSStefan Roese major = PVR_E600_MAJ(pvr); 82*a47a12beSStefan Roese minor = PVR_E600_MIN(pvr); 83*a47a12beSStefan Roese 84*a47a12beSStefan Roese printf("E600 Core %d", (msscr0 & 0x20) ? 1 : 0 ); 85*a47a12beSStefan Roese if (gur->pordevsr & MPC86xx_PORDEVSR_CORE1TE) 86*a47a12beSStefan Roese puts("\n Core1Translation Enabled"); 87*a47a12beSStefan Roese debug(" (MSSCR0=%x, PORDEVSR=%x)", msscr0, gur->pordevsr); 88*a47a12beSStefan Roese 89*a47a12beSStefan Roese printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr); 90*a47a12beSStefan Roese 91*a47a12beSStefan Roese get_sys_info(&sysinfo); 92*a47a12beSStefan Roese 93*a47a12beSStefan Roese puts("Clock Configuration:\n"); 94*a47a12beSStefan Roese printf(" CPU:%-4s MHz, ", strmhz(buf1, sysinfo.freqProcessor)); 95*a47a12beSStefan Roese printf("MPX:%-4s MHz\n", strmhz(buf1, sysinfo.freqSystemBus)); 96*a47a12beSStefan Roese printf(" DDR:%-4s MHz (%s MT/s data rate), ", 97*a47a12beSStefan Roese strmhz(buf1, sysinfo.freqSystemBus / 2), 98*a47a12beSStefan Roese strmhz(buf2, sysinfo.freqSystemBus)); 99*a47a12beSStefan Roese 100*a47a12beSStefan Roese if (sysinfo.freqLocalBus > LCRR_CLKDIV) { 101*a47a12beSStefan Roese printf("LBC:%-4s MHz\n", strmhz(buf1, sysinfo.freqLocalBus)); 102*a47a12beSStefan Roese } else { 103*a47a12beSStefan Roese printf("LBC: unknown (LCRR[CLKDIV] = 0x%02lx)\n", 104*a47a12beSStefan Roese sysinfo.freqLocalBus); 105*a47a12beSStefan Roese } 106*a47a12beSStefan Roese 107*a47a12beSStefan Roese puts("L1: D-cache 32 KB enabled\n"); 108*a47a12beSStefan Roese puts(" I-cache 32 KB enabled\n"); 109*a47a12beSStefan Roese 110*a47a12beSStefan Roese puts("L2: "); 111*a47a12beSStefan Roese if (get_l2cr() & 0x80000000) { 112*a47a12beSStefan Roese #if defined(CONFIG_MPC8610) 113*a47a12beSStefan Roese puts("256"); 114*a47a12beSStefan Roese #elif defined(CONFIG_MPC8641) 115*a47a12beSStefan Roese puts("512"); 116*a47a12beSStefan Roese #endif 117*a47a12beSStefan Roese puts(" KB enabled\n"); 118*a47a12beSStefan Roese } else { 119*a47a12beSStefan Roese puts("Disabled\n"); 120*a47a12beSStefan Roese } 121*a47a12beSStefan Roese 122*a47a12beSStefan Roese return 0; 123*a47a12beSStefan Roese } 124*a47a12beSStefan Roese 125*a47a12beSStefan Roese 126*a47a12beSStefan Roese void 127*a47a12beSStefan Roese do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) 128*a47a12beSStefan Roese { 129*a47a12beSStefan Roese volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; 130*a47a12beSStefan Roese volatile ccsr_gur_t *gur = &immap->im_gur; 131*a47a12beSStefan Roese 132*a47a12beSStefan Roese /* Attempt board-specific reset */ 133*a47a12beSStefan Roese board_reset(); 134*a47a12beSStefan Roese 135*a47a12beSStefan Roese /* Next try asserting HRESET_REQ */ 136*a47a12beSStefan Roese out_be32(&gur->rstcr, MPC86xx_RSTCR_HRST_REQ); 137*a47a12beSStefan Roese 138*a47a12beSStefan Roese while (1) 139*a47a12beSStefan Roese ; 140*a47a12beSStefan Roese } 141*a47a12beSStefan Roese 142*a47a12beSStefan Roese 143*a47a12beSStefan Roese /* 144*a47a12beSStefan Roese * Get timebase clock frequency 145*a47a12beSStefan Roese */ 146*a47a12beSStefan Roese unsigned long 147*a47a12beSStefan Roese get_tbclk(void) 148*a47a12beSStefan Roese { 149*a47a12beSStefan Roese sys_info_t sys_info; 150*a47a12beSStefan Roese 151*a47a12beSStefan Roese get_sys_info(&sys_info); 152*a47a12beSStefan Roese return (sys_info.freqSystemBus + 3L) / 4L; 153*a47a12beSStefan Roese } 154*a47a12beSStefan Roese 155*a47a12beSStefan Roese 156*a47a12beSStefan Roese #if defined(CONFIG_WATCHDOG) 157*a47a12beSStefan Roese void 158*a47a12beSStefan Roese watchdog_reset(void) 159*a47a12beSStefan Roese { 160*a47a12beSStefan Roese #if defined(CONFIG_MPC8610) 161*a47a12beSStefan Roese /* 162*a47a12beSStefan Roese * This actually feed the hard enabled watchdog. 163*a47a12beSStefan Roese */ 164*a47a12beSStefan Roese volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; 165*a47a12beSStefan Roese volatile ccsr_wdt_t *wdt = &immap->im_wdt; 166*a47a12beSStefan Roese volatile ccsr_gur_t *gur = &immap->im_gur; 167*a47a12beSStefan Roese u32 tmp = gur->pordevsr; 168*a47a12beSStefan Roese 169*a47a12beSStefan Roese if (tmp & 0x4000) { 170*a47a12beSStefan Roese wdt->swsrr = 0x556c; 171*a47a12beSStefan Roese wdt->swsrr = 0xaa39; 172*a47a12beSStefan Roese } 173*a47a12beSStefan Roese #endif 174*a47a12beSStefan Roese } 175*a47a12beSStefan Roese #endif /* CONFIG_WATCHDOG */ 176*a47a12beSStefan Roese 177*a47a12beSStefan Roese /* 178*a47a12beSStefan Roese * Print out the state of various machine registers. 179*a47a12beSStefan Roese * Currently prints out LAWs, BR0/OR0, and BATs 180*a47a12beSStefan Roese */ 181*a47a12beSStefan Roese void mpc86xx_reginfo(void) 182*a47a12beSStefan Roese { 183*a47a12beSStefan Roese immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; 184*a47a12beSStefan Roese ccsr_lbc_t *lbc = &immap->im_lbc; 185*a47a12beSStefan Roese 186*a47a12beSStefan Roese print_bats(); 187*a47a12beSStefan Roese print_laws(); 188*a47a12beSStefan Roese 189*a47a12beSStefan Roese printf ("Local Bus Controller Registers\n" 190*a47a12beSStefan Roese "\tBR0\t0x%08X\tOR0\t0x%08X \n", in_be32(&lbc->br0), in_be32(&lbc->or0)); 191*a47a12beSStefan Roese printf("\tBR1\t0x%08X\tOR1\t0x%08X \n", in_be32(&lbc->br1), in_be32(&lbc->or1)); 192*a47a12beSStefan Roese printf("\tBR2\t0x%08X\tOR2\t0x%08X \n", in_be32(&lbc->br2), in_be32(&lbc->or2)); 193*a47a12beSStefan Roese printf("\tBR3\t0x%08X\tOR3\t0x%08X \n", in_be32(&lbc->br3), in_be32(&lbc->or3)); 194*a47a12beSStefan Roese printf("\tBR4\t0x%08X\tOR4\t0x%08X \n", in_be32(&lbc->br4), in_be32(&lbc->or4)); 195*a47a12beSStefan Roese printf("\tBR5\t0x%08X\tOR5\t0x%08X \n", in_be32(&lbc->br5), in_be32(&lbc->or5)); 196*a47a12beSStefan Roese printf("\tBR6\t0x%08X\tOR6\t0x%08X \n", in_be32(&lbc->br6), in_be32(&lbc->or6)); 197*a47a12beSStefan Roese printf("\tBR7\t0x%08X\tOR7\t0x%08X \n", in_be32(&lbc->br7), in_be32(&lbc->or7)); 198*a47a12beSStefan Roese 199*a47a12beSStefan Roese } 200*a47a12beSStefan Roese 201*a47a12beSStefan Roese /* 202*a47a12beSStefan Roese * Set the DDR BATs to reflect the actual size of DDR. 203*a47a12beSStefan Roese * 204*a47a12beSStefan Roese * dram_size is the actual size of DDR, in bytes 205*a47a12beSStefan Roese * 206*a47a12beSStefan Roese * Note: we assume that CONFIG_MAX_MEM_MAPPED is 2G or smaller as we only 207*a47a12beSStefan Roese * are using a single BAT to cover DDR. 208*a47a12beSStefan Roese * 209*a47a12beSStefan Roese * If this is not true, (e.g. CONFIG_MAX_MEM_MAPPED is 2GB but HID0_XBSEN 210*a47a12beSStefan Roese * is not defined) then we might have a situation where U-Boot will attempt 211*a47a12beSStefan Roese * to relocated itself outside of the region mapped by DBAT0. 212*a47a12beSStefan Roese * This will cause a machine check. 213*a47a12beSStefan Roese * 214*a47a12beSStefan Roese * Currently we are limited to power of two sized DDR since we only use a 215*a47a12beSStefan Roese * single bat. If a non-power of two size is used that is less than 216*a47a12beSStefan Roese * CONFIG_MAX_MEM_MAPPED u-boot will crash. 217*a47a12beSStefan Roese * 218*a47a12beSStefan Roese */ 219*a47a12beSStefan Roese void setup_ddr_bat(phys_addr_t dram_size) 220*a47a12beSStefan Roese { 221*a47a12beSStefan Roese unsigned long batu, bl; 222*a47a12beSStefan Roese 223*a47a12beSStefan Roese bl = TO_BATU_BL(min(dram_size, CONFIG_MAX_MEM_MAPPED)); 224*a47a12beSStefan Roese 225*a47a12beSStefan Roese if (BATU_SIZE(bl) != dram_size) { 226*a47a12beSStefan Roese u64 sz = (u64)dram_size - BATU_SIZE(bl); 227*a47a12beSStefan Roese print_size(sz, " left unmapped\n"); 228*a47a12beSStefan Roese } 229*a47a12beSStefan Roese 230*a47a12beSStefan Roese batu = bl | BATU_VS | BATU_VP; 231*a47a12beSStefan Roese write_bat(DBAT0, batu, CONFIG_SYS_DBAT0L); 232*a47a12beSStefan Roese write_bat(IBAT0, batu, CONFIG_SYS_IBAT0L); 233*a47a12beSStefan Roese } 234