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> 13*ba3da734SChristophe 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 */ 22*ba3da734SChristophe Leroy void cpu_init_f(immap_t __iomem *immr) 23907208c4SChristophe Leroy { 24*ba3da734SChristophe Leroy memctl8xx_t __iomem *memctl = &immr->im_memctl; 25907208c4SChristophe Leroy ulong reg; 26907208c4SChristophe Leroy 27907208c4SChristophe Leroy /* SYPCR - contains watchdog control (11-9) */ 28907208c4SChristophe Leroy 29*ba3da734SChristophe 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) */ 36*ba3da734SChristophe 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 40*ba3da734SChristophe Leroy out_be32(&immr->im_sitk.sitk_tbscrk, KAPWR_KEY); 41*ba3da734SChristophe Leroy out_be16(&immr->im_sit.sit_tbscr, CONFIG_SYS_TBSCR); 42907208c4SChristophe Leroy 43907208c4SChristophe Leroy /* initialize the PIT (11-31) */ 44907208c4SChristophe Leroy 45*ba3da734SChristophe Leroy out_be32(&immr->im_sitk.sitk_piscrk, KAPWR_KEY); 46*ba3da734SChristophe 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 50*ba3da734SChristophe Leroy out_be32(&immr->im_clkrstk.cark_sccrk, KAPWR_KEY); 51*ba3da734SChristophe Leroy clrsetbits_be32(&immr->im_clkrst.car_sccr, ~SCCR_MASK, 52*ba3da734SChristophe Leroy CONFIG_SYS_SCCR); 53907208c4SChristophe Leroy 54907208c4SChristophe Leroy /* PLL (CPU clock) settings (15-30) */ 55907208c4SChristophe Leroy 56*ba3da734SChristophe Leroy out_be32(&immr->im_clkrstk.cark_plprcrk, KAPWR_KEY); 57907208c4SChristophe Leroy 58907208c4SChristophe Leroy /* If CONFIG_SYS_PLPRCR (set in the various *_config.h files) tries to 59907208c4SChristophe Leroy * set the MF field, then just copy CONFIG_SYS_PLPRCR over car_plprcr, 60907208c4SChristophe Leroy * otherwise OR in CONFIG_SYS_PLPRCR so we do not change the current MF 61907208c4SChristophe Leroy * field value. 62907208c4SChristophe Leroy * 63907208c4SChristophe Leroy * For newer (starting MPC866) chips PLPRCR layout is different. 64907208c4SChristophe Leroy */ 65907208c4SChristophe Leroy #ifdef CONFIG_SYS_PLPRCR 66*ba3da734SChristophe Leroy if ((CONFIG_SYS_PLPRCR & PLPRCR_MFACT_MSK) != 0) /* reset control bits*/ 67*ba3da734SChristophe Leroy out_be32(&immr->im_clkrst.car_plprcr, CONFIG_SYS_PLPRCR); 68*ba3da734SChristophe Leroy else /* isolate MF-related fields and reset control bits */ 69*ba3da734SChristophe Leroy clrsetbits_be32(&immr->im_clkrst.car_plprcr, ~PLPRCR_MFACT_MSK, 70*ba3da734SChristophe Leroy CONFIG_SYS_PLPRCR); 71907208c4SChristophe Leroy #endif 72907208c4SChristophe Leroy 73907208c4SChristophe Leroy /* 74907208c4SChristophe Leroy * Memory Controller: 75907208c4SChristophe Leroy */ 76907208c4SChristophe Leroy 77*ba3da734SChristophe Leroy /* Clear everything except Port Size bits & add the "Bank Valid" bit */ 78*ba3da734SChristophe Leroy clrsetbits_be32(&memctl->memc_br0, ~BR_PS_MSK, BR_V); 79907208c4SChristophe Leroy 80907208c4SChristophe Leroy /* Map banks 0 (and maybe 1) to the FLASH banks 0 (and 1) at 81907208c4SChristophe Leroy * preliminary addresses - these have to be modified later 82907208c4SChristophe Leroy * when FLASH size has been determined 83907208c4SChristophe Leroy * 84907208c4SChristophe Leroy * Depending on the size of the memory region defined by 85907208c4SChristophe Leroy * CONFIG_SYS_OR0_REMAP some boards (wide address mask) allow to map the 86907208c4SChristophe Leroy * CONFIG_SYS_MONITOR_BASE, while others (narrower address mask) can't 87907208c4SChristophe Leroy * map CONFIG_SYS_MONITOR_BASE. 88907208c4SChristophe Leroy * 89907208c4SChristophe Leroy * For example, for CONFIG_IVMS8, the CONFIG_SYS_MONITOR_BASE is 90907208c4SChristophe Leroy * 0xff000000, but CONFIG_SYS_OR0_REMAP's address mask is 0xfff80000. 91907208c4SChristophe Leroy * 92907208c4SChristophe Leroy * If BR0 wasn't loaded with address base 0xff000000, then BR0's 93907208c4SChristophe Leroy * base address remains as 0x00000000. However, the address mask 94907208c4SChristophe Leroy * have been narrowed to 512Kb, so CONFIG_SYS_MONITOR_BASE wasn't mapped 95907208c4SChristophe Leroy * into the Bank0. 96907208c4SChristophe Leroy * 97907208c4SChristophe Leroy * This is why CONFIG_IVMS8 and similar boards must load BR0 with 98907208c4SChristophe Leroy * CONFIG_SYS_BR0_PRELIM in advance. 99907208c4SChristophe Leroy * 100907208c4SChristophe Leroy * [Thanks to Michael Liao for this explanation. 101907208c4SChristophe Leroy * I owe him a free beer. - wd] 102907208c4SChristophe Leroy */ 103907208c4SChristophe Leroy 104907208c4SChristophe Leroy #if defined(CONFIG_SYS_OR0_REMAP) 105*ba3da734SChristophe Leroy out_be32(&memctl->memc_or0, CONFIG_SYS_OR0_REMAP); 106907208c4SChristophe Leroy #endif 107907208c4SChristophe Leroy #if defined(CONFIG_SYS_OR1_REMAP) 108*ba3da734SChristophe Leroy out_be32(&memctl->memc_or1, CONFIG_SYS_OR1_REMAP); 109907208c4SChristophe Leroy #endif 110907208c4SChristophe Leroy #if defined(CONFIG_SYS_OR5_REMAP) 111*ba3da734SChristophe Leroy out_be32(&memctl->memc_or5, CONFIG_SYS_OR5_REMAP); 112907208c4SChristophe Leroy #endif 113907208c4SChristophe Leroy 114907208c4SChristophe Leroy /* now restrict to preliminary range */ 115*ba3da734SChristophe Leroy out_be32(&memctl->memc_br0, CONFIG_SYS_BR0_PRELIM); 116*ba3da734SChristophe Leroy out_be32(&memctl->memc_or0, CONFIG_SYS_OR0_PRELIM); 117907208c4SChristophe Leroy 118907208c4SChristophe Leroy #if (defined(CONFIG_SYS_OR1_PRELIM) && defined(CONFIG_SYS_BR1_PRELIM)) 119*ba3da734SChristophe Leroy out_be32(&memctl->memc_or1, CONFIG_SYS_OR1_PRELIM); 120*ba3da734SChristophe Leroy out_be32(&memctl->memc_br1, CONFIG_SYS_BR1_PRELIM); 121907208c4SChristophe Leroy #endif 122907208c4SChristophe Leroy 123907208c4SChristophe Leroy #if defined(CONFIG_SYS_OR2_PRELIM) && defined(CONFIG_SYS_BR2_PRELIM) 124*ba3da734SChristophe Leroy out_be32(&memctl->memc_or2, CONFIG_SYS_OR2_PRELIM); 125*ba3da734SChristophe Leroy out_be32(&memctl->memc_br2, CONFIG_SYS_BR2_PRELIM); 126907208c4SChristophe Leroy #endif 127907208c4SChristophe Leroy 128907208c4SChristophe Leroy #if defined(CONFIG_SYS_OR3_PRELIM) && defined(CONFIG_SYS_BR3_PRELIM) 129*ba3da734SChristophe Leroy out_be32(&memctl->memc_or3, CONFIG_SYS_OR3_PRELIM); 130*ba3da734SChristophe Leroy out_be32(&memctl->memc_br3, CONFIG_SYS_BR3_PRELIM); 131907208c4SChristophe Leroy #endif 132907208c4SChristophe Leroy 133907208c4SChristophe Leroy #if defined(CONFIG_SYS_OR4_PRELIM) && defined(CONFIG_SYS_BR4_PRELIM) 134*ba3da734SChristophe Leroy out_be32(&memctl->memc_or4, CONFIG_SYS_OR4_PRELIM); 135*ba3da734SChristophe Leroy out_be32(&memctl->memc_br4, CONFIG_SYS_BR4_PRELIM); 136907208c4SChristophe Leroy #endif 137907208c4SChristophe Leroy 138907208c4SChristophe Leroy #if defined(CONFIG_SYS_OR5_PRELIM) && defined(CONFIG_SYS_BR5_PRELIM) 139*ba3da734SChristophe Leroy out_be32(&memctl->memc_or5, CONFIG_SYS_OR5_PRELIM); 140*ba3da734SChristophe Leroy out_be32(&memctl->memc_br5, CONFIG_SYS_BR5_PRELIM); 141907208c4SChristophe Leroy #endif 142907208c4SChristophe Leroy 143907208c4SChristophe Leroy #if defined(CONFIG_SYS_OR6_PRELIM) && defined(CONFIG_SYS_BR6_PRELIM) 144*ba3da734SChristophe Leroy out_be32(&memctl->memc_or6, CONFIG_SYS_OR6_PRELIM); 145*ba3da734SChristophe Leroy out_be32(&memctl->memc_br6, CONFIG_SYS_BR6_PRELIM); 146907208c4SChristophe Leroy #endif 147907208c4SChristophe Leroy 148907208c4SChristophe Leroy #if defined(CONFIG_SYS_OR7_PRELIM) && defined(CONFIG_SYS_BR7_PRELIM) 149*ba3da734SChristophe Leroy out_be32(&memctl->memc_or7, CONFIG_SYS_OR7_PRELIM); 150*ba3da734SChristophe Leroy out_be32(&memctl->memc_br7, CONFIG_SYS_BR7_PRELIM); 151907208c4SChristophe Leroy #endif 152907208c4SChristophe Leroy 153907208c4SChristophe Leroy /* 154907208c4SChristophe Leroy * Reset CPM 155907208c4SChristophe Leroy */ 156*ba3da734SChristophe Leroy out_be16(&immr->im_cpm.cp_cpcr, CPM_CR_RST | CPM_CR_FLG); 157*ba3da734SChristophe Leroy /* Spin until command processed */ 158*ba3da734SChristophe Leroy while (in_be16(&immr->im_cpm.cp_cpcr) & CPM_CR_FLG) 159*ba3da734SChristophe Leroy ; 160907208c4SChristophe Leroy } 161907208c4SChristophe Leroy 162907208c4SChristophe Leroy /* 163907208c4SChristophe Leroy * initialize higher level parts of CPU like timers 164907208c4SChristophe Leroy */ 165907208c4SChristophe Leroy int cpu_init_r (void) 166907208c4SChristophe Leroy { 167907208c4SChristophe Leroy return (0); 168907208c4SChristophe Leroy } 169