1907208c4SChristophe Leroy /* 2907208c4SChristophe Leroy * (C) Copyright 2000-2002 3907208c4SChristophe Leroy * Wolfgang Denk, DENX Software Engineering, wd@denx.de. 4907208c4SChristophe Leroy * 5907208c4SChristophe Leroy * SPDX-License-Identifier: GPL-2.0+ 6907208c4SChristophe Leroy */ 7907208c4SChristophe Leroy 8907208c4SChristophe Leroy #include <common.h> 9907208c4SChristophe Leroy #include <watchdog.h> 10907208c4SChristophe Leroy 11907208c4SChristophe Leroy #include <mpc8xx.h> 12907208c4SChristophe Leroy #include <commproc.h> 13ba3da734SChristophe Leroy #include <asm/io.h> 14907208c4SChristophe Leroy 15907208c4SChristophe Leroy /* 16907208c4SChristophe Leroy * Breath some life into the CPU... 17907208c4SChristophe Leroy * 18907208c4SChristophe Leroy * Set up the memory map, 19907208c4SChristophe Leroy * initialize a bunch of registers, 20907208c4SChristophe Leroy * initialize the UPM's 21907208c4SChristophe Leroy */ 22ba3da734SChristophe Leroy void cpu_init_f(immap_t __iomem *immr) 23907208c4SChristophe Leroy { 24ba3da734SChristophe Leroy memctl8xx_t __iomem *memctl = &immr->im_memctl; 25907208c4SChristophe Leroy ulong reg; 26907208c4SChristophe Leroy 27907208c4SChristophe Leroy /* SYPCR - contains watchdog control (11-9) */ 28907208c4SChristophe Leroy 29ba3da734SChristophe Leroy out_be32(&immr->im_siu_conf.sc_sypcr, CONFIG_SYS_SYPCR); 30907208c4SChristophe Leroy 31907208c4SChristophe Leroy #if defined(CONFIG_WATCHDOG) 32907208c4SChristophe Leroy reset_8xx_watchdog (immr); 33907208c4SChristophe Leroy #endif /* CONFIG_WATCHDOG */ 34907208c4SChristophe Leroy 35907208c4SChristophe Leroy /* SIUMCR - contains debug pin configuration (11-6) */ 36ba3da734SChristophe Leroy setbits_be32(&immr->im_siu_conf.sc_siumcr, CONFIG_SYS_SIUMCR); 37907208c4SChristophe Leroy /* initialize timebase status and control register (11-26) */ 38907208c4SChristophe Leroy /* unlock TBSCRK */ 39907208c4SChristophe Leroy 40ba3da734SChristophe Leroy out_be32(&immr->im_sitk.sitk_tbscrk, KAPWR_KEY); 41ba3da734SChristophe Leroy out_be16(&immr->im_sit.sit_tbscr, CONFIG_SYS_TBSCR); 42907208c4SChristophe Leroy 43907208c4SChristophe Leroy /* initialize the PIT (11-31) */ 44907208c4SChristophe Leroy 45ba3da734SChristophe Leroy out_be32(&immr->im_sitk.sitk_piscrk, KAPWR_KEY); 46ba3da734SChristophe Leroy out_be16(&immr->im_sit.sit_piscr, CONFIG_SYS_PISCR); 47907208c4SChristophe Leroy 48907208c4SChristophe Leroy /* System integration timers. Don't change EBDF! (15-27) */ 49907208c4SChristophe Leroy 50ba3da734SChristophe Leroy out_be32(&immr->im_clkrstk.cark_sccrk, KAPWR_KEY); 51ba3da734SChristophe Leroy clrsetbits_be32(&immr->im_clkrst.car_sccr, ~SCCR_MASK, 52ba3da734SChristophe Leroy CONFIG_SYS_SCCR); 53907208c4SChristophe Leroy 54*73bc94c6SChristophe Leroy /* 55*73bc94c6SChristophe Leroy * MPC866/885 ERRATA GLL2 56*73bc94c6SChristophe Leroy * Description: 57*73bc94c6SChristophe Leroy * In 1:2:1 mode, when HRESET is detected at the positive edge of 58*73bc94c6SChristophe Leroy * EXTCLK, then there will be a loss of phase between 59*73bc94c6SChristophe Leroy * EXTCLK and CLKOUT. 60*73bc94c6SChristophe Leroy * 61*73bc94c6SChristophe Leroy * Workaround: 62*73bc94c6SChristophe Leroy * Reprogram the SCCR: 63*73bc94c6SChristophe Leroy * 1. Write 1'b00 to SCCR[EBDF]. 64*73bc94c6SChristophe Leroy * 2. Write 1'b01 to SCCR[EBDF]. 65*73bc94c6SChristophe Leroy * 3. Rewrite the desired value to the PLPRCR register. 66*73bc94c6SChristophe Leroy */ 67*73bc94c6SChristophe Leroy reg = in_be32(&immr->im_clkrst.car_sccr); 68*73bc94c6SChristophe Leroy /* Are we in mode 1:2:1 ? */ 69*73bc94c6SChristophe Leroy if ((reg & SCCR_EBDF11) == SCCR_EBDF01) { 70*73bc94c6SChristophe Leroy clrbits_be32(&immr->im_clkrst.car_sccr, SCCR_EBDF11); 71*73bc94c6SChristophe Leroy setbits_be32(&immr->im_clkrst.car_sccr, SCCR_EBDF01); 72*73bc94c6SChristophe Leroy } 73*73bc94c6SChristophe Leroy 74907208c4SChristophe Leroy /* PLL (CPU clock) settings (15-30) */ 75907208c4SChristophe Leroy 76ba3da734SChristophe Leroy out_be32(&immr->im_clkrstk.cark_plprcrk, KAPWR_KEY); 77907208c4SChristophe Leroy 78907208c4SChristophe Leroy /* If CONFIG_SYS_PLPRCR (set in the various *_config.h files) tries to 79907208c4SChristophe Leroy * set the MF field, then just copy CONFIG_SYS_PLPRCR over car_plprcr, 80907208c4SChristophe Leroy * otherwise OR in CONFIG_SYS_PLPRCR so we do not change the current MF 81907208c4SChristophe Leroy * field value. 82907208c4SChristophe Leroy * 83907208c4SChristophe Leroy * For newer (starting MPC866) chips PLPRCR layout is different. 84907208c4SChristophe Leroy */ 85907208c4SChristophe Leroy #ifdef CONFIG_SYS_PLPRCR 86ba3da734SChristophe Leroy if ((CONFIG_SYS_PLPRCR & PLPRCR_MFACT_MSK) != 0) /* reset control bits*/ 87ba3da734SChristophe Leroy out_be32(&immr->im_clkrst.car_plprcr, CONFIG_SYS_PLPRCR); 88ba3da734SChristophe Leroy else /* isolate MF-related fields and reset control bits */ 89ba3da734SChristophe Leroy clrsetbits_be32(&immr->im_clkrst.car_plprcr, ~PLPRCR_MFACT_MSK, 90ba3da734SChristophe Leroy CONFIG_SYS_PLPRCR); 91907208c4SChristophe Leroy #endif 92907208c4SChristophe Leroy 93907208c4SChristophe Leroy /* 94907208c4SChristophe Leroy * Memory Controller: 95907208c4SChristophe Leroy */ 96907208c4SChristophe Leroy 97ba3da734SChristophe Leroy /* Clear everything except Port Size bits & add the "Bank Valid" bit */ 98ba3da734SChristophe Leroy clrsetbits_be32(&memctl->memc_br0, ~BR_PS_MSK, BR_V); 99907208c4SChristophe Leroy 100907208c4SChristophe Leroy /* Map banks 0 (and maybe 1) to the FLASH banks 0 (and 1) at 101907208c4SChristophe Leroy * preliminary addresses - these have to be modified later 102907208c4SChristophe Leroy * when FLASH size has been determined 103907208c4SChristophe Leroy * 104907208c4SChristophe Leroy * Depending on the size of the memory region defined by 105907208c4SChristophe Leroy * CONFIG_SYS_OR0_REMAP some boards (wide address mask) allow to map the 106907208c4SChristophe Leroy * CONFIG_SYS_MONITOR_BASE, while others (narrower address mask) can't 107907208c4SChristophe Leroy * map CONFIG_SYS_MONITOR_BASE. 108907208c4SChristophe Leroy * 109907208c4SChristophe Leroy * For example, for CONFIG_IVMS8, the CONFIG_SYS_MONITOR_BASE is 110907208c4SChristophe Leroy * 0xff000000, but CONFIG_SYS_OR0_REMAP's address mask is 0xfff80000. 111907208c4SChristophe Leroy * 112907208c4SChristophe Leroy * If BR0 wasn't loaded with address base 0xff000000, then BR0's 113907208c4SChristophe Leroy * base address remains as 0x00000000. However, the address mask 114907208c4SChristophe Leroy * have been narrowed to 512Kb, so CONFIG_SYS_MONITOR_BASE wasn't mapped 115907208c4SChristophe Leroy * into the Bank0. 116907208c4SChristophe Leroy * 117907208c4SChristophe Leroy * This is why CONFIG_IVMS8 and similar boards must load BR0 with 118907208c4SChristophe Leroy * CONFIG_SYS_BR0_PRELIM in advance. 119907208c4SChristophe Leroy * 120907208c4SChristophe Leroy * [Thanks to Michael Liao for this explanation. 121907208c4SChristophe Leroy * I owe him a free beer. - wd] 122907208c4SChristophe Leroy */ 123907208c4SChristophe Leroy 124907208c4SChristophe Leroy #if defined(CONFIG_SYS_OR0_REMAP) 125ba3da734SChristophe Leroy out_be32(&memctl->memc_or0, CONFIG_SYS_OR0_REMAP); 126907208c4SChristophe Leroy #endif 127907208c4SChristophe Leroy #if defined(CONFIG_SYS_OR1_REMAP) 128ba3da734SChristophe Leroy out_be32(&memctl->memc_or1, CONFIG_SYS_OR1_REMAP); 129907208c4SChristophe Leroy #endif 130907208c4SChristophe Leroy #if defined(CONFIG_SYS_OR5_REMAP) 131ba3da734SChristophe Leroy out_be32(&memctl->memc_or5, CONFIG_SYS_OR5_REMAP); 132907208c4SChristophe Leroy #endif 133907208c4SChristophe Leroy 134907208c4SChristophe Leroy /* now restrict to preliminary range */ 135ba3da734SChristophe Leroy out_be32(&memctl->memc_br0, CONFIG_SYS_BR0_PRELIM); 136ba3da734SChristophe Leroy out_be32(&memctl->memc_or0, CONFIG_SYS_OR0_PRELIM); 137907208c4SChristophe Leroy 138907208c4SChristophe Leroy #if (defined(CONFIG_SYS_OR1_PRELIM) && defined(CONFIG_SYS_BR1_PRELIM)) 139ba3da734SChristophe Leroy out_be32(&memctl->memc_or1, CONFIG_SYS_OR1_PRELIM); 140ba3da734SChristophe Leroy out_be32(&memctl->memc_br1, CONFIG_SYS_BR1_PRELIM); 141907208c4SChristophe Leroy #endif 142907208c4SChristophe Leroy 143907208c4SChristophe Leroy #if defined(CONFIG_SYS_OR2_PRELIM) && defined(CONFIG_SYS_BR2_PRELIM) 144ba3da734SChristophe Leroy out_be32(&memctl->memc_or2, CONFIG_SYS_OR2_PRELIM); 145ba3da734SChristophe Leroy out_be32(&memctl->memc_br2, CONFIG_SYS_BR2_PRELIM); 146907208c4SChristophe Leroy #endif 147907208c4SChristophe Leroy 148907208c4SChristophe Leroy #if defined(CONFIG_SYS_OR3_PRELIM) && defined(CONFIG_SYS_BR3_PRELIM) 149ba3da734SChristophe Leroy out_be32(&memctl->memc_or3, CONFIG_SYS_OR3_PRELIM); 150ba3da734SChristophe Leroy out_be32(&memctl->memc_br3, CONFIG_SYS_BR3_PRELIM); 151907208c4SChristophe Leroy #endif 152907208c4SChristophe Leroy 153907208c4SChristophe Leroy #if defined(CONFIG_SYS_OR4_PRELIM) && defined(CONFIG_SYS_BR4_PRELIM) 154ba3da734SChristophe Leroy out_be32(&memctl->memc_or4, CONFIG_SYS_OR4_PRELIM); 155ba3da734SChristophe Leroy out_be32(&memctl->memc_br4, CONFIG_SYS_BR4_PRELIM); 156907208c4SChristophe Leroy #endif 157907208c4SChristophe Leroy 158907208c4SChristophe Leroy #if defined(CONFIG_SYS_OR5_PRELIM) && defined(CONFIG_SYS_BR5_PRELIM) 159ba3da734SChristophe Leroy out_be32(&memctl->memc_or5, CONFIG_SYS_OR5_PRELIM); 160ba3da734SChristophe Leroy out_be32(&memctl->memc_br5, CONFIG_SYS_BR5_PRELIM); 161907208c4SChristophe Leroy #endif 162907208c4SChristophe Leroy 163907208c4SChristophe Leroy #if defined(CONFIG_SYS_OR6_PRELIM) && defined(CONFIG_SYS_BR6_PRELIM) 164ba3da734SChristophe Leroy out_be32(&memctl->memc_or6, CONFIG_SYS_OR6_PRELIM); 165ba3da734SChristophe Leroy out_be32(&memctl->memc_br6, CONFIG_SYS_BR6_PRELIM); 166907208c4SChristophe Leroy #endif 167907208c4SChristophe Leroy 168907208c4SChristophe Leroy #if defined(CONFIG_SYS_OR7_PRELIM) && defined(CONFIG_SYS_BR7_PRELIM) 169ba3da734SChristophe Leroy out_be32(&memctl->memc_or7, CONFIG_SYS_OR7_PRELIM); 170ba3da734SChristophe Leroy out_be32(&memctl->memc_br7, CONFIG_SYS_BR7_PRELIM); 171907208c4SChristophe Leroy #endif 172907208c4SChristophe Leroy 173907208c4SChristophe Leroy /* 174907208c4SChristophe Leroy * Reset CPM 175907208c4SChristophe Leroy */ 176ba3da734SChristophe Leroy out_be16(&immr->im_cpm.cp_cpcr, CPM_CR_RST | CPM_CR_FLG); 177ba3da734SChristophe Leroy /* Spin until command processed */ 178ba3da734SChristophe Leroy while (in_be16(&immr->im_cpm.cp_cpcr) & CPM_CR_FLG) 179ba3da734SChristophe Leroy ; 180907208c4SChristophe Leroy } 181907208c4SChristophe Leroy 182907208c4SChristophe Leroy /* 183907208c4SChristophe Leroy * initialize higher level parts of CPU like timers 184907208c4SChristophe Leroy */ 185907208c4SChristophe Leroy int cpu_init_r (void) 186907208c4SChristophe Leroy { 187907208c4SChristophe Leroy return (0); 188907208c4SChristophe Leroy } 189