1a47a12beSStefan Roese /* 2a09b9b68SKumar Gala * Copyright 2007-2011 Freescale Semiconductor, Inc. 3a47a12beSStefan Roese * 4a47a12beSStefan Roese * (C) Copyright 2003 Motorola Inc. 5a47a12beSStefan Roese * Modified by Xianghua Xiao, X.Xiao@motorola.com 6a47a12beSStefan Roese * 7a47a12beSStefan Roese * (C) Copyright 2000 8a47a12beSStefan Roese * Wolfgang Denk, DENX Software Engineering, wd@denx.de. 9a47a12beSStefan Roese * 101a459660SWolfgang Denk * SPDX-License-Identifier: GPL-2.0+ 11a47a12beSStefan Roese */ 12a47a12beSStefan Roese 13a47a12beSStefan Roese #include <common.h> 14a47a12beSStefan Roese #include <watchdog.h> 15a47a12beSStefan Roese #include <asm/processor.h> 16a47a12beSStefan Roese #include <ioports.h> 17f54fe87aSKumar Gala #include <sata.h> 18c916d7c9SKumar Gala #include <fm_eth.h> 19a47a12beSStefan Roese #include <asm/io.h> 20fd3c9befSKumar Gala #include <asm/cache.h> 21a47a12beSStefan Roese #include <asm/mmu.h> 22133fbfa9SYork Sun #include <asm/fsl_errata.h> 23a47a12beSStefan Roese #include <asm/fsl_law.h> 24f54fe87aSKumar Gala #include <asm/fsl_serdes.h> 255ffa88ecSLiu Gang #include <asm/fsl_srio.h> 269dee205dSramneek mehresh #include <fsl_usb.h> 2757125f22SYork Sun #include <hwconfig.h> 28fbc20aabSTimur Tabi #include <linux/compiler.h> 29a47a12beSStefan Roese #include "mp.h" 30f2717b47STimur Tabi #ifdef CONFIG_SYS_QE_FMAN_FW_IN_NAND 31a7b1e1b7SHaiying Wang #include <nand.h> 32a7b1e1b7SHaiying Wang #include <errno.h> 33a7b1e1b7SHaiying Wang #endif 34a47a12beSStefan Roese 35fbc20aabSTimur Tabi #include "../../../../drivers/block/fsl_sata.h" 362a44efebSZhao Qiang #ifdef CONFIG_U_QE 372a44efebSZhao Qiang #include "../../../../drivers/qe/qe.h" 382a44efebSZhao Qiang #endif 39fbc20aabSTimur Tabi 40a47a12beSStefan Roese DECLARE_GLOBAL_DATA_PTR; 41a47a12beSStefan Roese 42d1c561cdSNikhil Badola #ifdef CONFIG_SYS_FSL_SINGLE_SOURCE_CLK 43d1c561cdSNikhil Badola /* 44d1c561cdSNikhil Badola * For deriving usb clock from 100MHz sysclk, reference divisor is set 45d1c561cdSNikhil Badola * to a value of 5, which gives an intermediate value 20(100/5). The 46d1c561cdSNikhil Badola * multiplication factor integer is set to 24, which when multiplied to 47d1c561cdSNikhil Badola * above intermediate value provides clock for usb ip. 48d1c561cdSNikhil Badola */ 49d1c561cdSNikhil Badola void usb_single_source_clk_configure(struct ccsr_usb_phy *usb_phy) 50d1c561cdSNikhil Badola { 51d1c561cdSNikhil Badola sys_info_t sysinfo; 52d1c561cdSNikhil Badola 53d1c561cdSNikhil Badola get_sys_info(&sysinfo); 54d1c561cdSNikhil Badola if (sysinfo.diff_sysclk == 1) { 55d1c561cdSNikhil Badola clrbits_be32(&usb_phy->pllprg[1], 56d1c561cdSNikhil Badola CONFIG_SYS_FSL_USB_PLLPRG2_MFI); 57d1c561cdSNikhil Badola setbits_be32(&usb_phy->pllprg[1], 58d1c561cdSNikhil Badola CONFIG_SYS_FSL_USB_PLLPRG2_REF_DIV_INTERNAL_CLK | 59d1c561cdSNikhil Badola CONFIG_SYS_FSL_USB_PLLPRG2_MFI_INTERNAL_CLK | 60d1c561cdSNikhil Badola CONFIG_SYS_FSL_USB_INTERNAL_SOC_CLK_EN); 61d1c561cdSNikhil Badola } 62d1c561cdSNikhil Badola } 63d1c561cdSNikhil Badola #endif 64d1c561cdSNikhil Badola 659c641a87SSuresh Gupta #ifdef CONFIG_SYS_FSL_ERRATUM_A006261 669c641a87SSuresh Gupta void fsl_erratum_a006261_workaround(struct ccsr_usb_phy __iomem *usb_phy) 679c641a87SSuresh Gupta { 689c641a87SSuresh Gupta #ifdef CONFIG_SYS_FSL_USB_DUAL_PHY_ENABLE 699c641a87SSuresh Gupta u32 xcvrprg = in_be32(&usb_phy->port1.xcvrprg); 709c641a87SSuresh Gupta 719c641a87SSuresh Gupta /* Increase Disconnect Threshold by 50mV */ 729c641a87SSuresh Gupta xcvrprg &= ~CONFIG_SYS_FSL_USB_XCVRPRG_HS_DCNT_PROG_MASK | 739c641a87SSuresh Gupta INC_DCNT_THRESHOLD_50MV; 749c641a87SSuresh Gupta /* Enable programming of USB High speed Disconnect threshold */ 759c641a87SSuresh Gupta xcvrprg |= CONFIG_SYS_FSL_USB_XCVRPRG_HS_DCNT_PROG_EN; 769c641a87SSuresh Gupta out_be32(&usb_phy->port1.xcvrprg, xcvrprg); 779c641a87SSuresh Gupta 789c641a87SSuresh Gupta xcvrprg = in_be32(&usb_phy->port2.xcvrprg); 799c641a87SSuresh Gupta /* Increase Disconnect Threshold by 50mV */ 809c641a87SSuresh Gupta xcvrprg &= ~CONFIG_SYS_FSL_USB_XCVRPRG_HS_DCNT_PROG_MASK | 819c641a87SSuresh Gupta INC_DCNT_THRESHOLD_50MV; 829c641a87SSuresh Gupta /* Enable programming of USB High speed Disconnect threshold */ 839c641a87SSuresh Gupta xcvrprg |= CONFIG_SYS_FSL_USB_XCVRPRG_HS_DCNT_PROG_EN; 849c641a87SSuresh Gupta out_be32(&usb_phy->port2.xcvrprg, xcvrprg); 859c641a87SSuresh Gupta #else 869c641a87SSuresh Gupta 879c641a87SSuresh Gupta u32 temp = 0; 889c641a87SSuresh Gupta u32 status = in_be32(&usb_phy->status1); 899c641a87SSuresh Gupta 909c641a87SSuresh Gupta u32 squelch_prog_rd_0_2 = 919c641a87SSuresh Gupta (status >> CONFIG_SYS_FSL_USB_SQUELCH_PROG_RD_0) 929c641a87SSuresh Gupta & CONFIG_SYS_FSL_USB_SQUELCH_PROG_MASK; 939c641a87SSuresh Gupta 949c641a87SSuresh Gupta u32 squelch_prog_rd_3_5 = 959c641a87SSuresh Gupta (status >> CONFIG_SYS_FSL_USB_SQUELCH_PROG_RD_3) 969c641a87SSuresh Gupta & CONFIG_SYS_FSL_USB_SQUELCH_PROG_MASK; 979c641a87SSuresh Gupta 989c641a87SSuresh Gupta setbits_be32(&usb_phy->config1, 999c641a87SSuresh Gupta CONFIG_SYS_FSL_USB_HS_DISCNCT_INC); 1009c641a87SSuresh Gupta setbits_be32(&usb_phy->config2, 1019c641a87SSuresh Gupta CONFIG_SYS_FSL_USB_RX_AUTO_CAL_RD_WR_SEL); 1029c641a87SSuresh Gupta 1039c641a87SSuresh Gupta temp = squelch_prog_rd_0_2 << CONFIG_SYS_FSL_USB_SQUELCH_PROG_WR_0; 1049c641a87SSuresh Gupta out_be32(&usb_phy->config2, in_be32(&usb_phy->config2) | temp); 1059c641a87SSuresh Gupta 1069c641a87SSuresh Gupta temp = squelch_prog_rd_3_5 << CONFIG_SYS_FSL_USB_SQUELCH_PROG_WR_3; 1079c641a87SSuresh Gupta out_be32(&usb_phy->config2, in_be32(&usb_phy->config2) | temp); 1089c641a87SSuresh Gupta #endif 1099c641a87SSuresh Gupta } 1109c641a87SSuresh Gupta #endif 1119c641a87SSuresh Gupta 1129c641a87SSuresh Gupta 1132a44efebSZhao Qiang #if defined(CONFIG_QE) && !defined(CONFIG_U_QE) 114a47a12beSStefan Roese extern qe_iop_conf_t qe_iop_conf_tab[]; 115a47a12beSStefan Roese extern void qe_config_iopin(u8 port, u8 pin, int dir, 116a47a12beSStefan Roese int open_drain, int assign); 117a47a12beSStefan Roese extern void qe_init(uint qe_base); 118a47a12beSStefan Roese extern void qe_reset(void); 119a47a12beSStefan Roese 120a47a12beSStefan Roese static void config_qe_ioports(void) 121a47a12beSStefan Roese { 122a47a12beSStefan Roese u8 port, pin; 123a47a12beSStefan Roese int dir, open_drain, assign; 124a47a12beSStefan Roese int i; 125a47a12beSStefan Roese 126a47a12beSStefan Roese for (i = 0; qe_iop_conf_tab[i].assign != QE_IOP_TAB_END; i++) { 127a47a12beSStefan Roese port = qe_iop_conf_tab[i].port; 128a47a12beSStefan Roese pin = qe_iop_conf_tab[i].pin; 129a47a12beSStefan Roese dir = qe_iop_conf_tab[i].dir; 130a47a12beSStefan Roese open_drain = qe_iop_conf_tab[i].open_drain; 131a47a12beSStefan Roese assign = qe_iop_conf_tab[i].assign; 132a47a12beSStefan Roese qe_config_iopin(port, pin, dir, open_drain, assign); 133a47a12beSStefan Roese } 134a47a12beSStefan Roese } 135a47a12beSStefan Roese #endif 136a47a12beSStefan Roese 137a47a12beSStefan Roese #ifdef CONFIG_CPM2 138a47a12beSStefan Roese void config_8560_ioports (volatile ccsr_cpm_t * cpm) 139a47a12beSStefan Roese { 140a47a12beSStefan Roese int portnum; 141a47a12beSStefan Roese 142a47a12beSStefan Roese for (portnum = 0; portnum < 4; portnum++) { 143a47a12beSStefan Roese uint pmsk = 0, 144a47a12beSStefan Roese ppar = 0, 145a47a12beSStefan Roese psor = 0, 146a47a12beSStefan Roese pdir = 0, 147a47a12beSStefan Roese podr = 0, 148a47a12beSStefan Roese pdat = 0; 149a47a12beSStefan Roese iop_conf_t *iopc = (iop_conf_t *) & iop_conf_tab[portnum][0]; 150a47a12beSStefan Roese iop_conf_t *eiopc = iopc + 32; 151a47a12beSStefan Roese uint msk = 1; 152a47a12beSStefan Roese 153a47a12beSStefan Roese /* 154a47a12beSStefan Roese * NOTE: 155a47a12beSStefan Roese * index 0 refers to pin 31, 156a47a12beSStefan Roese * index 31 refers to pin 0 157a47a12beSStefan Roese */ 158a47a12beSStefan Roese while (iopc < eiopc) { 159a47a12beSStefan Roese if (iopc->conf) { 160a47a12beSStefan Roese pmsk |= msk; 161a47a12beSStefan Roese if (iopc->ppar) 162a47a12beSStefan Roese ppar |= msk; 163a47a12beSStefan Roese if (iopc->psor) 164a47a12beSStefan Roese psor |= msk; 165a47a12beSStefan Roese if (iopc->pdir) 166a47a12beSStefan Roese pdir |= msk; 167a47a12beSStefan Roese if (iopc->podr) 168a47a12beSStefan Roese podr |= msk; 169a47a12beSStefan Roese if (iopc->pdat) 170a47a12beSStefan Roese pdat |= msk; 171a47a12beSStefan Roese } 172a47a12beSStefan Roese 173a47a12beSStefan Roese msk <<= 1; 174a47a12beSStefan Roese iopc++; 175a47a12beSStefan Roese } 176a47a12beSStefan Roese 177a47a12beSStefan Roese if (pmsk != 0) { 178a47a12beSStefan Roese volatile ioport_t *iop = ioport_addr (cpm, portnum); 179a47a12beSStefan Roese uint tpmsk = ~pmsk; 180a47a12beSStefan Roese 181a47a12beSStefan Roese /* 182a47a12beSStefan Roese * the (somewhat confused) paragraph at the 183a47a12beSStefan Roese * bottom of page 35-5 warns that there might 184a47a12beSStefan Roese * be "unknown behaviour" when programming 185a47a12beSStefan Roese * PSORx and PDIRx, if PPARx = 1, so I 186a47a12beSStefan Roese * decided this meant I had to disable the 187a47a12beSStefan Roese * dedicated function first, and enable it 188a47a12beSStefan Roese * last. 189a47a12beSStefan Roese */ 190a47a12beSStefan Roese iop->ppar &= tpmsk; 191a47a12beSStefan Roese iop->psor = (iop->psor & tpmsk) | psor; 192a47a12beSStefan Roese iop->podr = (iop->podr & tpmsk) | podr; 193a47a12beSStefan Roese iop->pdat = (iop->pdat & tpmsk) | pdat; 194a47a12beSStefan Roese iop->pdir = (iop->pdir & tpmsk) | pdir; 195a47a12beSStefan Roese iop->ppar |= ppar; 196a47a12beSStefan Roese } 197a47a12beSStefan Roese } 198a47a12beSStefan Roese } 199a47a12beSStefan Roese #endif 200a47a12beSStefan Roese 2016aba33e9SKumar Gala #ifdef CONFIG_SYS_FSL_CPC 202fb4a2409SAneesh Bansal #if defined(CONFIG_RAMBOOT_PBL) || defined(CONFIG_SYS_CPC_REINIT_F) 203fb4a2409SAneesh Bansal static void disable_cpc_sram(void) 2046aba33e9SKumar Gala { 2056aba33e9SKumar Gala int i; 2066aba33e9SKumar Gala 2076aba33e9SKumar Gala cpc_corenet_t *cpc = (cpc_corenet_t *)CONFIG_SYS_FSL_CPC_ADDR; 2086aba33e9SKumar Gala 2096aba33e9SKumar Gala for (i = 0; i < CONFIG_SYS_NUM_CPC; i++, cpc++) { 2102a9fab82SShaohui Xie if (in_be32(&cpc->cpcsrcr0) & CPC_SRCR0_SRAMEN) { 2112a9fab82SShaohui Xie /* find and disable LAW of SRAM */ 2122a9fab82SShaohui Xie struct law_entry law = find_law(CONFIG_SYS_INIT_L3_ADDR); 2132a9fab82SShaohui Xie 2142a9fab82SShaohui Xie if (law.index == -1) { 2152a9fab82SShaohui Xie printf("\nFatal error happened\n"); 2162a9fab82SShaohui Xie return; 2172a9fab82SShaohui Xie } 2182a9fab82SShaohui Xie disable_law(law.index); 2192a9fab82SShaohui Xie 2202a9fab82SShaohui Xie clrbits_be32(&cpc->cpchdbcr0, CPC_HDBCR0_CDQ_SPEC_DIS); 2212a9fab82SShaohui Xie out_be32(&cpc->cpccsr0, 0); 2222a9fab82SShaohui Xie out_be32(&cpc->cpcsrcr0, 0); 2232a9fab82SShaohui Xie } 224fb4a2409SAneesh Bansal } 225fb4a2409SAneesh Bansal } 2262a9fab82SShaohui Xie #endif 2276aba33e9SKumar Gala 228fb4a2409SAneesh Bansal static void enable_cpc(void) 229fb4a2409SAneesh Bansal { 230fb4a2409SAneesh Bansal int i; 231fb4a2409SAneesh Bansal u32 size = 0; 232fb4a2409SAneesh Bansal 233fb4a2409SAneesh Bansal cpc_corenet_t *cpc = (cpc_corenet_t *)CONFIG_SYS_FSL_CPC_ADDR; 234fb4a2409SAneesh Bansal 235fb4a2409SAneesh Bansal for (i = 0; i < CONFIG_SYS_NUM_CPC; i++, cpc++) { 236fb4a2409SAneesh Bansal u32 cpccfg0 = in_be32(&cpc->cpccfg0); 237fb4a2409SAneesh Bansal size += CPC_CFG0_SZ_K(cpccfg0); 238fb4a2409SAneesh Bansal 2391d2c2a62SKumar Gala #ifdef CONFIG_SYS_FSL_ERRATUM_CPC_A002 2401d2c2a62SKumar Gala setbits_be32(&cpc->cpchdbcr0, CPC_HDBCR0_TAG_ECC_SCRUB_DIS); 2411d2c2a62SKumar Gala #endif 242868da593SKumar Gala #ifdef CONFIG_SYS_FSL_ERRATUM_CPC_A003 243868da593SKumar Gala setbits_be32(&cpc->cpchdbcr0, CPC_HDBCR0_DATA_ECC_SCRUB_DIS); 244868da593SKumar Gala #endif 24582125192SScott Wood #ifdef CONFIG_SYS_FSL_ERRATUM_A006593 24682125192SScott Wood setbits_be32(&cpc->cpchdbcr0, 1 << (31 - 21)); 24782125192SScott Wood #endif 248133fbfa9SYork Sun #ifdef CONFIG_SYS_FSL_ERRATUM_A006379 249133fbfa9SYork Sun if (has_erratum_a006379()) { 250133fbfa9SYork Sun setbits_be32(&cpc->cpchdbcr0, 251133fbfa9SYork Sun CPC_HDBCR0_SPLRU_LEVEL_EN); 252133fbfa9SYork Sun } 253133fbfa9SYork Sun #endif 2541d2c2a62SKumar Gala 2556aba33e9SKumar Gala out_be32(&cpc->cpccsr0, CPC_CSR0_CE | CPC_CSR0_PE); 2566aba33e9SKumar Gala /* Read back to sync write */ 2576aba33e9SKumar Gala in_be32(&cpc->cpccsr0); 2586aba33e9SKumar Gala 2596aba33e9SKumar Gala } 2606aba33e9SKumar Gala 2612f848f97SShruti Kanetkar puts("Corenet Platform Cache: "); 2622f848f97SShruti Kanetkar print_size(size * 1024, " enabled\n"); 2636aba33e9SKumar Gala } 2646aba33e9SKumar Gala 265e56143e5SKim Phillips static void invalidate_cpc(void) 2666aba33e9SKumar Gala { 2676aba33e9SKumar Gala int i; 2686aba33e9SKumar Gala cpc_corenet_t *cpc = (cpc_corenet_t *)CONFIG_SYS_FSL_CPC_ADDR; 2696aba33e9SKumar Gala 2706aba33e9SKumar Gala for (i = 0; i < CONFIG_SYS_NUM_CPC; i++, cpc++) { 2712a9fab82SShaohui Xie /* skip CPC when it used as all SRAM */ 2722a9fab82SShaohui Xie if (in_be32(&cpc->cpcsrcr0) & CPC_SRCR0_SRAMEN) 2732a9fab82SShaohui Xie continue; 2746aba33e9SKumar Gala /* Flash invalidate the CPC and clear all the locks */ 2756aba33e9SKumar Gala out_be32(&cpc->cpccsr0, CPC_CSR0_FI | CPC_CSR0_LFC); 2766aba33e9SKumar Gala while (in_be32(&cpc->cpccsr0) & (CPC_CSR0_FI | CPC_CSR0_LFC)) 2776aba33e9SKumar Gala ; 2786aba33e9SKumar Gala } 2796aba33e9SKumar Gala } 2806aba33e9SKumar Gala #else 2816aba33e9SKumar Gala #define enable_cpc() 2826aba33e9SKumar Gala #define invalidate_cpc() 2836aba33e9SKumar Gala #endif /* CONFIG_SYS_FSL_CPC */ 2846aba33e9SKumar Gala 285a47a12beSStefan Roese /* 286a47a12beSStefan Roese * Breathe some life into the CPU... 287a47a12beSStefan Roese * 288a47a12beSStefan Roese * Set up the memory map 289a47a12beSStefan Roese * initialize a bunch of registers 290a47a12beSStefan Roese */ 291a47a12beSStefan Roese 292a47a12beSStefan Roese #ifdef CONFIG_FSL_CORENET 293a47a12beSStefan Roese static void corenet_tb_init(void) 294a47a12beSStefan Roese { 295a47a12beSStefan Roese volatile ccsr_rcpm_t *rcpm = 296a47a12beSStefan Roese (void *)(CONFIG_SYS_FSL_CORENET_RCPM_ADDR); 297a47a12beSStefan Roese volatile ccsr_pic_t *pic = 298680c613aSKim Phillips (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR); 299a47a12beSStefan Roese u32 whoami = in_be32(&pic->whoami); 300a47a12beSStefan Roese 301a47a12beSStefan Roese /* Enable the timebase register for this core */ 302a47a12beSStefan Roese out_be32(&rcpm->ctbenrl, (1 << whoami)); 303a47a12beSStefan Roese } 304a47a12beSStefan Roese #endif 305a47a12beSStefan Roese 306c3678b09SYork Sun #ifdef CONFIG_SYS_FSL_ERRATUM_A007212 307c3678b09SYork Sun void fsl_erratum_a007212_workaround(void) 308c3678b09SYork Sun { 309c3678b09SYork Sun ccsr_gur_t __iomem *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); 310c3678b09SYork Sun u32 ddr_pll_ratio; 311c3678b09SYork Sun u32 __iomem *plldgdcr1 = (void *)(CONFIG_SYS_DCSRBAR + 0x21c20); 312c3678b09SYork Sun u32 __iomem *plldadcr1 = (void *)(CONFIG_SYS_DCSRBAR + 0x21c28); 313c3678b09SYork Sun u32 __iomem *dpdovrcr4 = (void *)(CONFIG_SYS_DCSRBAR + 0x21e80); 314c3678b09SYork Sun #if (CONFIG_NUM_DDR_CONTROLLERS >= 2) 315c3678b09SYork Sun u32 __iomem *plldgdcr2 = (void *)(CONFIG_SYS_DCSRBAR + 0x21c40); 316c3678b09SYork Sun u32 __iomem *plldadcr2 = (void *)(CONFIG_SYS_DCSRBAR + 0x21c48); 317c3678b09SYork Sun #if (CONFIG_NUM_DDR_CONTROLLERS >= 3) 318c3678b09SYork Sun u32 __iomem *plldgdcr3 = (void *)(CONFIG_SYS_DCSRBAR + 0x21c60); 319c3678b09SYork Sun u32 __iomem *plldadcr3 = (void *)(CONFIG_SYS_DCSRBAR + 0x21c68); 320c3678b09SYork Sun #endif 321c3678b09SYork Sun #endif 322c3678b09SYork Sun /* 323c3678b09SYork Sun * Even this workaround applies to selected version of SoCs, it is 324c3678b09SYork Sun * safe to apply to all versions, with the limitation of odd ratios. 325c3678b09SYork Sun * If RCW has disabled DDR PLL, we have to apply this workaround, 326c3678b09SYork Sun * otherwise DDR will not work. 327c3678b09SYork Sun */ 328c3678b09SYork Sun ddr_pll_ratio = (in_be32(&gur->rcwsr[0]) >> 329c3678b09SYork Sun FSL_CORENET_RCWSR0_MEM_PLL_RAT_SHIFT) & 330c3678b09SYork Sun FSL_CORENET_RCWSR0_MEM_PLL_RAT_MASK; 331c3678b09SYork Sun /* check if RCW sets ratio to 0, required by this workaround */ 332c3678b09SYork Sun if (ddr_pll_ratio != 0) 333c3678b09SYork Sun return; 334c3678b09SYork Sun ddr_pll_ratio = (in_be32(&gur->rcwsr[0]) >> 335c3678b09SYork Sun FSL_CORENET_RCWSR0_MEM_PLL_RAT_RESV_SHIFT) & 336c3678b09SYork Sun FSL_CORENET_RCWSR0_MEM_PLL_RAT_MASK; 337c3678b09SYork Sun /* check if reserved bits have the desired ratio */ 338c3678b09SYork Sun if (ddr_pll_ratio == 0) { 339c3678b09SYork Sun printf("Error: Unknown DDR PLL ratio!\n"); 340c3678b09SYork Sun return; 341c3678b09SYork Sun } 342c3678b09SYork Sun ddr_pll_ratio >>= 1; 343c3678b09SYork Sun 344c3678b09SYork Sun setbits_be32(plldadcr1, 0x02000001); 345c3678b09SYork Sun #if (CONFIG_NUM_DDR_CONTROLLERS >= 2) 346c3678b09SYork Sun setbits_be32(plldadcr2, 0x02000001); 347c3678b09SYork Sun #if (CONFIG_NUM_DDR_CONTROLLERS >= 3) 348c3678b09SYork Sun setbits_be32(plldadcr3, 0x02000001); 349c3678b09SYork Sun #endif 350c3678b09SYork Sun #endif 351c3678b09SYork Sun setbits_be32(dpdovrcr4, 0xe0000000); 352c3678b09SYork Sun out_be32(plldgdcr1, 0x08000001 | (ddr_pll_ratio << 1)); 353c3678b09SYork Sun #if (CONFIG_NUM_DDR_CONTROLLERS >= 2) 354c3678b09SYork Sun out_be32(plldgdcr2, 0x08000001 | (ddr_pll_ratio << 1)); 355c3678b09SYork Sun #if (CONFIG_NUM_DDR_CONTROLLERS >= 3) 356c3678b09SYork Sun out_be32(plldgdcr3, 0x08000001 | (ddr_pll_ratio << 1)); 357c3678b09SYork Sun #endif 358c3678b09SYork Sun #endif 359c3678b09SYork Sun udelay(100); 360c3678b09SYork Sun clrbits_be32(plldadcr1, 0x02000001); 361c3678b09SYork Sun #if (CONFIG_NUM_DDR_CONTROLLERS >= 2) 362c3678b09SYork Sun clrbits_be32(plldadcr2, 0x02000001); 363c3678b09SYork Sun #if (CONFIG_NUM_DDR_CONTROLLERS >= 3) 364c3678b09SYork Sun clrbits_be32(plldadcr3, 0x02000001); 365c3678b09SYork Sun #endif 366c3678b09SYork Sun #endif 367c3678b09SYork Sun clrbits_be32(dpdovrcr4, 0xe0000000); 368c3678b09SYork Sun } 369c3678b09SYork Sun #endif 370c3678b09SYork Sun 371a47a12beSStefan Roese void cpu_init_f (void) 372a47a12beSStefan Roese { 373a47a12beSStefan Roese extern void m8560_cpm_reset (void); 374f110fe94SStephen George #ifdef CONFIG_SYS_DCSRBAR_PHYS 375f110fe94SStephen George ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); 376aade2004STang Yuantian gd = (gd_t *)(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET); 377f110fe94SStephen George #endif 3787065b7d4SRuchika Gupta #if defined(CONFIG_SECURE_BOOT) 3797065b7d4SRuchika Gupta struct law_entry law; 3807065b7d4SRuchika Gupta #endif 381a47a12beSStefan Roese #ifdef CONFIG_MPC8548 382a47a12beSStefan Roese ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR); 383a47a12beSStefan Roese uint svr = get_svr(); 384a47a12beSStefan Roese 385a47a12beSStefan Roese /* 386a47a12beSStefan Roese * CPU2 errata workaround: A core hang possible while executing 387a47a12beSStefan Roese * a msync instruction and a snoopable transaction from an I/O 388a47a12beSStefan Roese * master tagged to make quick forward progress is present. 389a47a12beSStefan Roese * Fixed in silicon rev 2.1. 390a47a12beSStefan Roese */ 391a47a12beSStefan Roese if ((SVR_MAJ(svr) == 1) || ((SVR_MAJ(svr) == 2 && SVR_MIN(svr) == 0x0))) 392a47a12beSStefan Roese out_be32(&ecm->eebpcr, in_be32(&ecm->eebpcr) | (1 << 16)); 393a47a12beSStefan Roese #endif 394a47a12beSStefan Roese 395a47a12beSStefan Roese disable_tlb(14); 396a47a12beSStefan Roese disable_tlb(15); 397a47a12beSStefan Roese 3987065b7d4SRuchika Gupta #if defined(CONFIG_SECURE_BOOT) 3997065b7d4SRuchika Gupta /* Disable the LAW created for NOR flash by the PBI commands */ 4007065b7d4SRuchika Gupta law = find_law(CONFIG_SYS_PBI_FLASH_BASE); 4017065b7d4SRuchika Gupta if (law.index != -1) 4027065b7d4SRuchika Gupta disable_law(law.index); 403fb4a2409SAneesh Bansal 404fb4a2409SAneesh Bansal #if defined(CONFIG_SYS_CPC_REINIT_F) 405fb4a2409SAneesh Bansal disable_cpc_sram(); 406fb4a2409SAneesh Bansal #endif 4077065b7d4SRuchika Gupta #endif 4087065b7d4SRuchika Gupta 409a47a12beSStefan Roese #ifdef CONFIG_CPM2 410a47a12beSStefan Roese config_8560_ioports((ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR); 411a47a12beSStefan Roese #endif 412a47a12beSStefan Roese 413f51cdaf1SBecky Bruce init_early_memctl_regs(); 414a47a12beSStefan Roese 415a47a12beSStefan Roese #if defined(CONFIG_CPM2) 416a47a12beSStefan Roese m8560_cpm_reset(); 417a47a12beSStefan Roese #endif 4182a44efebSZhao Qiang 4192a44efebSZhao Qiang #if defined(CONFIG_QE) && !defined(CONFIG_U_QE) 420a47a12beSStefan Roese /* Config QE ioports */ 421a47a12beSStefan Roese config_qe_ioports(); 422a47a12beSStefan Roese #endif 4232a44efebSZhao Qiang 424a47a12beSStefan Roese #if defined(CONFIG_FSL_DMA) 425a47a12beSStefan Roese dma_init(); 426a47a12beSStefan Roese #endif 427a47a12beSStefan Roese #ifdef CONFIG_FSL_CORENET 428a47a12beSStefan Roese corenet_tb_init(); 429a47a12beSStefan Roese #endif 430a47a12beSStefan Roese init_used_tlb_cams(); 4316aba33e9SKumar Gala 4326aba33e9SKumar Gala /* Invalidate the CPC before DDR gets enabled */ 4336aba33e9SKumar Gala invalidate_cpc(); 434f110fe94SStephen George 435f110fe94SStephen George #ifdef CONFIG_SYS_DCSRBAR_PHYS 436f110fe94SStephen George /* set DCSRCR so that DCSR space is 1G */ 437f110fe94SStephen George setbits_be32(&gur->dcsrcr, FSL_CORENET_DCSR_SZ_1G); 438f110fe94SStephen George in_be32(&gur->dcsrcr); 439f110fe94SStephen George #endif 440f110fe94SStephen George 441aade2004STang Yuantian #ifdef CONFIG_SYS_DCSRBAR_PHYS 442aade2004STang Yuantian #ifdef CONFIG_DEEP_SLEEP 443aade2004STang Yuantian /* disable the console if boot from deep sleep */ 444aade2004STang Yuantian if (in_be32(&gur->scrtsr[0]) & (1 << 3)) 445aade2004STang Yuantian gd->flags |= GD_FLG_SILENT | GD_FLG_DISABLE_CONSOLE; 446aade2004STang Yuantian #endif 447aade2004STang Yuantian #endif 448c3678b09SYork Sun #ifdef CONFIG_SYS_FSL_ERRATUM_A007212 449c3678b09SYork Sun fsl_erratum_a007212_workaround(); 450c3678b09SYork Sun #endif 451c3678b09SYork Sun 452a47a12beSStefan Roese } 453a47a12beSStefan Roese 45435079aa9SKumar Gala /* Implement a dummy function for those platforms w/o SERDES */ 45535079aa9SKumar Gala static void __fsl_serdes__init(void) 45635079aa9SKumar Gala { 45735079aa9SKumar Gala return ; 45835079aa9SKumar Gala } 45935079aa9SKumar Gala __attribute__((weak, alias("__fsl_serdes__init"))) void fsl_serdes_init(void); 460a47a12beSStefan Roese 461e9827468SPrabhakar Kushwaha #if defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2) && defined(CONFIG_E6500) 4626d2b9da1SYork Sun int enable_cluster_l2(void) 4636d2b9da1SYork Sun { 4646d2b9da1SYork Sun int i = 0; 4655122dfaeSShengzhou Liu u32 cluster, svr = get_svr(); 4666d2b9da1SYork Sun ccsr_gur_t *gur = (void __iomem *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); 4676d2b9da1SYork Sun struct ccsr_cluster_l2 __iomem *l2cache; 4686d2b9da1SYork Sun 4695122dfaeSShengzhou Liu /* only the L2 of first cluster should be enabled as expected on T4080, 4705122dfaeSShengzhou Liu * but there is no EOC in the first cluster as HW sake, so return here 4715122dfaeSShengzhou Liu * to skip enabling L2 cache of the 2nd cluster. 4725122dfaeSShengzhou Liu */ 4735122dfaeSShengzhou Liu if (SVR_SOC_VER(svr) == SVR_T4080) 4745122dfaeSShengzhou Liu return 0; 4755122dfaeSShengzhou Liu 4766d2b9da1SYork Sun cluster = in_be32(&gur->tp_cluster[i].lower); 4776d2b9da1SYork Sun if (cluster & TP_CLUSTER_EOC) 4786d2b9da1SYork Sun return 0; 4796d2b9da1SYork Sun 4806d2b9da1SYork Sun /* The first cache has already been set up, so skip it */ 4816d2b9da1SYork Sun i++; 4826d2b9da1SYork Sun 4836d2b9da1SYork Sun /* Look through the remaining clusters, and set up their caches */ 4846d2b9da1SYork Sun do { 485db9a8070SPrabhakar Kushwaha int j, cluster_valid = 0; 486db9a8070SPrabhakar Kushwaha 4876d2b9da1SYork Sun l2cache = (void __iomem *)(CONFIG_SYS_FSL_CLUSTER_1_L2 + i * 0x40000); 488db9a8070SPrabhakar Kushwaha 4896d2b9da1SYork Sun cluster = in_be32(&gur->tp_cluster[i].lower); 4906d2b9da1SYork Sun 491db9a8070SPrabhakar Kushwaha /* check that at least one core/accel is enabled in cluster */ 492db9a8070SPrabhakar Kushwaha for (j = 0; j < 4; j++) { 493db9a8070SPrabhakar Kushwaha u32 idx = (cluster >> (j*8)) & TP_CLUSTER_INIT_MASK; 494db9a8070SPrabhakar Kushwaha u32 type = in_be32(&gur->tp_ityp[idx]); 495db9a8070SPrabhakar Kushwaha 496db9a8070SPrabhakar Kushwaha if (type & TP_ITYP_AV) 497db9a8070SPrabhakar Kushwaha cluster_valid = 1; 498db9a8070SPrabhakar Kushwaha } 499db9a8070SPrabhakar Kushwaha 500db9a8070SPrabhakar Kushwaha if (cluster_valid) { 5016d2b9da1SYork Sun /* set stash ID to (cluster) * 2 + 32 + 1 */ 5026d2b9da1SYork Sun clrsetbits_be32(&l2cache->l2csr1, 0xff, 32 + i * 2 + 1); 5036d2b9da1SYork Sun 5046d2b9da1SYork Sun printf("enable l2 for cluster %d %p\n", i, l2cache); 5056d2b9da1SYork Sun 5066d2b9da1SYork Sun out_be32(&l2cache->l2csr0, L2CSR0_L2FI|L2CSR0_L2LFC); 507db9a8070SPrabhakar Kushwaha while ((in_be32(&l2cache->l2csr0) 508db9a8070SPrabhakar Kushwaha & (L2CSR0_L2FI|L2CSR0_L2LFC)) != 0) 5096d2b9da1SYork Sun ; 5109cd95ac7SJames Yang out_be32(&l2cache->l2csr0, L2CSR0_L2E|L2CSR0_L2PE|L2CSR0_L2REP_MODE); 511db9a8070SPrabhakar Kushwaha } 5126d2b9da1SYork Sun i++; 5136d2b9da1SYork Sun } while (!(cluster & TP_CLUSTER_EOC)); 5146d2b9da1SYork Sun 5156d2b9da1SYork Sun return 0; 5166d2b9da1SYork Sun } 5176d2b9da1SYork Sun #endif 5186d2b9da1SYork Sun 519a47a12beSStefan Roese /* 520a47a12beSStefan Roese * Initialize L2 as cache. 521a47a12beSStefan Roese * 522a47a12beSStefan Roese * The newer 8548, etc, parts have twice as much cache, but 523a47a12beSStefan Roese * use the same bit-encoding as the older 8555, etc, parts. 524a47a12beSStefan Roese * 525a47a12beSStefan Roese */ 526a47a12beSStefan Roese int cpu_init_r(void) 527a47a12beSStefan Roese { 528fbc20aabSTimur Tabi __maybe_unused u32 svr = get_svr(); 5293f0202edSLan Chunhe #ifdef CONFIG_SYS_LBC_LCRR 5306d2b9da1SYork Sun fsl_lbc_t *lbc = (void __iomem *)LBC_BASE_ADDR; 5316d2b9da1SYork Sun #endif 5326d2b9da1SYork Sun #ifdef CONFIG_L2_CACHE 5336d2b9da1SYork Sun ccsr_l2cache_t *l2cache = (void __iomem *)CONFIG_SYS_MPC85xx_L2_ADDR; 534e9827468SPrabhakar Kushwaha #elif defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2) && defined(CONFIG_E6500) 5356d2b9da1SYork Sun struct ccsr_cluster_l2 * l2cache = (void __iomem *)CONFIG_SYS_FSL_CLUSTER_1_L2; 5363f0202edSLan Chunhe #endif 537afbfdf54SYork Sun #if defined(CONFIG_PPC_SPINTABLE_COMPATIBLE) && defined(CONFIG_MP) 5382a5fcb83SYork Sun extern int spin_table_compat; 5392a5fcb83SYork Sun const char *spin; 5402a5fcb83SYork Sun #endif 541424bf942SShengzhou Liu #ifdef CONFIG_SYS_FSL_ERRATUM_SEC_A003571 542424bf942SShengzhou Liu ccsr_sec_t __iomem *sec = (void *)CONFIG_SYS_FSL_SEC_ADDR; 543424bf942SShengzhou Liu #endif 5445e23ab0aSYork Sun #if defined(CONFIG_SYS_P4080_ERRATUM_CPU22) || \ 5455e23ab0aSYork Sun defined(CONFIG_SYS_FSL_ERRATUM_NMG_CPU_A011) 5465e23ab0aSYork Sun /* 54757125f22SYork Sun * CPU22 and NMG_CPU_A011 share the same workaround. 5485e23ab0aSYork Sun * CPU22 applies to P4080 rev 1.0, 2.0, fixed in 3.0 5495e23ab0aSYork Sun * NMG_CPU_A011 applies to P4080 rev 1.0, 2.0, fixed in 3.0 55057125f22SYork Sun * also applies to P3041 rev 1.0, 1.1, P2041 rev 1.0, 1.1, both 55157125f22SYork Sun * fixed in 2.0. NMG_CPU_A011 is activated by default and can 55257125f22SYork Sun * be disabled by hwconfig with syntax: 55357125f22SYork Sun * 55457125f22SYork Sun * fsl_cpu_a011:disable 5555e23ab0aSYork Sun */ 55657125f22SYork Sun extern int enable_cpu_a011_workaround; 55757125f22SYork Sun #ifdef CONFIG_SYS_P4080_ERRATUM_CPU22 55857125f22SYork Sun enable_cpu_a011_workaround = (SVR_MAJ(svr) < 3); 55957125f22SYork Sun #else 56057125f22SYork Sun char buffer[HWCONFIG_BUFFER_SIZE]; 56157125f22SYork Sun char *buf = NULL; 56257125f22SYork Sun int n, res; 56357125f22SYork Sun 56457125f22SYork Sun n = getenv_f("hwconfig", buffer, sizeof(buffer)); 56557125f22SYork Sun if (n > 0) 56657125f22SYork Sun buf = buffer; 56757125f22SYork Sun 56857125f22SYork Sun res = hwconfig_arg_cmp_f("fsl_cpu_a011", "disable", buf); 56957125f22SYork Sun if (res > 0) 57057125f22SYork Sun enable_cpu_a011_workaround = 0; 57157125f22SYork Sun else { 57257125f22SYork Sun if (n >= HWCONFIG_BUFFER_SIZE) { 57357125f22SYork Sun printf("fsl_cpu_a011 was not found. hwconfig variable " 57457125f22SYork Sun "may be too long\n"); 57557125f22SYork Sun } 57657125f22SYork Sun enable_cpu_a011_workaround = 57757125f22SYork Sun (SVR_SOC_VER(svr) == SVR_P4080 && SVR_MAJ(svr) < 3) || 57857125f22SYork Sun (SVR_SOC_VER(svr) != SVR_P4080 && SVR_MAJ(svr) < 2); 57957125f22SYork Sun } 58057125f22SYork Sun #endif 58157125f22SYork Sun if (enable_cpu_a011_workaround) { 582fd3c9befSKumar Gala flush_dcache(); 583fd3c9befSKumar Gala mtspr(L1CSR2, (mfspr(L1CSR2) | L1CSR2_DCWS)); 584fd3c9befSKumar Gala sync(); 5851e9ea85fSYork Sun } 586fd3c9befSKumar Gala #endif 587d217a9adSYork Sun #ifdef CONFIG_SYS_FSL_ERRATUM_A005812 588d217a9adSYork Sun /* 589d217a9adSYork Sun * A-005812 workaround sets bit 32 of SPR 976 for SoCs running 590d217a9adSYork Sun * in write shadow mode. Checking DCWS before setting SPR 976. 591d217a9adSYork Sun */ 592d217a9adSYork Sun if (mfspr(L1CSR2) & L1CSR2_DCWS) 593d217a9adSYork Sun mtspr(SPRN_HDBCR0, (mfspr(SPRN_HDBCR0) | 0x80000000)); 594d217a9adSYork Sun #endif 595fd3c9befSKumar Gala 596afbfdf54SYork Sun #if defined(CONFIG_PPC_SPINTABLE_COMPATIBLE) && defined(CONFIG_MP) 5972a5fcb83SYork Sun spin = getenv("spin_table_compat"); 5982a5fcb83SYork Sun if (spin && (*spin == 'n')) 5992a5fcb83SYork Sun spin_table_compat = 0; 6002a5fcb83SYork Sun else 6012a5fcb83SYork Sun spin_table_compat = 1; 6022a5fcb83SYork Sun #endif 6032a5fcb83SYork Sun 604a47a12beSStefan Roese puts ("L2: "); 605a47a12beSStefan Roese 606a47a12beSStefan Roese #if defined(CONFIG_L2_CACHE) 607a47a12beSStefan Roese volatile uint cache_ctl; 608fbc20aabSTimur Tabi uint ver; 609a47a12beSStefan Roese u32 l2siz_field; 610a47a12beSStefan Roese 611a47a12beSStefan Roese ver = SVR_SOC_VER(svr); 612a47a12beSStefan Roese 613a47a12beSStefan Roese asm("msync;isync"); 614a47a12beSStefan Roese cache_ctl = l2cache->l2ctl; 615a47a12beSStefan Roese 616a47a12beSStefan Roese #if defined(CONFIG_SYS_RAMBOOT) && defined(CONFIG_SYS_INIT_L2_ADDR) 617a47a12beSStefan Roese if (cache_ctl & MPC85xx_L2CTL_L2E) { 618a47a12beSStefan Roese /* Clear L2 SRAM memory-mapped base address */ 619a47a12beSStefan Roese out_be32(&l2cache->l2srbar0, 0x0); 620a47a12beSStefan Roese out_be32(&l2cache->l2srbar1, 0x0); 621a47a12beSStefan Roese 622a47a12beSStefan Roese /* set MBECCDIS=0, SBECCDIS=0 */ 623a47a12beSStefan Roese clrbits_be32(&l2cache->l2errdis, 624a47a12beSStefan Roese (MPC85xx_L2ERRDIS_MBECC | 625a47a12beSStefan Roese MPC85xx_L2ERRDIS_SBECC)); 626a47a12beSStefan Roese 627a47a12beSStefan Roese /* set L2E=0, L2SRAM=0 */ 628a47a12beSStefan Roese clrbits_be32(&l2cache->l2ctl, 629a47a12beSStefan Roese (MPC85xx_L2CTL_L2E | 630a47a12beSStefan Roese MPC85xx_L2CTL_L2SRAM_ENTIRE)); 631a47a12beSStefan Roese } 632a47a12beSStefan Roese #endif 633a47a12beSStefan Roese 634a47a12beSStefan Roese l2siz_field = (cache_ctl >> 28) & 0x3; 635a47a12beSStefan Roese 636a47a12beSStefan Roese switch (l2siz_field) { 637a47a12beSStefan Roese case 0x0: 638a47a12beSStefan Roese printf(" unknown size (0x%08x)\n", cache_ctl); 639a47a12beSStefan Roese return -1; 640a47a12beSStefan Roese break; 641a47a12beSStefan Roese case 0x1: 642a47a12beSStefan Roese if (ver == SVR_8540 || ver == SVR_8560 || 64348f6a5c3SYork Sun ver == SVR_8541 || ver == SVR_8555) { 6446b44d9e5SShruti Kanetkar puts("128 KiB "); 6456b44d9e5SShruti Kanetkar /* set L2E=1, L2I=1, & L2BLKSZ=1 (128 KiBibyte) */ 646a47a12beSStefan Roese cache_ctl = 0xc4000000; 647a47a12beSStefan Roese } else { 6486b44d9e5SShruti Kanetkar puts("256 KiB "); 649a47a12beSStefan Roese cache_ctl = 0xc0000000; /* set L2E=1, L2I=1, & L2SRAM=0 */ 650a47a12beSStefan Roese } 651a47a12beSStefan Roese break; 652a47a12beSStefan Roese case 0x2: 653a47a12beSStefan Roese if (ver == SVR_8540 || ver == SVR_8560 || 65448f6a5c3SYork Sun ver == SVR_8541 || ver == SVR_8555) { 6556b44d9e5SShruti Kanetkar puts("256 KiB "); 6566b44d9e5SShruti Kanetkar /* set L2E=1, L2I=1, & L2BLKSZ=2 (256 KiBibyte) */ 657a47a12beSStefan Roese cache_ctl = 0xc8000000; 658a47a12beSStefan Roese } else { 6596b44d9e5SShruti Kanetkar puts("512 KiB "); 660a47a12beSStefan Roese /* set L2E=1, L2I=1, & L2SRAM=0 */ 661a47a12beSStefan Roese cache_ctl = 0xc0000000; 662a47a12beSStefan Roese } 663a47a12beSStefan Roese break; 664a47a12beSStefan Roese case 0x3: 6656b44d9e5SShruti Kanetkar puts("1024 KiB "); 666a47a12beSStefan Roese /* set L2E=1, L2I=1, & L2SRAM=0 */ 667a47a12beSStefan Roese cache_ctl = 0xc0000000; 668a47a12beSStefan Roese break; 669a47a12beSStefan Roese } 670a47a12beSStefan Roese 671a47a12beSStefan Roese if (l2cache->l2ctl & MPC85xx_L2CTL_L2E) { 672a47a12beSStefan Roese puts("already enabled"); 673888279b5SHaiying Wang #if defined(CONFIG_SYS_INIT_L2_ADDR) && defined(CONFIG_SYS_FLASH_BASE) 674e4c9a35dSKumar Gala u32 l2srbar = l2cache->l2srbar0; 675a47a12beSStefan Roese if (l2cache->l2ctl & MPC85xx_L2CTL_L2SRAM_ENTIRE 676a47a12beSStefan Roese && l2srbar >= CONFIG_SYS_FLASH_BASE) { 677a47a12beSStefan Roese l2srbar = CONFIG_SYS_INIT_L2_ADDR; 678a47a12beSStefan Roese l2cache->l2srbar0 = l2srbar; 6799a511bd6SScott Wood printf(", moving to 0x%08x", CONFIG_SYS_INIT_L2_ADDR); 680a47a12beSStefan Roese } 681a47a12beSStefan Roese #endif /* CONFIG_SYS_INIT_L2_ADDR */ 682a47a12beSStefan Roese puts("\n"); 683a47a12beSStefan Roese } else { 684a47a12beSStefan Roese asm("msync;isync"); 685a47a12beSStefan Roese l2cache->l2ctl = cache_ctl; /* invalidate & enable */ 686a47a12beSStefan Roese asm("msync;isync"); 687a47a12beSStefan Roese puts("enabled\n"); 688a47a12beSStefan Roese } 689a47a12beSStefan Roese #elif defined(CONFIG_BACKSIDE_L2_CACHE) 69048f6a5c3SYork Sun if (SVR_SOC_VER(svr) == SVR_P2040) { 691acf3f8daSKumar Gala puts("N/A\n"); 692acf3f8daSKumar Gala goto skip_l2; 693acf3f8daSKumar Gala } 694acf3f8daSKumar Gala 695a47a12beSStefan Roese u32 l2cfg0 = mfspr(SPRN_L2CFG0); 696a47a12beSStefan Roese 697a47a12beSStefan Roese /* invalidate the L2 cache */ 698a47a12beSStefan Roese mtspr(SPRN_L2CSR0, (L2CSR0_L2FI|L2CSR0_L2LFC)); 699a47a12beSStefan Roese while (mfspr(SPRN_L2CSR0) & (L2CSR0_L2FI|L2CSR0_L2LFC)) 700a47a12beSStefan Roese ; 701a47a12beSStefan Roese 702a47a12beSStefan Roese #ifdef CONFIG_SYS_CACHE_STASHING 703a47a12beSStefan Roese /* set stash id to (coreID) * 2 + 32 + L2 (1) */ 704a47a12beSStefan Roese mtspr(SPRN_L2CSR1, (32 + 1)); 705a47a12beSStefan Roese #endif 706a47a12beSStefan Roese 707a47a12beSStefan Roese /* enable the cache */ 708a47a12beSStefan Roese mtspr(SPRN_L2CSR0, CONFIG_SYS_INIT_L2CSR0); 709a47a12beSStefan Roese 710a47a12beSStefan Roese if (CONFIG_SYS_INIT_L2CSR0 & L2CSR0_L2E) { 711a47a12beSStefan Roese while (!(mfspr(SPRN_L2CSR0) & L2CSR0_L2E)) 712a47a12beSStefan Roese ; 7132f848f97SShruti Kanetkar print_size((l2cfg0 & 0x3fff) * 64 * 1024, " enabled\n"); 714a47a12beSStefan Roese } 715acf3f8daSKumar Gala 716acf3f8daSKumar Gala skip_l2: 717e9827468SPrabhakar Kushwaha #elif defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2) && defined(CONFIG_E6500) 7186d2b9da1SYork Sun if (l2cache->l2csr0 & L2CSR0_L2E) 7192f848f97SShruti Kanetkar print_size((l2cache->l2cfg0 & 0x3fff) * 64 * 1024, 7202f848f97SShruti Kanetkar " enabled\n"); 7216d2b9da1SYork Sun 7226d2b9da1SYork Sun enable_cluster_l2(); 723a47a12beSStefan Roese #else 724a47a12beSStefan Roese puts("disabled\n"); 725a47a12beSStefan Roese #endif 7266aba33e9SKumar Gala 727fb4a2409SAneesh Bansal #if defined(CONFIG_RAMBOOT_PBL) 728fb4a2409SAneesh Bansal disable_cpc_sram(); 729fb4a2409SAneesh Bansal #endif 7306aba33e9SKumar Gala enable_cpc(); 7316aba33e9SKumar Gala 732cb93071bSYork Sun #ifndef CONFIG_SYS_FSL_NO_SERDES 733af025065SKumar Gala /* needs to be in ram since code uses global static vars */ 734af025065SKumar Gala fsl_serdes_init(); 735cb93071bSYork Sun #endif 736af025065SKumar Gala 737424bf942SShengzhou Liu #ifdef CONFIG_SYS_FSL_ERRATUM_SEC_A003571 738424bf942SShengzhou Liu #define MCFGR_AXIPIPE 0x000000f0 739424bf942SShengzhou Liu if (IS_SVR_REV(svr, 1, 0)) 740424bf942SShengzhou Liu clrbits_be32(&sec->mcfgr, MCFGR_AXIPIPE); 741424bf942SShengzhou Liu #endif 742424bf942SShengzhou Liu 74372bd83cdSShengzhou Liu #ifdef CONFIG_SYS_FSL_ERRATUM_A005871 74472bd83cdSShengzhou Liu if (IS_SVR_REV(svr, 1, 0)) { 74572bd83cdSShengzhou Liu int i; 74672bd83cdSShengzhou Liu __be32 *p = (void __iomem *)CONFIG_SYS_DCSRBAR + 0xb004c; 74772bd83cdSShengzhou Liu 74872bd83cdSShengzhou Liu for (i = 0; i < 12; i++) { 74972bd83cdSShengzhou Liu p += i + (i > 5 ? 11 : 0); 75072bd83cdSShengzhou Liu out_be32(p, 0x2); 75172bd83cdSShengzhou Liu } 75272bd83cdSShengzhou Liu p = (void __iomem *)CONFIG_SYS_DCSRBAR + 0xb0108; 75372bd83cdSShengzhou Liu out_be32(p, 0x34); 75472bd83cdSShengzhou Liu } 75572bd83cdSShengzhou Liu #endif 75672bd83cdSShengzhou Liu 757a09b9b68SKumar Gala #ifdef CONFIG_SYS_SRIO 758a09b9b68SKumar Gala srio_init(); 759c8b28152SLiu Gang #ifdef CONFIG_SRIO_PCIE_BOOT_MASTER 760ff65f126SLiu Gang char *s = getenv("bootmaster"); 761ff65f126SLiu Gang if (s) { 762ff65f126SLiu Gang if (!strcmp(s, "SRIO1")) { 763ff65f126SLiu Gang srio_boot_master(1); 764ff65f126SLiu Gang srio_boot_master_release_slave(1); 765ff65f126SLiu Gang } 766ff65f126SLiu Gang if (!strcmp(s, "SRIO2")) { 767ff65f126SLiu Gang srio_boot_master(2); 768ff65f126SLiu Gang srio_boot_master_release_slave(2); 769ff65f126SLiu Gang } 770ff65f126SLiu Gang } 7715ffa88ecSLiu Gang #endif 772a09b9b68SKumar Gala #endif 773a09b9b68SKumar Gala 774a47a12beSStefan Roese #if defined(CONFIG_MP) 775a47a12beSStefan Roese setup_mp(); 776a47a12beSStefan Roese #endif 7773f0202edSLan Chunhe 7784e0be34aSZang Roy-R61911 #ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC13 779ae026ffdSRoy Zang { 7804e0be34aSZang Roy-R61911 if (SVR_MAJ(svr) < 3) { 781ae026ffdSRoy Zang void *p; 782ae026ffdSRoy Zang p = (void *)CONFIG_SYS_DCSRBAR + 0x20520; 783ae026ffdSRoy Zang setbits_be32(p, 1 << (31 - 14)); 784ae026ffdSRoy Zang } 7854e0be34aSZang Roy-R61911 } 786ae026ffdSRoy Zang #endif 787ae026ffdSRoy Zang 7883f0202edSLan Chunhe #ifdef CONFIG_SYS_LBC_LCRR 7893f0202edSLan Chunhe /* 7903f0202edSLan Chunhe * Modify the CLKDIV field of LCRR register to improve the writing 7913f0202edSLan Chunhe * speed for NOR flash. 7923f0202edSLan Chunhe */ 7933f0202edSLan Chunhe clrsetbits_be32(&lbc->lcrr, LCRR_CLKDIV, CONFIG_SYS_LBC_LCRR); 7943f0202edSLan Chunhe __raw_readl(&lbc->lcrr); 7953f0202edSLan Chunhe isync(); 7962b3a1cddSKumar Gala #ifdef CONFIG_SYS_FSL_ERRATUM_NMG_LBC103 7972b3a1cddSKumar Gala udelay(100); 7982b3a1cddSKumar Gala #endif 7993f0202edSLan Chunhe #endif 8003f0202edSLan Chunhe 80186221f09SRoy Zang #ifdef CONFIG_SYS_FSL_USB1_PHY_ENABLE 80286221f09SRoy Zang { 8039dee205dSramneek mehresh struct ccsr_usb_phy __iomem *usb_phy1 = 80486221f09SRoy Zang (void *)CONFIG_SYS_MPC85xx_USB1_PHY_ADDR; 8059c641a87SSuresh Gupta #ifdef CONFIG_SYS_FSL_ERRATUM_A006261 8069c641a87SSuresh Gupta if (has_erratum_a006261()) 8079c641a87SSuresh Gupta fsl_erratum_a006261_workaround(usb_phy1); 8089c641a87SSuresh Gupta #endif 80986221f09SRoy Zang out_be32(&usb_phy1->usb_enable_override, 81086221f09SRoy Zang CONFIG_SYS_FSL_USB_ENABLE_OVERRIDE); 81186221f09SRoy Zang } 81286221f09SRoy Zang #endif 81386221f09SRoy Zang #ifdef CONFIG_SYS_FSL_USB2_PHY_ENABLE 81486221f09SRoy Zang { 8159dee205dSramneek mehresh struct ccsr_usb_phy __iomem *usb_phy2 = 81686221f09SRoy Zang (void *)CONFIG_SYS_MPC85xx_USB2_PHY_ADDR; 8179c641a87SSuresh Gupta #ifdef CONFIG_SYS_FSL_ERRATUM_A006261 8189c641a87SSuresh Gupta if (has_erratum_a006261()) 8199c641a87SSuresh Gupta fsl_erratum_a006261_workaround(usb_phy2); 8209c641a87SSuresh Gupta #endif 82186221f09SRoy Zang out_be32(&usb_phy2->usb_enable_override, 82286221f09SRoy Zang CONFIG_SYS_FSL_USB_ENABLE_OVERRIDE); 82386221f09SRoy Zang } 82486221f09SRoy Zang #endif 82586221f09SRoy Zang 82699d7b0a4SXulei #ifdef CONFIG_SYS_FSL_ERRATUM_USB14 82799d7b0a4SXulei /* On P204x/P304x/P50x0 Rev1.0, USB transmit will result internal 82899d7b0a4SXulei * multi-bit ECC errors which has impact on performance, so software 82999d7b0a4SXulei * should disable all ECC reporting from USB1 and USB2. 83099d7b0a4SXulei */ 83199d7b0a4SXulei if (IS_SVR_REV(get_svr(), 1, 0)) { 83299d7b0a4SXulei struct dcsr_dcfg_regs *dcfg = (struct dcsr_dcfg_regs *) 83399d7b0a4SXulei (CONFIG_SYS_DCSRBAR + CONFIG_SYS_DCSR_DCFG_OFFSET); 83499d7b0a4SXulei setbits_be32(&dcfg->ecccr1, 83599d7b0a4SXulei (DCSR_DCFG_ECC_DISABLE_USB1 | 83699d7b0a4SXulei DCSR_DCFG_ECC_DISABLE_USB2)); 83799d7b0a4SXulei } 83899d7b0a4SXulei #endif 83999d7b0a4SXulei 8403fa75c87SRoy Zang #if defined(CONFIG_SYS_FSL_USB_DUAL_PHY_ENABLE) 8419dee205dSramneek mehresh struct ccsr_usb_phy __iomem *usb_phy = 8423fa75c87SRoy Zang (void *)CONFIG_SYS_MPC85xx_USB1_PHY_ADDR; 8433fa75c87SRoy Zang setbits_be32(&usb_phy->pllprg[1], 8443fa75c87SRoy Zang CONFIG_SYS_FSL_USB_PLLPRG2_PHY2_CLK_EN | 8453fa75c87SRoy Zang CONFIG_SYS_FSL_USB_PLLPRG2_PHY1_CLK_EN | 8463fa75c87SRoy Zang CONFIG_SYS_FSL_USB_PLLPRG2_MFI | 8473fa75c87SRoy Zang CONFIG_SYS_FSL_USB_PLLPRG2_PLL_EN); 848d1c561cdSNikhil Badola #ifdef CONFIG_SYS_FSL_SINGLE_SOURCE_CLK 849d1c561cdSNikhil Badola usb_single_source_clk_configure(usb_phy); 850d1c561cdSNikhil Badola #endif 8513fa75c87SRoy Zang setbits_be32(&usb_phy->port1.ctrl, 8523fa75c87SRoy Zang CONFIG_SYS_FSL_USB_CTRL_PHY_EN); 8533fa75c87SRoy Zang setbits_be32(&usb_phy->port1.drvvbuscfg, 8543fa75c87SRoy Zang CONFIG_SYS_FSL_USB_DRVVBUS_CR_EN); 8553fa75c87SRoy Zang setbits_be32(&usb_phy->port1.pwrfltcfg, 8563fa75c87SRoy Zang CONFIG_SYS_FSL_USB_PWRFLT_CR_EN); 8573fa75c87SRoy Zang setbits_be32(&usb_phy->port2.ctrl, 8583fa75c87SRoy Zang CONFIG_SYS_FSL_USB_CTRL_PHY_EN); 8593fa75c87SRoy Zang setbits_be32(&usb_phy->port2.drvvbuscfg, 8603fa75c87SRoy Zang CONFIG_SYS_FSL_USB_DRVVBUS_CR_EN); 8613fa75c87SRoy Zang setbits_be32(&usb_phy->port2.pwrfltcfg, 8623fa75c87SRoy Zang CONFIG_SYS_FSL_USB_PWRFLT_CR_EN); 8639c641a87SSuresh Gupta 8649c641a87SSuresh Gupta #ifdef CONFIG_SYS_FSL_ERRATUM_A006261 8659c641a87SSuresh Gupta if (has_erratum_a006261()) 8669c641a87SSuresh Gupta fsl_erratum_a006261_workaround(usb_phy); 8673fa75c87SRoy Zang #endif 8683fa75c87SRoy Zang 8699c641a87SSuresh Gupta #endif /* CONFIG_SYS_FSL_USB_DUAL_PHY_ENABLE */ 8709c641a87SSuresh Gupta 871c916d7c9SKumar Gala #ifdef CONFIG_FMAN_ENET 872c916d7c9SKumar Gala fman_enet_init(); 873c916d7c9SKumar Gala #endif 874c916d7c9SKumar Gala 875fbc20aabSTimur Tabi #if defined(CONFIG_FSL_SATA_V2) && defined(CONFIG_FSL_SATA_ERRATUM_A001) 876fbc20aabSTimur Tabi /* 877fbc20aabSTimur Tabi * For P1022/1013 Rev1.0 silicon, after power on SATA host 878fbc20aabSTimur Tabi * controller is configured in legacy mode instead of the 879fbc20aabSTimur Tabi * expected enterprise mode. Software needs to clear bit[28] 880fbc20aabSTimur Tabi * of HControl register to change to enterprise mode from 881fbc20aabSTimur Tabi * legacy mode. We assume that the controller is offline. 882fbc20aabSTimur Tabi */ 883fbc20aabSTimur Tabi if (IS_SVR_REV(svr, 1, 0) && 884fbc20aabSTimur Tabi ((SVR_SOC_VER(svr) == SVR_P1022) || 88548f6a5c3SYork Sun (SVR_SOC_VER(svr) == SVR_P1013))) { 886fbc20aabSTimur Tabi fsl_sata_reg_t *reg; 887fbc20aabSTimur Tabi 888fbc20aabSTimur Tabi /* first SATA controller */ 889fbc20aabSTimur Tabi reg = (void *)CONFIG_SYS_MPC85xx_SATA1_ADDR; 890fbc20aabSTimur Tabi clrbits_le32(®->hcontrol, HCONTROL_ENTERPRISE_EN); 891fbc20aabSTimur Tabi 892fbc20aabSTimur Tabi /* second SATA controller */ 893fbc20aabSTimur Tabi reg = (void *)CONFIG_SYS_MPC85xx_SATA2_ADDR; 894fbc20aabSTimur Tabi clrbits_le32(®->hcontrol, HCONTROL_ENTERPRISE_EN); 895fbc20aabSTimur Tabi } 896fbc20aabSTimur Tabi #endif 897fbc20aabSTimur Tabi 898*f13c9156SAlexander Graf init_used_tlb_cams(); 899fbc20aabSTimur Tabi 900a47a12beSStefan Roese return 0; 901a47a12beSStefan Roese } 902a47a12beSStefan Roese 903a47a12beSStefan Roese void arch_preboot_os(void) 904a47a12beSStefan Roese { 905a47a12beSStefan Roese u32 msr; 906a47a12beSStefan Roese 907a47a12beSStefan Roese /* 908a47a12beSStefan Roese * We are changing interrupt offsets and are about to boot the OS so 909a47a12beSStefan Roese * we need to make sure we disable all async interrupts. EE is already 910a47a12beSStefan Roese * disabled by the time we get called. 911a47a12beSStefan Roese */ 912a47a12beSStefan Roese msr = mfmsr(); 9135344f7a2SPrabhakar Kushwaha msr &= ~(MSR_ME|MSR_CE); 914a47a12beSStefan Roese mtmsr(msr); 915a47a12beSStefan Roese } 916f54fe87aSKumar Gala 917f54fe87aSKumar Gala #if defined(CONFIG_CMD_SATA) && defined(CONFIG_FSL_SATA) 918f54fe87aSKumar Gala int sata_initialize(void) 919f54fe87aSKumar Gala { 920f54fe87aSKumar Gala if (is_serdes_configured(SATA1) || is_serdes_configured(SATA2)) 921f54fe87aSKumar Gala return __sata_initialize(); 922f54fe87aSKumar Gala 923f54fe87aSKumar Gala return 1; 924f54fe87aSKumar Gala } 925f54fe87aSKumar Gala #endif 926f9a33f1cSKumar Gala 927f9a33f1cSKumar Gala void cpu_secondary_init_r(void) 928f9a33f1cSKumar Gala { 9292a44efebSZhao Qiang #ifdef CONFIG_U_QE 9302a44efebSZhao Qiang uint qe_base = CONFIG_SYS_IMMR + 0x00140000; /* QE immr base */ 9312a44efebSZhao Qiang #elif defined CONFIG_QE 932f9a33f1cSKumar Gala uint qe_base = CONFIG_SYS_IMMR + 0x00080000; /* QE immr base */ 9332a44efebSZhao Qiang #endif 9342a44efebSZhao Qiang 9352a44efebSZhao Qiang #ifdef CONFIG_QE 936f9a33f1cSKumar Gala qe_init(qe_base); 937f9a33f1cSKumar Gala qe_reset(); 938f9a33f1cSKumar Gala #endif 939f9a33f1cSKumar Gala } 940