1*a47a12beSStefan Roese /* 2*a47a12beSStefan Roese * Copyright 2004,2009 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 /* 26*a47a12beSStefan Roese * cpu_init.c - low level cpu init 27*a47a12beSStefan Roese */ 28*a47a12beSStefan Roese 29*a47a12beSStefan Roese #include <config.h> 30*a47a12beSStefan Roese #include <common.h> 31*a47a12beSStefan Roese #include <mpc86xx.h> 32*a47a12beSStefan Roese #include <asm/mmu.h> 33*a47a12beSStefan Roese #include <asm/fsl_law.h> 34*a47a12beSStefan Roese #include <asm/mp.h> 35*a47a12beSStefan Roese 36*a47a12beSStefan Roese void setup_bats(void); 37*a47a12beSStefan Roese 38*a47a12beSStefan Roese DECLARE_GLOBAL_DATA_PTR; 39*a47a12beSStefan Roese 40*a47a12beSStefan Roese /* 41*a47a12beSStefan Roese * Breathe some life into the CPU... 42*a47a12beSStefan Roese * 43*a47a12beSStefan Roese * Set up the memory map 44*a47a12beSStefan Roese * initialize a bunch of registers 45*a47a12beSStefan Roese */ 46*a47a12beSStefan Roese 47*a47a12beSStefan Roese void cpu_init_f(void) 48*a47a12beSStefan Roese { 49*a47a12beSStefan Roese volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; 50*a47a12beSStefan Roese volatile ccsr_lbc_t *memctl = &immap->im_lbc; 51*a47a12beSStefan Roese 52*a47a12beSStefan Roese /* Pointer is writable since we allocated a register for it */ 53*a47a12beSStefan Roese gd = (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET); 54*a47a12beSStefan Roese 55*a47a12beSStefan Roese /* Clear initial global data */ 56*a47a12beSStefan Roese memset ((void *) gd, 0, sizeof (gd_t)); 57*a47a12beSStefan Roese 58*a47a12beSStefan Roese #ifdef CONFIG_FSL_LAW 59*a47a12beSStefan Roese init_laws(); 60*a47a12beSStefan Roese #endif 61*a47a12beSStefan Roese 62*a47a12beSStefan Roese setup_bats(); 63*a47a12beSStefan Roese 64*a47a12beSStefan Roese /* Map banks 0 and 1 to the FLASH banks 0 and 1 at preliminary 65*a47a12beSStefan Roese * addresses - these have to be modified later when FLASH size 66*a47a12beSStefan Roese * has been determined 67*a47a12beSStefan Roese */ 68*a47a12beSStefan Roese 69*a47a12beSStefan Roese #if defined(CONFIG_SYS_OR0_REMAP) 70*a47a12beSStefan Roese memctl->or0 = CONFIG_SYS_OR0_REMAP; 71*a47a12beSStefan Roese #endif 72*a47a12beSStefan Roese #if defined(CONFIG_SYS_OR1_REMAP) 73*a47a12beSStefan Roese memctl->or1 = CONFIG_SYS_OR1_REMAP; 74*a47a12beSStefan Roese #endif 75*a47a12beSStefan Roese 76*a47a12beSStefan Roese /* now restrict to preliminary range */ 77*a47a12beSStefan Roese #if defined(CONFIG_SYS_BR0_PRELIM) && defined(CONFIG_SYS_OR0_PRELIM) 78*a47a12beSStefan Roese memctl->br0 = CONFIG_SYS_BR0_PRELIM; 79*a47a12beSStefan Roese memctl->or0 = CONFIG_SYS_OR0_PRELIM; 80*a47a12beSStefan Roese #endif 81*a47a12beSStefan Roese 82*a47a12beSStefan Roese #if defined(CONFIG_SYS_BR1_PRELIM) && defined(CONFIG_SYS_OR1_PRELIM) 83*a47a12beSStefan Roese memctl->or1 = CONFIG_SYS_OR1_PRELIM; 84*a47a12beSStefan Roese memctl->br1 = CONFIG_SYS_BR1_PRELIM; 85*a47a12beSStefan Roese #endif 86*a47a12beSStefan Roese 87*a47a12beSStefan Roese #if defined(CONFIG_SYS_BR2_PRELIM) && defined(CONFIG_SYS_OR2_PRELIM) 88*a47a12beSStefan Roese memctl->or2 = CONFIG_SYS_OR2_PRELIM; 89*a47a12beSStefan Roese memctl->br2 = CONFIG_SYS_BR2_PRELIM; 90*a47a12beSStefan Roese #endif 91*a47a12beSStefan Roese 92*a47a12beSStefan Roese #if defined(CONFIG_SYS_BR3_PRELIM) && defined(CONFIG_SYS_OR3_PRELIM) 93*a47a12beSStefan Roese memctl->or3 = CONFIG_SYS_OR3_PRELIM; 94*a47a12beSStefan Roese memctl->br3 = CONFIG_SYS_BR3_PRELIM; 95*a47a12beSStefan Roese #endif 96*a47a12beSStefan Roese 97*a47a12beSStefan Roese #if defined(CONFIG_SYS_BR4_PRELIM) && defined(CONFIG_SYS_OR4_PRELIM) 98*a47a12beSStefan Roese memctl->or4 = CONFIG_SYS_OR4_PRELIM; 99*a47a12beSStefan Roese memctl->br4 = CONFIG_SYS_BR4_PRELIM; 100*a47a12beSStefan Roese #endif 101*a47a12beSStefan Roese 102*a47a12beSStefan Roese #if defined(CONFIG_SYS_BR5_PRELIM) && defined(CONFIG_SYS_OR5_PRELIM) 103*a47a12beSStefan Roese memctl->or5 = CONFIG_SYS_OR5_PRELIM; 104*a47a12beSStefan Roese memctl->br5 = CONFIG_SYS_BR5_PRELIM; 105*a47a12beSStefan Roese #endif 106*a47a12beSStefan Roese 107*a47a12beSStefan Roese #if defined(CONFIG_SYS_BR6_PRELIM) && defined(CONFIG_SYS_OR6_PRELIM) 108*a47a12beSStefan Roese memctl->or6 = CONFIG_SYS_OR6_PRELIM; 109*a47a12beSStefan Roese memctl->br6 = CONFIG_SYS_BR6_PRELIM; 110*a47a12beSStefan Roese #endif 111*a47a12beSStefan Roese 112*a47a12beSStefan Roese #if defined(CONFIG_SYS_BR7_PRELIM) && defined(CONFIG_SYS_OR7_PRELIM) 113*a47a12beSStefan Roese memctl->or7 = CONFIG_SYS_OR7_PRELIM; 114*a47a12beSStefan Roese memctl->br7 = CONFIG_SYS_BR7_PRELIM; 115*a47a12beSStefan Roese #endif 116*a47a12beSStefan Roese #if defined(CONFIG_FSL_DMA) 117*a47a12beSStefan Roese dma_init(); 118*a47a12beSStefan Roese #endif 119*a47a12beSStefan Roese 120*a47a12beSStefan Roese /* enable the timebase bit in HID0 */ 121*a47a12beSStefan Roese set_hid0(get_hid0() | 0x4000000); 122*a47a12beSStefan Roese 123*a47a12beSStefan Roese /* enable EMCP, SYNCBE | ABE bits in HID1 */ 124*a47a12beSStefan Roese set_hid1(get_hid1() | 0x80000C00); 125*a47a12beSStefan Roese } 126*a47a12beSStefan Roese 127*a47a12beSStefan Roese /* 128*a47a12beSStefan Roese * initialize higher level parts of CPU like timers 129*a47a12beSStefan Roese */ 130*a47a12beSStefan Roese int cpu_init_r(void) 131*a47a12beSStefan Roese { 132*a47a12beSStefan Roese #if defined(CONFIG_MP) 133*a47a12beSStefan Roese setup_mp(); 134*a47a12beSStefan Roese #endif 135*a47a12beSStefan Roese return 0; 136*a47a12beSStefan Roese } 137*a47a12beSStefan Roese 138*a47a12beSStefan Roese /* Set up BAT registers */ 139*a47a12beSStefan Roese void setup_bats(void) 140*a47a12beSStefan Roese { 141*a47a12beSStefan Roese #if defined(CONFIG_SYS_DBAT0U) && defined(CONFIG_SYS_DBAT0L) 142*a47a12beSStefan Roese write_bat(DBAT0, CONFIG_SYS_DBAT0U, CONFIG_SYS_DBAT0L); 143*a47a12beSStefan Roese #endif 144*a47a12beSStefan Roese #if defined(CONFIG_SYS_IBAT0U) && defined(CONFIG_SYS_IBAT0L) 145*a47a12beSStefan Roese write_bat(IBAT0, CONFIG_SYS_IBAT0U, CONFIG_SYS_IBAT0L); 146*a47a12beSStefan Roese #endif 147*a47a12beSStefan Roese write_bat(DBAT1, CONFIG_SYS_DBAT1U, CONFIG_SYS_DBAT1L); 148*a47a12beSStefan Roese write_bat(IBAT1, CONFIG_SYS_IBAT1U, CONFIG_SYS_IBAT1L); 149*a47a12beSStefan Roese write_bat(DBAT2, CONFIG_SYS_DBAT2U, CONFIG_SYS_DBAT2L); 150*a47a12beSStefan Roese write_bat(IBAT2, CONFIG_SYS_IBAT2U, CONFIG_SYS_IBAT2L); 151*a47a12beSStefan Roese write_bat(DBAT3, CONFIG_SYS_DBAT3U, CONFIG_SYS_DBAT3L); 152*a47a12beSStefan Roese write_bat(IBAT3, CONFIG_SYS_IBAT3U, CONFIG_SYS_IBAT3L); 153*a47a12beSStefan Roese write_bat(DBAT4, CONFIG_SYS_DBAT4U, CONFIG_SYS_DBAT4L); 154*a47a12beSStefan Roese write_bat(IBAT4, CONFIG_SYS_IBAT4U, CONFIG_SYS_IBAT4L); 155*a47a12beSStefan Roese write_bat(DBAT5, CONFIG_SYS_DBAT5U, CONFIG_SYS_DBAT5L); 156*a47a12beSStefan Roese write_bat(IBAT5, CONFIG_SYS_IBAT5U, CONFIG_SYS_IBAT5L); 157*a47a12beSStefan Roese write_bat(DBAT6, CONFIG_SYS_DBAT6U, CONFIG_SYS_DBAT6L); 158*a47a12beSStefan Roese write_bat(IBAT6, CONFIG_SYS_IBAT6U, CONFIG_SYS_IBAT6L); 159*a47a12beSStefan Roese write_bat(DBAT7, CONFIG_SYS_DBAT7U, CONFIG_SYS_DBAT7L); 160*a47a12beSStefan Roese write_bat(IBAT7, CONFIG_SYS_IBAT7U, CONFIG_SYS_IBAT7L); 161*a47a12beSStefan Roese 162*a47a12beSStefan Roese return; 163*a47a12beSStefan Roese } 164*a47a12beSStefan Roese 165*a47a12beSStefan Roese #ifdef CONFIG_ADDR_MAP 166*a47a12beSStefan Roese /* Initialize address mapping array */ 167*a47a12beSStefan Roese void init_addr_map(void) 168*a47a12beSStefan Roese { 169*a47a12beSStefan Roese int i; 170*a47a12beSStefan Roese ppc_bat_t bat = DBAT0; 171*a47a12beSStefan Roese phys_size_t size; 172*a47a12beSStefan Roese unsigned long upper, lower; 173*a47a12beSStefan Roese 174*a47a12beSStefan Roese for (i = 0; i < CONFIG_SYS_NUM_ADDR_MAP; i++, bat++) { 175*a47a12beSStefan Roese if (read_bat(bat, &upper, &lower) != -1) { 176*a47a12beSStefan Roese if (!BATU_VALID(upper)) 177*a47a12beSStefan Roese size = 0; 178*a47a12beSStefan Roese else 179*a47a12beSStefan Roese size = BATU_SIZE(upper); 180*a47a12beSStefan Roese addrmap_set_entry(BATU_VADDR(upper), BATL_PADDR(lower), 181*a47a12beSStefan Roese size, i); 182*a47a12beSStefan Roese } 183*a47a12beSStefan Roese #ifdef CONFIG_HIGH_BATS 184*a47a12beSStefan Roese /* High bats are not contiguous with low BAT numbers */ 185*a47a12beSStefan Roese if (bat == DBAT3) 186*a47a12beSStefan Roese bat = DBAT4 - 1; 187*a47a12beSStefan Roese #endif 188*a47a12beSStefan Roese } 189*a47a12beSStefan Roese } 190*a47a12beSStefan Roese #endif 191