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 [] = { 58*7c619ddcSIlya Yanok CPU_TYPE_ENTRY(8308), 59a47a12beSStefan Roese CPU_TYPE_ENTRY(8311), 60a47a12beSStefan Roese CPU_TYPE_ENTRY(8313), 61a47a12beSStefan Roese CPU_TYPE_ENTRY(8314), 62a47a12beSStefan Roese CPU_TYPE_ENTRY(8315), 63a47a12beSStefan Roese CPU_TYPE_ENTRY(8321), 64a47a12beSStefan Roese CPU_TYPE_ENTRY(8323), 65a47a12beSStefan Roese CPU_TYPE_ENTRY(8343), 66a47a12beSStefan Roese CPU_TYPE_ENTRY(8347_TBGA_), 67a47a12beSStefan Roese CPU_TYPE_ENTRY(8347_PBGA_), 68a47a12beSStefan Roese CPU_TYPE_ENTRY(8349), 69a47a12beSStefan Roese CPU_TYPE_ENTRY(8358_TBGA_), 70a47a12beSStefan Roese CPU_TYPE_ENTRY(8358_PBGA_), 71a47a12beSStefan Roese CPU_TYPE_ENTRY(8360), 72a47a12beSStefan Roese CPU_TYPE_ENTRY(8377), 73a47a12beSStefan Roese CPU_TYPE_ENTRY(8378), 74a47a12beSStefan Roese CPU_TYPE_ENTRY(8379), 75a47a12beSStefan Roese }; 76a47a12beSStefan Roese 77a47a12beSStefan Roese immr = (immap_t *)CONFIG_SYS_IMMR; 78a47a12beSStefan Roese 79a47a12beSStefan Roese puts("CPU: "); 80a47a12beSStefan Roese 81a47a12beSStefan Roese switch (pvr & 0xffff0000) { 82a47a12beSStefan Roese case PVR_E300C1: 83a47a12beSStefan Roese printf("e300c1, "); 84a47a12beSStefan Roese break; 85a47a12beSStefan Roese 86a47a12beSStefan Roese case PVR_E300C2: 87a47a12beSStefan Roese printf("e300c2, "); 88a47a12beSStefan Roese break; 89a47a12beSStefan Roese 90a47a12beSStefan Roese case PVR_E300C3: 91a47a12beSStefan Roese printf("e300c3, "); 92a47a12beSStefan Roese break; 93a47a12beSStefan Roese 94a47a12beSStefan Roese case PVR_E300C4: 95a47a12beSStefan Roese printf("e300c4, "); 96a47a12beSStefan Roese break; 97a47a12beSStefan Roese 98a47a12beSStefan Roese default: 99a47a12beSStefan Roese printf("Unknown core, "); 100a47a12beSStefan Roese } 101a47a12beSStefan Roese 102a47a12beSStefan Roese spridr = immr->sysconf.spridr; 103a47a12beSStefan Roese 104a47a12beSStefan Roese for (i = 0; i < ARRAY_SIZE(cpu_type_list); i++) 105a47a12beSStefan Roese if (cpu_type_list[i].partid == PARTID_NO_E(spridr)) { 106a47a12beSStefan Roese puts("MPC"); 107a47a12beSStefan Roese puts(cpu_type_list[i].name); 108a47a12beSStefan Roese if (IS_E_PROCESSOR(spridr)) 109a47a12beSStefan Roese puts("E"); 110dfe812c7SKim Phillips if ((SPR_FAMILY(spridr) == SPR_834X_FAMILY || 111dfe812c7SKim Phillips SPR_FAMILY(spridr) == SPR_836X_FAMILY) && 112dfe812c7SKim Phillips REVID_MAJOR(spridr) >= 2) 113a47a12beSStefan Roese puts("A"); 114a47a12beSStefan Roese printf(", Rev: %d.%d", REVID_MAJOR(spridr), 115a47a12beSStefan Roese REVID_MINOR(spridr)); 116a47a12beSStefan Roese break; 117a47a12beSStefan Roese } 118a47a12beSStefan Roese 119a47a12beSStefan Roese if (i == ARRAY_SIZE(cpu_type_list)) 120a47a12beSStefan Roese printf("(SPRIDR %08x unknown), ", spridr); 121a47a12beSStefan Roese 122a47a12beSStefan Roese printf(" at %s MHz, ", strmhz(buf, clock)); 123a47a12beSStefan Roese 124a47a12beSStefan Roese printf("CSB: %s MHz\n", strmhz(buf, gd->csb_clk)); 125a47a12beSStefan Roese 126a47a12beSStefan Roese return 0; 127a47a12beSStefan Roese } 128a47a12beSStefan Roese 129a47a12beSStefan Roese 130a47a12beSStefan Roese /* 131a47a12beSStefan Roese * Program a UPM with the code supplied in the table. 132a47a12beSStefan Roese * 133a47a12beSStefan Roese * The 'dummy' variable is used to increment the MAD. 'dummy' is 134a47a12beSStefan Roese * supposed to be a pointer to the memory of the device being 135a47a12beSStefan Roese * programmed by the UPM. The data in the MDR is written into 136a47a12beSStefan Roese * memory and the MAD is incremented every time there's a write 137a47a12beSStefan Roese * to 'dummy'. Unfortunately, the current prototype for this 138a47a12beSStefan Roese * function doesn't allow for passing the address of this 139a47a12beSStefan Roese * device, and changing the prototype will break a number lots 140a47a12beSStefan Roese * of other code, so we need to use a round-about way of finding 141a47a12beSStefan Roese * the value for 'dummy'. 142a47a12beSStefan Roese * 143a47a12beSStefan Roese * The value can be extracted from the base address bits of the 144a47a12beSStefan Roese * Base Register (BR) associated with the specific UPM. To find 145a47a12beSStefan Roese * that BR, we need to scan all 8 BRs until we find the one that 146a47a12beSStefan Roese * has its MSEL bits matching the UPM we want. Once we know the 147a47a12beSStefan Roese * right BR, we can extract the base address bits from it. 148a47a12beSStefan Roese * 149a47a12beSStefan Roese * The MxMR and the BR and OR of the chosen bank should all be 150a47a12beSStefan Roese * configured before calling this function. 151a47a12beSStefan Roese * 152a47a12beSStefan Roese * Parameters: 153a47a12beSStefan Roese * upm: 0=UPMA, 1=UPMB, 2=UPMC 154a47a12beSStefan Roese * table: Pointer to an array of values to program 155a47a12beSStefan Roese * size: Number of elements in the array. Must be 64 or less. 156a47a12beSStefan Roese */ 157a47a12beSStefan Roese void upmconfig (uint upm, uint *table, uint size) 158a47a12beSStefan Roese { 159a47a12beSStefan Roese volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; 160a47a12beSStefan Roese volatile fsl_lbus_t *lbus = &immap->lbus; 161a47a12beSStefan Roese volatile uchar *dummy = NULL; 162a47a12beSStefan Roese const u32 msel = (upm + 4) << BR_MSEL_SHIFT; /* What the MSEL field in BRn should be */ 163a47a12beSStefan Roese volatile u32 *mxmr = &lbus->mamr + upm; /* Pointer to mamr, mbmr, or mcmr */ 164a47a12beSStefan Roese uint i; 165a47a12beSStefan Roese 166a47a12beSStefan Roese /* Scan all the banks to determine the base address of the device */ 167a47a12beSStefan Roese for (i = 0; i < 8; i++) { 168a47a12beSStefan Roese if ((lbus->bank[i].br & BR_MSEL) == msel) { 169a47a12beSStefan Roese dummy = (uchar *) (lbus->bank[i].br & BR_BA); 170a47a12beSStefan Roese break; 171a47a12beSStefan Roese } 172a47a12beSStefan Roese } 173a47a12beSStefan Roese 174a47a12beSStefan Roese if (!dummy) { 175a47a12beSStefan Roese printf("Error: %s() could not find matching BR\n", __FUNCTION__); 176a47a12beSStefan Roese hang(); 177a47a12beSStefan Roese } 178a47a12beSStefan Roese 179a47a12beSStefan Roese /* Set the OP field in the MxMR to "write" and the MAD field to 000000 */ 180a47a12beSStefan Roese *mxmr = (*mxmr & 0xCFFFFFC0) | 0x10000000; 181a47a12beSStefan Roese 182a47a12beSStefan Roese for (i = 0; i < size; i++) { 183a47a12beSStefan Roese lbus->mdr = table[i]; 184a47a12beSStefan Roese __asm__ __volatile__ ("sync"); 185a47a12beSStefan Roese *dummy = 0; /* Write the value to memory and increment MAD */ 186a47a12beSStefan Roese __asm__ __volatile__ ("sync"); 187a47a12beSStefan Roese while(((*mxmr & 0x3f) != ((i + 1) & 0x3f))); 188a47a12beSStefan Roese } 189a47a12beSStefan Roese 190a47a12beSStefan Roese /* Set the OP field in the MxMR to "normal" and the MAD field to 000000 */ 191a47a12beSStefan Roese *mxmr &= 0xCFFFFFC0; 192a47a12beSStefan Roese } 193a47a12beSStefan Roese 194a47a12beSStefan Roese 195a47a12beSStefan Roese int 19654841ab5SWolfgang Denk do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) 197a47a12beSStefan Roese { 198a47a12beSStefan Roese ulong msr; 199a47a12beSStefan Roese #ifndef MPC83xx_RESET 200a47a12beSStefan Roese ulong addr; 201a47a12beSStefan Roese #endif 202a47a12beSStefan Roese 203a47a12beSStefan Roese volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; 204a47a12beSStefan Roese 205a47a12beSStefan Roese puts("Resetting the board.\n"); 206a47a12beSStefan Roese 207a47a12beSStefan Roese #ifdef MPC83xx_RESET 208a47a12beSStefan Roese 209a47a12beSStefan Roese /* Interrupts and MMU off */ 210a47a12beSStefan Roese __asm__ __volatile__ ("mfmsr %0":"=r" (msr):); 211a47a12beSStefan Roese 212a47a12beSStefan Roese msr &= ~( MSR_EE | MSR_IR | MSR_DR); 213a47a12beSStefan Roese __asm__ __volatile__ ("mtmsr %0"::"r" (msr)); 214a47a12beSStefan Roese 215a47a12beSStefan Roese /* enable Reset Control Reg */ 216a47a12beSStefan Roese immap->reset.rpr = 0x52535445; 217a47a12beSStefan Roese __asm__ __volatile__ ("sync"); 218a47a12beSStefan Roese __asm__ __volatile__ ("isync"); 219a47a12beSStefan Roese 220a47a12beSStefan Roese /* confirm Reset Control Reg is enabled */ 221a47a12beSStefan Roese while(!((immap->reset.rcer) & RCER_CRE)); 222a47a12beSStefan Roese 223a47a12beSStefan Roese udelay(200); 224a47a12beSStefan Roese 225a47a12beSStefan Roese /* perform reset, only one bit */ 226a47a12beSStefan Roese immap->reset.rcr = RCR_SWHR; 227a47a12beSStefan Roese 228a47a12beSStefan Roese #else /* ! MPC83xx_RESET */ 229a47a12beSStefan Roese 230a47a12beSStefan Roese immap->reset.rmr = RMR_CSRE; /* Checkstop Reset enable */ 231a47a12beSStefan Roese 232a47a12beSStefan Roese /* Interrupts and MMU off */ 233a47a12beSStefan Roese __asm__ __volatile__ ("mfmsr %0":"=r" (msr):); 234a47a12beSStefan Roese 235a47a12beSStefan Roese msr &= ~(MSR_ME | MSR_EE | MSR_IR | MSR_DR); 236a47a12beSStefan Roese __asm__ __volatile__ ("mtmsr %0"::"r" (msr)); 237a47a12beSStefan Roese 238a47a12beSStefan Roese /* 239a47a12beSStefan Roese * Trying to execute the next instruction at a non-existing address 240a47a12beSStefan Roese * should cause a machine check, resulting in reset 241a47a12beSStefan Roese */ 242a47a12beSStefan Roese addr = CONFIG_SYS_RESET_ADDRESS; 243a47a12beSStefan Roese 244a47a12beSStefan Roese ((void (*)(void)) addr) (); 245a47a12beSStefan Roese #endif /* MPC83xx_RESET */ 246a47a12beSStefan Roese 247a47a12beSStefan Roese return 1; 248a47a12beSStefan Roese } 249a47a12beSStefan Roese 250a47a12beSStefan Roese 251a47a12beSStefan Roese /* 252a47a12beSStefan Roese * Get timebase clock frequency (like cpu_clk in Hz) 253a47a12beSStefan Roese */ 254a47a12beSStefan Roese 255a47a12beSStefan Roese unsigned long get_tbclk(void) 256a47a12beSStefan Roese { 257a47a12beSStefan Roese ulong tbclk; 258a47a12beSStefan Roese 259a47a12beSStefan Roese tbclk = (gd->bus_clk + 3L) / 4L; 260a47a12beSStefan Roese 261a47a12beSStefan Roese return tbclk; 262a47a12beSStefan Roese } 263a47a12beSStefan Roese 264a47a12beSStefan Roese 265a47a12beSStefan Roese #if defined(CONFIG_WATCHDOG) 266a47a12beSStefan Roese void watchdog_reset (void) 267a47a12beSStefan Roese { 268a47a12beSStefan Roese int re_enable = disable_interrupts(); 269a47a12beSStefan Roese 270a47a12beSStefan Roese /* Reset the 83xx watchdog */ 271a47a12beSStefan Roese volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR; 272a47a12beSStefan Roese immr->wdt.swsrr = 0x556c; 273a47a12beSStefan Roese immr->wdt.swsrr = 0xaa39; 274a47a12beSStefan Roese 275a47a12beSStefan Roese if (re_enable) 276a47a12beSStefan Roese enable_interrupts (); 277a47a12beSStefan Roese } 278a47a12beSStefan Roese #endif 279a47a12beSStefan Roese 280a47a12beSStefan Roese /* 281a47a12beSStefan Roese * Initializes on-chip ethernet controllers. 282a47a12beSStefan Roese * to override, implement board_eth_init() 283a47a12beSStefan Roese */ 284a47a12beSStefan Roese int cpu_eth_init(bd_t *bis) 285a47a12beSStefan Roese { 286a47a12beSStefan Roese #if defined(CONFIG_UEC_ETH) 287a47a12beSStefan Roese uec_standard_init(bis); 288a47a12beSStefan Roese #endif 289a47a12beSStefan Roese 290a47a12beSStefan Roese #if defined(CONFIG_TSEC_ENET) 291a47a12beSStefan Roese tsec_standard_init(bis); 292a47a12beSStefan Roese #endif 293a47a12beSStefan Roese return 0; 294a47a12beSStefan Roese } 295a47a12beSStefan Roese 296a47a12beSStefan Roese /* 297a47a12beSStefan Roese * Initializes on-chip MMC controllers. 298a47a12beSStefan Roese * to override, implement board_mmc_init() 299a47a12beSStefan Roese */ 300a47a12beSStefan Roese int cpu_mmc_init(bd_t *bis) 301a47a12beSStefan Roese { 302a47a12beSStefan Roese #ifdef CONFIG_FSL_ESDHC 303a47a12beSStefan Roese return fsl_esdhc_mmc_init(bis); 304a47a12beSStefan Roese #else 305a47a12beSStefan Roese return 0; 306a47a12beSStefan Roese #endif 307a47a12beSStefan Roese } 308