1a47a12beSStefan Roese /* 2a47a12beSStefan Roese * Copyright (C) 2004-2007 Freescale Semiconductor, Inc. 3a47a12beSStefan Roese * 4a47a12beSStefan Roese * See file CREDITS for list of people who contributed to this 5a47a12beSStefan Roese * project. 6a47a12beSStefan Roese * 7a47a12beSStefan Roese * This program is free software; you can redistribute it and/or 8a47a12beSStefan Roese * modify it under the terms of the GNU General Public License as 9a47a12beSStefan Roese * published by the Free Software Foundation; either version 2 of 10a47a12beSStefan Roese * the License, or (at your option) any later version. 11a47a12beSStefan Roese * 12a47a12beSStefan Roese * This program is distributed in the hope that it will be useful, 13a47a12beSStefan Roese * but WITHOUT ANY WARRANTY; without even the implied warranty of 14a47a12beSStefan Roese * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15a47a12beSStefan Roese * GNU General Public License for more details. 16a47a12beSStefan Roese * 17a47a12beSStefan Roese * You should have received a copy of the GNU General Public License 18a47a12beSStefan Roese * along with this program; if not, write to the Free Software 19a47a12beSStefan Roese * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 20a47a12beSStefan Roese * MA 02111-1307 USA 21a47a12beSStefan Roese */ 22a47a12beSStefan Roese 23a47a12beSStefan Roese /* 24a47a12beSStefan Roese * CPU specific code for the MPC83xx family. 25a47a12beSStefan Roese * 26a47a12beSStefan Roese * Derived from the MPC8260 and MPC85xx. 27a47a12beSStefan Roese */ 28a47a12beSStefan Roese 29a47a12beSStefan Roese #include <common.h> 30a47a12beSStefan Roese #include <watchdog.h> 31a47a12beSStefan Roese #include <command.h> 32a47a12beSStefan Roese #include <mpc83xx.h> 33a47a12beSStefan Roese #include <asm/processor.h> 34a47a12beSStefan Roese #include <libfdt.h> 35a47a12beSStefan Roese #include <tsec.h> 36a47a12beSStefan Roese #include <netdev.h> 37a47a12beSStefan Roese #include <fsl_esdhc.h> 38a47a12beSStefan Roese #ifdef CONFIG_BOOTCOUNT_LIMIT 39a47a12beSStefan Roese #include <asm/immap_qe.h> 40a47a12beSStefan Roese #include <asm/io.h> 41a47a12beSStefan Roese #endif 42a47a12beSStefan Roese 43a47a12beSStefan Roese DECLARE_GLOBAL_DATA_PTR; 44a47a12beSStefan Roese 45a47a12beSStefan Roese int checkcpu(void) 46a47a12beSStefan Roese { 47a47a12beSStefan Roese volatile immap_t *immr; 48a47a12beSStefan Roese ulong clock = gd->cpu_clk; 49a47a12beSStefan Roese u32 pvr = get_pvr(); 50a47a12beSStefan Roese u32 spridr; 51a47a12beSStefan Roese char buf[32]; 52a47a12beSStefan Roese int i; 53a47a12beSStefan Roese 54a47a12beSStefan Roese const struct cpu_type { 55a47a12beSStefan Roese char name[15]; 56a47a12beSStefan Roese u32 partid; 57a47a12beSStefan Roese } cpu_type_list [] = { 587c619ddcSIlya Yanok CPU_TYPE_ENTRY(8308), 59*a88731a6SGerlando Falauto CPU_TYPE_ENTRY(8309), 60a47a12beSStefan Roese CPU_TYPE_ENTRY(8311), 61a47a12beSStefan Roese CPU_TYPE_ENTRY(8313), 62a47a12beSStefan Roese CPU_TYPE_ENTRY(8314), 63a47a12beSStefan Roese CPU_TYPE_ENTRY(8315), 64a47a12beSStefan Roese CPU_TYPE_ENTRY(8321), 65a47a12beSStefan Roese CPU_TYPE_ENTRY(8323), 66a47a12beSStefan Roese CPU_TYPE_ENTRY(8343), 67a47a12beSStefan Roese CPU_TYPE_ENTRY(8347_TBGA_), 68a47a12beSStefan Roese CPU_TYPE_ENTRY(8347_PBGA_), 69a47a12beSStefan Roese CPU_TYPE_ENTRY(8349), 70a47a12beSStefan Roese CPU_TYPE_ENTRY(8358_TBGA_), 71a47a12beSStefan Roese CPU_TYPE_ENTRY(8358_PBGA_), 72a47a12beSStefan Roese CPU_TYPE_ENTRY(8360), 73a47a12beSStefan Roese CPU_TYPE_ENTRY(8377), 74a47a12beSStefan Roese CPU_TYPE_ENTRY(8378), 75a47a12beSStefan Roese CPU_TYPE_ENTRY(8379), 76a47a12beSStefan Roese }; 77a47a12beSStefan Roese 78a47a12beSStefan Roese immr = (immap_t *)CONFIG_SYS_IMMR; 79a47a12beSStefan Roese 80a47a12beSStefan Roese puts("CPU: "); 81a47a12beSStefan Roese 82a47a12beSStefan Roese switch (pvr & 0xffff0000) { 83a47a12beSStefan Roese case PVR_E300C1: 84a47a12beSStefan Roese printf("e300c1, "); 85a47a12beSStefan Roese break; 86a47a12beSStefan Roese 87a47a12beSStefan Roese case PVR_E300C2: 88a47a12beSStefan Roese printf("e300c2, "); 89a47a12beSStefan Roese break; 90a47a12beSStefan Roese 91a47a12beSStefan Roese case PVR_E300C3: 92a47a12beSStefan Roese printf("e300c3, "); 93a47a12beSStefan Roese break; 94a47a12beSStefan Roese 95a47a12beSStefan Roese case PVR_E300C4: 96a47a12beSStefan Roese printf("e300c4, "); 97a47a12beSStefan Roese break; 98a47a12beSStefan Roese 99a47a12beSStefan Roese default: 100a47a12beSStefan Roese printf("Unknown core, "); 101a47a12beSStefan Roese } 102a47a12beSStefan Roese 103a47a12beSStefan Roese spridr = immr->sysconf.spridr; 104a47a12beSStefan Roese 105a47a12beSStefan Roese for (i = 0; i < ARRAY_SIZE(cpu_type_list); i++) 106a47a12beSStefan Roese if (cpu_type_list[i].partid == PARTID_NO_E(spridr)) { 107a47a12beSStefan Roese puts("MPC"); 108a47a12beSStefan Roese puts(cpu_type_list[i].name); 109a47a12beSStefan Roese if (IS_E_PROCESSOR(spridr)) 110a47a12beSStefan Roese puts("E"); 111dfe812c7SKim Phillips if ((SPR_FAMILY(spridr) == SPR_834X_FAMILY || 112dfe812c7SKim Phillips SPR_FAMILY(spridr) == SPR_836X_FAMILY) && 113dfe812c7SKim Phillips REVID_MAJOR(spridr) >= 2) 114a47a12beSStefan Roese puts("A"); 115a47a12beSStefan Roese printf(", Rev: %d.%d", REVID_MAJOR(spridr), 116a47a12beSStefan Roese REVID_MINOR(spridr)); 117a47a12beSStefan Roese break; 118a47a12beSStefan Roese } 119a47a12beSStefan Roese 120a47a12beSStefan Roese if (i == ARRAY_SIZE(cpu_type_list)) 121a47a12beSStefan Roese printf("(SPRIDR %08x unknown), ", spridr); 122a47a12beSStefan Roese 123a47a12beSStefan Roese printf(" at %s MHz, ", strmhz(buf, clock)); 124a47a12beSStefan Roese 125a47a12beSStefan Roese printf("CSB: %s MHz\n", strmhz(buf, gd->csb_clk)); 126a47a12beSStefan Roese 127a47a12beSStefan Roese return 0; 128a47a12beSStefan Roese } 129a47a12beSStefan Roese 130a47a12beSStefan Roese int 13154841ab5SWolfgang Denk do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) 132a47a12beSStefan Roese { 133a47a12beSStefan Roese ulong msr; 134a47a12beSStefan Roese #ifndef MPC83xx_RESET 135a47a12beSStefan Roese ulong addr; 136a47a12beSStefan Roese #endif 137a47a12beSStefan Roese 138a47a12beSStefan Roese volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; 139a47a12beSStefan Roese 140a47a12beSStefan Roese puts("Resetting the board.\n"); 141a47a12beSStefan Roese 142a47a12beSStefan Roese #ifdef MPC83xx_RESET 143a47a12beSStefan Roese 144a47a12beSStefan Roese /* Interrupts and MMU off */ 145a47a12beSStefan Roese __asm__ __volatile__ ("mfmsr %0":"=r" (msr):); 146a47a12beSStefan Roese 147a47a12beSStefan Roese msr &= ~( MSR_EE | MSR_IR | MSR_DR); 148a47a12beSStefan Roese __asm__ __volatile__ ("mtmsr %0"::"r" (msr)); 149a47a12beSStefan Roese 150a47a12beSStefan Roese /* enable Reset Control Reg */ 151a47a12beSStefan Roese immap->reset.rpr = 0x52535445; 152a47a12beSStefan Roese __asm__ __volatile__ ("sync"); 153a47a12beSStefan Roese __asm__ __volatile__ ("isync"); 154a47a12beSStefan Roese 155a47a12beSStefan Roese /* confirm Reset Control Reg is enabled */ 156a47a12beSStefan Roese while(!((immap->reset.rcer) & RCER_CRE)); 157a47a12beSStefan Roese 158a47a12beSStefan Roese udelay(200); 159a47a12beSStefan Roese 160a47a12beSStefan Roese /* perform reset, only one bit */ 161a47a12beSStefan Roese immap->reset.rcr = RCR_SWHR; 162a47a12beSStefan Roese 163a47a12beSStefan Roese #else /* ! MPC83xx_RESET */ 164a47a12beSStefan Roese 165a47a12beSStefan Roese immap->reset.rmr = RMR_CSRE; /* Checkstop Reset enable */ 166a47a12beSStefan Roese 167a47a12beSStefan Roese /* Interrupts and MMU off */ 168a47a12beSStefan Roese __asm__ __volatile__ ("mfmsr %0":"=r" (msr):); 169a47a12beSStefan Roese 170a47a12beSStefan Roese msr &= ~(MSR_ME | MSR_EE | MSR_IR | MSR_DR); 171a47a12beSStefan Roese __asm__ __volatile__ ("mtmsr %0"::"r" (msr)); 172a47a12beSStefan Roese 173a47a12beSStefan Roese /* 174a47a12beSStefan Roese * Trying to execute the next instruction at a non-existing address 175a47a12beSStefan Roese * should cause a machine check, resulting in reset 176a47a12beSStefan Roese */ 177a47a12beSStefan Roese addr = CONFIG_SYS_RESET_ADDRESS; 178a47a12beSStefan Roese 179a47a12beSStefan Roese ((void (*)(void)) addr) (); 180a47a12beSStefan Roese #endif /* MPC83xx_RESET */ 181a47a12beSStefan Roese 182a47a12beSStefan Roese return 1; 183a47a12beSStefan Roese } 184a47a12beSStefan Roese 185a47a12beSStefan Roese 186a47a12beSStefan Roese /* 187a47a12beSStefan Roese * Get timebase clock frequency (like cpu_clk in Hz) 188a47a12beSStefan Roese */ 189a47a12beSStefan Roese 190a47a12beSStefan Roese unsigned long get_tbclk(void) 191a47a12beSStefan Roese { 192a47a12beSStefan Roese ulong tbclk; 193a47a12beSStefan Roese 194a47a12beSStefan Roese tbclk = (gd->bus_clk + 3L) / 4L; 195a47a12beSStefan Roese 196a47a12beSStefan Roese return tbclk; 197a47a12beSStefan Roese } 198a47a12beSStefan Roese 199a47a12beSStefan Roese 200a47a12beSStefan Roese #if defined(CONFIG_WATCHDOG) 201a47a12beSStefan Roese void watchdog_reset (void) 202a47a12beSStefan Roese { 203a47a12beSStefan Roese int re_enable = disable_interrupts(); 204a47a12beSStefan Roese 205a47a12beSStefan Roese /* Reset the 83xx watchdog */ 206a47a12beSStefan Roese volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR; 207a47a12beSStefan Roese immr->wdt.swsrr = 0x556c; 208a47a12beSStefan Roese immr->wdt.swsrr = 0xaa39; 209a47a12beSStefan Roese 210a47a12beSStefan Roese if (re_enable) 211a47a12beSStefan Roese enable_interrupts (); 212a47a12beSStefan Roese } 213a47a12beSStefan Roese #endif 214a47a12beSStefan Roese 215a47a12beSStefan Roese /* 216a47a12beSStefan Roese * Initializes on-chip ethernet controllers. 217a47a12beSStefan Roese * to override, implement board_eth_init() 218a47a12beSStefan Roese */ 219a47a12beSStefan Roese int cpu_eth_init(bd_t *bis) 220a47a12beSStefan Roese { 221a47a12beSStefan Roese #if defined(CONFIG_UEC_ETH) 222a47a12beSStefan Roese uec_standard_init(bis); 223a47a12beSStefan Roese #endif 224a47a12beSStefan Roese 225a47a12beSStefan Roese #if defined(CONFIG_TSEC_ENET) 226a47a12beSStefan Roese tsec_standard_init(bis); 227a47a12beSStefan Roese #endif 228a47a12beSStefan Roese return 0; 229a47a12beSStefan Roese } 230a47a12beSStefan Roese 231a47a12beSStefan Roese /* 232a47a12beSStefan Roese * Initializes on-chip MMC controllers. 233a47a12beSStefan Roese * to override, implement board_mmc_init() 234a47a12beSStefan Roese */ 235a47a12beSStefan Roese int cpu_mmc_init(bd_t *bis) 236a47a12beSStefan Roese { 237a47a12beSStefan Roese #ifdef CONFIG_FSL_ESDHC 238a47a12beSStefan Roese return fsl_esdhc_mmc_init(bis); 239a47a12beSStefan Roese #else 240a47a12beSStefan Roese return 0; 241a47a12beSStefan Roese #endif 242a47a12beSStefan Roese } 243