xref: /rk3399_rockchip-uboot/arch/powerpc/cpu/mpc85xx/cpu_init.c (revision fb4a2409b46c98672557bb07dec8e873bef1e23c)
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"
36fbc20aabSTimur Tabi 
37a47a12beSStefan Roese DECLARE_GLOBAL_DATA_PTR;
38a47a12beSStefan Roese 
399c641a87SSuresh Gupta #ifdef CONFIG_SYS_FSL_ERRATUM_A006261
409c641a87SSuresh Gupta void fsl_erratum_a006261_workaround(struct ccsr_usb_phy __iomem *usb_phy)
419c641a87SSuresh Gupta {
429c641a87SSuresh Gupta #ifdef CONFIG_SYS_FSL_USB_DUAL_PHY_ENABLE
439c641a87SSuresh Gupta 	u32 xcvrprg = in_be32(&usb_phy->port1.xcvrprg);
449c641a87SSuresh Gupta 
459c641a87SSuresh Gupta 	/* Increase Disconnect Threshold by 50mV */
469c641a87SSuresh Gupta 	xcvrprg &= ~CONFIG_SYS_FSL_USB_XCVRPRG_HS_DCNT_PROG_MASK |
479c641a87SSuresh Gupta 						INC_DCNT_THRESHOLD_50MV;
489c641a87SSuresh Gupta 	/* Enable programming of USB High speed Disconnect threshold */
499c641a87SSuresh Gupta 	xcvrprg |= CONFIG_SYS_FSL_USB_XCVRPRG_HS_DCNT_PROG_EN;
509c641a87SSuresh Gupta 	out_be32(&usb_phy->port1.xcvrprg, xcvrprg);
519c641a87SSuresh Gupta 
529c641a87SSuresh Gupta 	xcvrprg = in_be32(&usb_phy->port2.xcvrprg);
539c641a87SSuresh Gupta 	/* Increase Disconnect Threshold by 50mV */
549c641a87SSuresh Gupta 	xcvrprg &= ~CONFIG_SYS_FSL_USB_XCVRPRG_HS_DCNT_PROG_MASK |
559c641a87SSuresh Gupta 						INC_DCNT_THRESHOLD_50MV;
569c641a87SSuresh Gupta 	/* Enable programming of USB High speed Disconnect threshold */
579c641a87SSuresh Gupta 	xcvrprg |= CONFIG_SYS_FSL_USB_XCVRPRG_HS_DCNT_PROG_EN;
589c641a87SSuresh Gupta 	out_be32(&usb_phy->port2.xcvrprg, xcvrprg);
599c641a87SSuresh Gupta #else
609c641a87SSuresh Gupta 
619c641a87SSuresh Gupta 	u32 temp = 0;
629c641a87SSuresh Gupta 	u32 status = in_be32(&usb_phy->status1);
639c641a87SSuresh Gupta 
649c641a87SSuresh Gupta 	u32 squelch_prog_rd_0_2 =
659c641a87SSuresh Gupta 		(status >> CONFIG_SYS_FSL_USB_SQUELCH_PROG_RD_0)
669c641a87SSuresh Gupta 			& CONFIG_SYS_FSL_USB_SQUELCH_PROG_MASK;
679c641a87SSuresh Gupta 
689c641a87SSuresh Gupta 	u32 squelch_prog_rd_3_5 =
699c641a87SSuresh Gupta 		(status >> CONFIG_SYS_FSL_USB_SQUELCH_PROG_RD_3)
709c641a87SSuresh Gupta 			& CONFIG_SYS_FSL_USB_SQUELCH_PROG_MASK;
719c641a87SSuresh Gupta 
729c641a87SSuresh Gupta 	setbits_be32(&usb_phy->config1,
739c641a87SSuresh Gupta 		     CONFIG_SYS_FSL_USB_HS_DISCNCT_INC);
749c641a87SSuresh Gupta 	setbits_be32(&usb_phy->config2,
759c641a87SSuresh Gupta 		     CONFIG_SYS_FSL_USB_RX_AUTO_CAL_RD_WR_SEL);
769c641a87SSuresh Gupta 
779c641a87SSuresh Gupta 	temp = squelch_prog_rd_0_2 << CONFIG_SYS_FSL_USB_SQUELCH_PROG_WR_0;
789c641a87SSuresh Gupta 	out_be32(&usb_phy->config2, in_be32(&usb_phy->config2) | temp);
799c641a87SSuresh Gupta 
809c641a87SSuresh Gupta 	temp = squelch_prog_rd_3_5 << CONFIG_SYS_FSL_USB_SQUELCH_PROG_WR_3;
819c641a87SSuresh Gupta 	out_be32(&usb_phy->config2, in_be32(&usb_phy->config2) | temp);
829c641a87SSuresh Gupta #endif
839c641a87SSuresh Gupta }
849c641a87SSuresh Gupta #endif
859c641a87SSuresh Gupta 
869c641a87SSuresh Gupta 
87a47a12beSStefan Roese #ifdef CONFIG_QE
88a47a12beSStefan Roese extern qe_iop_conf_t qe_iop_conf_tab[];
89a47a12beSStefan Roese extern void qe_config_iopin(u8 port, u8 pin, int dir,
90a47a12beSStefan Roese 				int open_drain, int assign);
91a47a12beSStefan Roese extern void qe_init(uint qe_base);
92a47a12beSStefan Roese extern void qe_reset(void);
93a47a12beSStefan Roese 
94a47a12beSStefan Roese static void config_qe_ioports(void)
95a47a12beSStefan Roese {
96a47a12beSStefan Roese 	u8      port, pin;
97a47a12beSStefan Roese 	int     dir, open_drain, assign;
98a47a12beSStefan Roese 	int     i;
99a47a12beSStefan Roese 
100a47a12beSStefan Roese 	for (i = 0; qe_iop_conf_tab[i].assign != QE_IOP_TAB_END; i++) {
101a47a12beSStefan Roese 		port		= qe_iop_conf_tab[i].port;
102a47a12beSStefan Roese 		pin		= qe_iop_conf_tab[i].pin;
103a47a12beSStefan Roese 		dir		= qe_iop_conf_tab[i].dir;
104a47a12beSStefan Roese 		open_drain	= qe_iop_conf_tab[i].open_drain;
105a47a12beSStefan Roese 		assign		= qe_iop_conf_tab[i].assign;
106a47a12beSStefan Roese 		qe_config_iopin(port, pin, dir, open_drain, assign);
107a47a12beSStefan Roese 	}
108a47a12beSStefan Roese }
109a47a12beSStefan Roese #endif
110a47a12beSStefan Roese 
111a47a12beSStefan Roese #ifdef CONFIG_CPM2
112a47a12beSStefan Roese void config_8560_ioports (volatile ccsr_cpm_t * cpm)
113a47a12beSStefan Roese {
114a47a12beSStefan Roese 	int portnum;
115a47a12beSStefan Roese 
116a47a12beSStefan Roese 	for (portnum = 0; portnum < 4; portnum++) {
117a47a12beSStefan Roese 		uint pmsk = 0,
118a47a12beSStefan Roese 		     ppar = 0,
119a47a12beSStefan Roese 		     psor = 0,
120a47a12beSStefan Roese 		     pdir = 0,
121a47a12beSStefan Roese 		     podr = 0,
122a47a12beSStefan Roese 		     pdat = 0;
123a47a12beSStefan Roese 		iop_conf_t *iopc = (iop_conf_t *) & iop_conf_tab[portnum][0];
124a47a12beSStefan Roese 		iop_conf_t *eiopc = iopc + 32;
125a47a12beSStefan Roese 		uint msk = 1;
126a47a12beSStefan Roese 
127a47a12beSStefan Roese 		/*
128a47a12beSStefan Roese 		 * NOTE:
129a47a12beSStefan Roese 		 * index 0 refers to pin 31,
130a47a12beSStefan Roese 		 * index 31 refers to pin 0
131a47a12beSStefan Roese 		 */
132a47a12beSStefan Roese 		while (iopc < eiopc) {
133a47a12beSStefan Roese 			if (iopc->conf) {
134a47a12beSStefan Roese 				pmsk |= msk;
135a47a12beSStefan Roese 				if (iopc->ppar)
136a47a12beSStefan Roese 					ppar |= msk;
137a47a12beSStefan Roese 				if (iopc->psor)
138a47a12beSStefan Roese 					psor |= msk;
139a47a12beSStefan Roese 				if (iopc->pdir)
140a47a12beSStefan Roese 					pdir |= msk;
141a47a12beSStefan Roese 				if (iopc->podr)
142a47a12beSStefan Roese 					podr |= msk;
143a47a12beSStefan Roese 				if (iopc->pdat)
144a47a12beSStefan Roese 					pdat |= msk;
145a47a12beSStefan Roese 			}
146a47a12beSStefan Roese 
147a47a12beSStefan Roese 			msk <<= 1;
148a47a12beSStefan Roese 			iopc++;
149a47a12beSStefan Roese 		}
150a47a12beSStefan Roese 
151a47a12beSStefan Roese 		if (pmsk != 0) {
152a47a12beSStefan Roese 			volatile ioport_t *iop = ioport_addr (cpm, portnum);
153a47a12beSStefan Roese 			uint tpmsk = ~pmsk;
154a47a12beSStefan Roese 
155a47a12beSStefan Roese 			/*
156a47a12beSStefan Roese 			 * the (somewhat confused) paragraph at the
157a47a12beSStefan Roese 			 * bottom of page 35-5 warns that there might
158a47a12beSStefan Roese 			 * be "unknown behaviour" when programming
159a47a12beSStefan Roese 			 * PSORx and PDIRx, if PPARx = 1, so I
160a47a12beSStefan Roese 			 * decided this meant I had to disable the
161a47a12beSStefan Roese 			 * dedicated function first, and enable it
162a47a12beSStefan Roese 			 * last.
163a47a12beSStefan Roese 			 */
164a47a12beSStefan Roese 			iop->ppar &= tpmsk;
165a47a12beSStefan Roese 			iop->psor = (iop->psor & tpmsk) | psor;
166a47a12beSStefan Roese 			iop->podr = (iop->podr & tpmsk) | podr;
167a47a12beSStefan Roese 			iop->pdat = (iop->pdat & tpmsk) | pdat;
168a47a12beSStefan Roese 			iop->pdir = (iop->pdir & tpmsk) | pdir;
169a47a12beSStefan Roese 			iop->ppar |= ppar;
170a47a12beSStefan Roese 		}
171a47a12beSStefan Roese 	}
172a47a12beSStefan Roese }
173a47a12beSStefan Roese #endif
174a47a12beSStefan Roese 
1756aba33e9SKumar Gala #ifdef CONFIG_SYS_FSL_CPC
176*fb4a2409SAneesh Bansal #if defined(CONFIG_RAMBOOT_PBL) || defined(CONFIG_SYS_CPC_REINIT_F)
177*fb4a2409SAneesh Bansal static void disable_cpc_sram(void)
1786aba33e9SKumar Gala {
1796aba33e9SKumar Gala 	int i;
1806aba33e9SKumar Gala 
1816aba33e9SKumar Gala 	cpc_corenet_t *cpc = (cpc_corenet_t *)CONFIG_SYS_FSL_CPC_ADDR;
1826aba33e9SKumar Gala 
1836aba33e9SKumar Gala 	for (i = 0; i < CONFIG_SYS_NUM_CPC; i++, cpc++) {
1842a9fab82SShaohui Xie 		if (in_be32(&cpc->cpcsrcr0) & CPC_SRCR0_SRAMEN) {
1852a9fab82SShaohui Xie 			/* find and disable LAW of SRAM */
1862a9fab82SShaohui Xie 			struct law_entry law = find_law(CONFIG_SYS_INIT_L3_ADDR);
1872a9fab82SShaohui Xie 
1882a9fab82SShaohui Xie 			if (law.index == -1) {
1892a9fab82SShaohui Xie 				printf("\nFatal error happened\n");
1902a9fab82SShaohui Xie 				return;
1912a9fab82SShaohui Xie 			}
1922a9fab82SShaohui Xie 			disable_law(law.index);
1932a9fab82SShaohui Xie 
1942a9fab82SShaohui Xie 			clrbits_be32(&cpc->cpchdbcr0, CPC_HDBCR0_CDQ_SPEC_DIS);
1952a9fab82SShaohui Xie 			out_be32(&cpc->cpccsr0, 0);
1962a9fab82SShaohui Xie 			out_be32(&cpc->cpcsrcr0, 0);
1972a9fab82SShaohui Xie 		}
198*fb4a2409SAneesh Bansal 	}
199*fb4a2409SAneesh Bansal }
2002a9fab82SShaohui Xie #endif
2016aba33e9SKumar Gala 
202*fb4a2409SAneesh Bansal static void enable_cpc(void)
203*fb4a2409SAneesh Bansal {
204*fb4a2409SAneesh Bansal 	int i;
205*fb4a2409SAneesh Bansal 	u32 size = 0;
206*fb4a2409SAneesh Bansal 
207*fb4a2409SAneesh Bansal 	cpc_corenet_t *cpc = (cpc_corenet_t *)CONFIG_SYS_FSL_CPC_ADDR;
208*fb4a2409SAneesh Bansal 
209*fb4a2409SAneesh Bansal 	for (i = 0; i < CONFIG_SYS_NUM_CPC; i++, cpc++) {
210*fb4a2409SAneesh Bansal 		u32 cpccfg0 = in_be32(&cpc->cpccfg0);
211*fb4a2409SAneesh Bansal 		size += CPC_CFG0_SZ_K(cpccfg0);
212*fb4a2409SAneesh Bansal 
2131d2c2a62SKumar Gala #ifdef CONFIG_SYS_FSL_ERRATUM_CPC_A002
2141d2c2a62SKumar Gala 		setbits_be32(&cpc->cpchdbcr0, CPC_HDBCR0_TAG_ECC_SCRUB_DIS);
2151d2c2a62SKumar Gala #endif
216868da593SKumar Gala #ifdef CONFIG_SYS_FSL_ERRATUM_CPC_A003
217868da593SKumar Gala 		setbits_be32(&cpc->cpchdbcr0, CPC_HDBCR0_DATA_ECC_SCRUB_DIS);
218868da593SKumar Gala #endif
21982125192SScott Wood #ifdef CONFIG_SYS_FSL_ERRATUM_A006593
22082125192SScott Wood 		setbits_be32(&cpc->cpchdbcr0, 1 << (31 - 21));
22182125192SScott Wood #endif
222133fbfa9SYork Sun #ifdef CONFIG_SYS_FSL_ERRATUM_A006379
223133fbfa9SYork Sun 		if (has_erratum_a006379()) {
224133fbfa9SYork Sun 			setbits_be32(&cpc->cpchdbcr0,
225133fbfa9SYork Sun 				     CPC_HDBCR0_SPLRU_LEVEL_EN);
226133fbfa9SYork Sun 		}
227133fbfa9SYork Sun #endif
2281d2c2a62SKumar Gala 
2296aba33e9SKumar Gala 		out_be32(&cpc->cpccsr0, CPC_CSR0_CE | CPC_CSR0_PE);
2306aba33e9SKumar Gala 		/* Read back to sync write */
2316aba33e9SKumar Gala 		in_be32(&cpc->cpccsr0);
2326aba33e9SKumar Gala 
2336aba33e9SKumar Gala 	}
2346aba33e9SKumar Gala 
2352f848f97SShruti Kanetkar 	puts("Corenet Platform Cache: ");
2362f848f97SShruti Kanetkar 	print_size(size * 1024, " enabled\n");
2376aba33e9SKumar Gala }
2386aba33e9SKumar Gala 
239e56143e5SKim Phillips static void invalidate_cpc(void)
2406aba33e9SKumar Gala {
2416aba33e9SKumar Gala 	int i;
2426aba33e9SKumar Gala 	cpc_corenet_t *cpc = (cpc_corenet_t *)CONFIG_SYS_FSL_CPC_ADDR;
2436aba33e9SKumar Gala 
2446aba33e9SKumar Gala 	for (i = 0; i < CONFIG_SYS_NUM_CPC; i++, cpc++) {
2452a9fab82SShaohui Xie 		/* skip CPC when it used as all SRAM */
2462a9fab82SShaohui Xie 		if (in_be32(&cpc->cpcsrcr0) & CPC_SRCR0_SRAMEN)
2472a9fab82SShaohui Xie 			continue;
2486aba33e9SKumar Gala 		/* Flash invalidate the CPC and clear all the locks */
2496aba33e9SKumar Gala 		out_be32(&cpc->cpccsr0, CPC_CSR0_FI | CPC_CSR0_LFC);
2506aba33e9SKumar Gala 		while (in_be32(&cpc->cpccsr0) & (CPC_CSR0_FI | CPC_CSR0_LFC))
2516aba33e9SKumar Gala 			;
2526aba33e9SKumar Gala 	}
2536aba33e9SKumar Gala }
2546aba33e9SKumar Gala #else
2556aba33e9SKumar Gala #define enable_cpc()
2566aba33e9SKumar Gala #define invalidate_cpc()
2576aba33e9SKumar Gala #endif /* CONFIG_SYS_FSL_CPC */
2586aba33e9SKumar Gala 
259a47a12beSStefan Roese /*
260a47a12beSStefan Roese  * Breathe some life into the CPU...
261a47a12beSStefan Roese  *
262a47a12beSStefan Roese  * Set up the memory map
263a47a12beSStefan Roese  * initialize a bunch of registers
264a47a12beSStefan Roese  */
265a47a12beSStefan Roese 
266a47a12beSStefan Roese #ifdef CONFIG_FSL_CORENET
267a47a12beSStefan Roese static void corenet_tb_init(void)
268a47a12beSStefan Roese {
269a47a12beSStefan Roese 	volatile ccsr_rcpm_t *rcpm =
270a47a12beSStefan Roese 		(void *)(CONFIG_SYS_FSL_CORENET_RCPM_ADDR);
271a47a12beSStefan Roese 	volatile ccsr_pic_t *pic =
272680c613aSKim Phillips 		(void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
273a47a12beSStefan Roese 	u32 whoami = in_be32(&pic->whoami);
274a47a12beSStefan Roese 
275a47a12beSStefan Roese 	/* Enable the timebase register for this core */
276a47a12beSStefan Roese 	out_be32(&rcpm->ctbenrl, (1 << whoami));
277a47a12beSStefan Roese }
278a47a12beSStefan Roese #endif
279a47a12beSStefan Roese 
280a47a12beSStefan Roese void cpu_init_f (void)
281a47a12beSStefan Roese {
282a47a12beSStefan Roese 	extern void m8560_cpm_reset (void);
283f110fe94SStephen George #ifdef CONFIG_SYS_DCSRBAR_PHYS
284f110fe94SStephen George 	ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
285f110fe94SStephen George #endif
2867065b7d4SRuchika Gupta #if defined(CONFIG_SECURE_BOOT)
2877065b7d4SRuchika Gupta 	struct law_entry law;
2887065b7d4SRuchika Gupta #endif
289a47a12beSStefan Roese #ifdef CONFIG_MPC8548
290a47a12beSStefan Roese 	ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR);
291a47a12beSStefan Roese 	uint svr = get_svr();
292a47a12beSStefan Roese 
293a47a12beSStefan Roese 	/*
294a47a12beSStefan Roese 	 * CPU2 errata workaround: A core hang possible while executing
295a47a12beSStefan Roese 	 * a msync instruction and a snoopable transaction from an I/O
296a47a12beSStefan Roese 	 * master tagged to make quick forward progress is present.
297a47a12beSStefan Roese 	 * Fixed in silicon rev 2.1.
298a47a12beSStefan Roese 	 */
299a47a12beSStefan Roese 	if ((SVR_MAJ(svr) == 1) || ((SVR_MAJ(svr) == 2 && SVR_MIN(svr) == 0x0)))
300a47a12beSStefan Roese 		out_be32(&ecm->eebpcr, in_be32(&ecm->eebpcr) | (1 << 16));
301a47a12beSStefan Roese #endif
302a47a12beSStefan Roese 
303a47a12beSStefan Roese 	disable_tlb(14);
304a47a12beSStefan Roese 	disable_tlb(15);
305a47a12beSStefan Roese 
3067065b7d4SRuchika Gupta #if defined(CONFIG_SECURE_BOOT)
3077065b7d4SRuchika Gupta 	/* Disable the LAW created for NOR flash by the PBI commands */
3087065b7d4SRuchika Gupta 	law = find_law(CONFIG_SYS_PBI_FLASH_BASE);
3097065b7d4SRuchika Gupta 	if (law.index != -1)
3107065b7d4SRuchika Gupta 		disable_law(law.index);
311*fb4a2409SAneesh Bansal 
312*fb4a2409SAneesh Bansal #if defined(CONFIG_SYS_CPC_REINIT_F)
313*fb4a2409SAneesh Bansal 	disable_cpc_sram();
314*fb4a2409SAneesh Bansal #endif
3157065b7d4SRuchika Gupta #endif
3167065b7d4SRuchika Gupta 
317a47a12beSStefan Roese #ifdef CONFIG_CPM2
318a47a12beSStefan Roese 	config_8560_ioports((ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR);
319a47a12beSStefan Roese #endif
320a47a12beSStefan Roese 
321f51cdaf1SBecky Bruce        init_early_memctl_regs();
322a47a12beSStefan Roese 
323a47a12beSStefan Roese #if defined(CONFIG_CPM2)
324a47a12beSStefan Roese 	m8560_cpm_reset();
325a47a12beSStefan Roese #endif
326a47a12beSStefan Roese #ifdef CONFIG_QE
327a47a12beSStefan Roese 	/* Config QE ioports */
328a47a12beSStefan Roese 	config_qe_ioports();
329a47a12beSStefan Roese #endif
330a47a12beSStefan Roese #if defined(CONFIG_FSL_DMA)
331a47a12beSStefan Roese 	dma_init();
332a47a12beSStefan Roese #endif
333a47a12beSStefan Roese #ifdef CONFIG_FSL_CORENET
334a47a12beSStefan Roese 	corenet_tb_init();
335a47a12beSStefan Roese #endif
336a47a12beSStefan Roese 	init_used_tlb_cams();
3376aba33e9SKumar Gala 
3386aba33e9SKumar Gala 	/* Invalidate the CPC before DDR gets enabled */
3396aba33e9SKumar Gala 	invalidate_cpc();
340f110fe94SStephen George 
341f110fe94SStephen George  #ifdef CONFIG_SYS_DCSRBAR_PHYS
342f110fe94SStephen George 	/* set DCSRCR so that DCSR space is 1G */
343f110fe94SStephen George 	setbits_be32(&gur->dcsrcr, FSL_CORENET_DCSR_SZ_1G);
344f110fe94SStephen George 	in_be32(&gur->dcsrcr);
345f110fe94SStephen George #endif
346f110fe94SStephen George 
347a47a12beSStefan Roese }
348a47a12beSStefan Roese 
34935079aa9SKumar Gala /* Implement a dummy function for those platforms w/o SERDES */
35035079aa9SKumar Gala static void __fsl_serdes__init(void)
35135079aa9SKumar Gala {
35235079aa9SKumar Gala 	return ;
35335079aa9SKumar Gala }
35435079aa9SKumar Gala __attribute__((weak, alias("__fsl_serdes__init"))) void fsl_serdes_init(void);
355a47a12beSStefan Roese 
356e9827468SPrabhakar Kushwaha #if defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2) && defined(CONFIG_E6500)
3576d2b9da1SYork Sun int enable_cluster_l2(void)
3586d2b9da1SYork Sun {
3596d2b9da1SYork Sun 	int i = 0;
3606d2b9da1SYork Sun 	u32 cluster;
3616d2b9da1SYork Sun 	ccsr_gur_t *gur = (void __iomem *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
3626d2b9da1SYork Sun 	struct ccsr_cluster_l2 __iomem *l2cache;
3636d2b9da1SYork Sun 
3646d2b9da1SYork Sun 	cluster = in_be32(&gur->tp_cluster[i].lower);
3656d2b9da1SYork Sun 	if (cluster & TP_CLUSTER_EOC)
3666d2b9da1SYork Sun 		return 0;
3676d2b9da1SYork Sun 
3686d2b9da1SYork Sun 	/* The first cache has already been set up, so skip it */
3696d2b9da1SYork Sun 	i++;
3706d2b9da1SYork Sun 
3716d2b9da1SYork Sun 	/* Look through the remaining clusters, and set up their caches */
3726d2b9da1SYork Sun 	do {
373db9a8070SPrabhakar Kushwaha 		int j, cluster_valid = 0;
374db9a8070SPrabhakar Kushwaha 
3756d2b9da1SYork Sun 		l2cache = (void __iomem *)(CONFIG_SYS_FSL_CLUSTER_1_L2 + i * 0x40000);
376db9a8070SPrabhakar Kushwaha 
3776d2b9da1SYork Sun 		cluster = in_be32(&gur->tp_cluster[i].lower);
3786d2b9da1SYork Sun 
379db9a8070SPrabhakar Kushwaha 		/* check that at least one core/accel is enabled in cluster */
380db9a8070SPrabhakar Kushwaha 		for (j = 0; j < 4; j++) {
381db9a8070SPrabhakar Kushwaha 			u32 idx = (cluster >> (j*8)) & TP_CLUSTER_INIT_MASK;
382db9a8070SPrabhakar Kushwaha 			u32 type = in_be32(&gur->tp_ityp[idx]);
383db9a8070SPrabhakar Kushwaha 
384db9a8070SPrabhakar Kushwaha 			if (type & TP_ITYP_AV)
385db9a8070SPrabhakar Kushwaha 				cluster_valid = 1;
386db9a8070SPrabhakar Kushwaha 		}
387db9a8070SPrabhakar Kushwaha 
388db9a8070SPrabhakar Kushwaha 		if (cluster_valid) {
3896d2b9da1SYork Sun 			/* set stash ID to (cluster) * 2 + 32 + 1 */
3906d2b9da1SYork Sun 			clrsetbits_be32(&l2cache->l2csr1, 0xff, 32 + i * 2 + 1);
3916d2b9da1SYork Sun 
3926d2b9da1SYork Sun 			printf("enable l2 for cluster %d %p\n", i, l2cache);
3936d2b9da1SYork Sun 
3946d2b9da1SYork Sun 			out_be32(&l2cache->l2csr0, L2CSR0_L2FI|L2CSR0_L2LFC);
395db9a8070SPrabhakar Kushwaha 			while ((in_be32(&l2cache->l2csr0)
396db9a8070SPrabhakar Kushwaha 				& (L2CSR0_L2FI|L2CSR0_L2LFC)) != 0)
3976d2b9da1SYork Sun 					;
3989cd95ac7SJames Yang 			out_be32(&l2cache->l2csr0, L2CSR0_L2E|L2CSR0_L2PE|L2CSR0_L2REP_MODE);
399db9a8070SPrabhakar Kushwaha 		}
4006d2b9da1SYork Sun 		i++;
4016d2b9da1SYork Sun 	} while (!(cluster & TP_CLUSTER_EOC));
4026d2b9da1SYork Sun 
4036d2b9da1SYork Sun 	return 0;
4046d2b9da1SYork Sun }
4056d2b9da1SYork Sun #endif
4066d2b9da1SYork Sun 
407a47a12beSStefan Roese /*
408a47a12beSStefan Roese  * Initialize L2 as cache.
409a47a12beSStefan Roese  *
410a47a12beSStefan Roese  * The newer 8548, etc, parts have twice as much cache, but
411a47a12beSStefan Roese  * use the same bit-encoding as the older 8555, etc, parts.
412a47a12beSStefan Roese  *
413a47a12beSStefan Roese  */
414a47a12beSStefan Roese int cpu_init_r(void)
415a47a12beSStefan Roese {
416fbc20aabSTimur Tabi 	__maybe_unused u32 svr = get_svr();
4173f0202edSLan Chunhe #ifdef CONFIG_SYS_LBC_LCRR
4186d2b9da1SYork Sun 	fsl_lbc_t *lbc = (void __iomem *)LBC_BASE_ADDR;
4196d2b9da1SYork Sun #endif
4206d2b9da1SYork Sun #ifdef CONFIG_L2_CACHE
4216d2b9da1SYork Sun 	ccsr_l2cache_t *l2cache = (void __iomem *)CONFIG_SYS_MPC85xx_L2_ADDR;
422e9827468SPrabhakar Kushwaha #elif defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2) && defined(CONFIG_E6500)
4236d2b9da1SYork Sun 	struct ccsr_cluster_l2 * l2cache = (void __iomem *)CONFIG_SYS_FSL_CLUSTER_1_L2;
4243f0202edSLan Chunhe #endif
425afbfdf54SYork Sun #if defined(CONFIG_PPC_SPINTABLE_COMPATIBLE) && defined(CONFIG_MP)
4262a5fcb83SYork Sun 	extern int spin_table_compat;
4272a5fcb83SYork Sun 	const char *spin;
4282a5fcb83SYork Sun #endif
429424bf942SShengzhou Liu #ifdef CONFIG_SYS_FSL_ERRATUM_SEC_A003571
430424bf942SShengzhou Liu 	ccsr_sec_t __iomem *sec = (void *)CONFIG_SYS_FSL_SEC_ADDR;
431424bf942SShengzhou Liu #endif
4325e23ab0aSYork Sun #if defined(CONFIG_SYS_P4080_ERRATUM_CPU22) || \
4335e23ab0aSYork Sun 	defined(CONFIG_SYS_FSL_ERRATUM_NMG_CPU_A011)
4345e23ab0aSYork Sun 	/*
43557125f22SYork Sun 	 * CPU22 and NMG_CPU_A011 share the same workaround.
4365e23ab0aSYork Sun 	 * CPU22 applies to P4080 rev 1.0, 2.0, fixed in 3.0
4375e23ab0aSYork Sun 	 * NMG_CPU_A011 applies to P4080 rev 1.0, 2.0, fixed in 3.0
43857125f22SYork Sun 	 * also applies to P3041 rev 1.0, 1.1, P2041 rev 1.0, 1.1, both
43957125f22SYork Sun 	 * fixed in 2.0. NMG_CPU_A011 is activated by default and can
44057125f22SYork Sun 	 * be disabled by hwconfig with syntax:
44157125f22SYork Sun 	 *
44257125f22SYork Sun 	 * fsl_cpu_a011:disable
4435e23ab0aSYork Sun 	 */
44457125f22SYork Sun 	extern int enable_cpu_a011_workaround;
44557125f22SYork Sun #ifdef CONFIG_SYS_P4080_ERRATUM_CPU22
44657125f22SYork Sun 	enable_cpu_a011_workaround = (SVR_MAJ(svr) < 3);
44757125f22SYork Sun #else
44857125f22SYork Sun 	char buffer[HWCONFIG_BUFFER_SIZE];
44957125f22SYork Sun 	char *buf = NULL;
45057125f22SYork Sun 	int n, res;
45157125f22SYork Sun 
45257125f22SYork Sun 	n = getenv_f("hwconfig", buffer, sizeof(buffer));
45357125f22SYork Sun 	if (n > 0)
45457125f22SYork Sun 		buf = buffer;
45557125f22SYork Sun 
45657125f22SYork Sun 	res = hwconfig_arg_cmp_f("fsl_cpu_a011", "disable", buf);
45757125f22SYork Sun 	if (res > 0)
45857125f22SYork Sun 		enable_cpu_a011_workaround = 0;
45957125f22SYork Sun 	else {
46057125f22SYork Sun 		if (n >= HWCONFIG_BUFFER_SIZE) {
46157125f22SYork Sun 			printf("fsl_cpu_a011 was not found. hwconfig variable "
46257125f22SYork Sun 				"may be too long\n");
46357125f22SYork Sun 		}
46457125f22SYork Sun 		enable_cpu_a011_workaround =
46557125f22SYork Sun 			(SVR_SOC_VER(svr) == SVR_P4080 && SVR_MAJ(svr) < 3) ||
46657125f22SYork Sun 			(SVR_SOC_VER(svr) != SVR_P4080 && SVR_MAJ(svr) < 2);
46757125f22SYork Sun 	}
46857125f22SYork Sun #endif
46957125f22SYork Sun 	if (enable_cpu_a011_workaround) {
470fd3c9befSKumar Gala 		flush_dcache();
471fd3c9befSKumar Gala 		mtspr(L1CSR2, (mfspr(L1CSR2) | L1CSR2_DCWS));
472fd3c9befSKumar Gala 		sync();
4731e9ea85fSYork Sun 	}
474fd3c9befSKumar Gala #endif
475d217a9adSYork Sun #ifdef CONFIG_SYS_FSL_ERRATUM_A005812
476d217a9adSYork Sun 	/*
477d217a9adSYork Sun 	 * A-005812 workaround sets bit 32 of SPR 976 for SoCs running
478d217a9adSYork Sun 	 * in write shadow mode. Checking DCWS before setting SPR 976.
479d217a9adSYork Sun 	 */
480d217a9adSYork Sun 	if (mfspr(L1CSR2) & L1CSR2_DCWS)
481d217a9adSYork Sun 		mtspr(SPRN_HDBCR0, (mfspr(SPRN_HDBCR0) | 0x80000000));
482d217a9adSYork Sun #endif
483fd3c9befSKumar Gala 
484afbfdf54SYork Sun #if defined(CONFIG_PPC_SPINTABLE_COMPATIBLE) && defined(CONFIG_MP)
4852a5fcb83SYork Sun 	spin = getenv("spin_table_compat");
4862a5fcb83SYork Sun 	if (spin && (*spin == 'n'))
4872a5fcb83SYork Sun 		spin_table_compat = 0;
4882a5fcb83SYork Sun 	else
4892a5fcb83SYork Sun 		spin_table_compat = 1;
4902a5fcb83SYork Sun #endif
4912a5fcb83SYork Sun 
492a47a12beSStefan Roese 	puts ("L2:    ");
493a47a12beSStefan Roese 
494a47a12beSStefan Roese #if defined(CONFIG_L2_CACHE)
495a47a12beSStefan Roese 	volatile uint cache_ctl;
496fbc20aabSTimur Tabi 	uint ver;
497a47a12beSStefan Roese 	u32 l2siz_field;
498a47a12beSStefan Roese 
499a47a12beSStefan Roese 	ver = SVR_SOC_VER(svr);
500a47a12beSStefan Roese 
501a47a12beSStefan Roese 	asm("msync;isync");
502a47a12beSStefan Roese 	cache_ctl = l2cache->l2ctl;
503a47a12beSStefan Roese 
504a47a12beSStefan Roese #if defined(CONFIG_SYS_RAMBOOT) && defined(CONFIG_SYS_INIT_L2_ADDR)
505a47a12beSStefan Roese 	if (cache_ctl & MPC85xx_L2CTL_L2E) {
506a47a12beSStefan Roese 		/* Clear L2 SRAM memory-mapped base address */
507a47a12beSStefan Roese 		out_be32(&l2cache->l2srbar0, 0x0);
508a47a12beSStefan Roese 		out_be32(&l2cache->l2srbar1, 0x0);
509a47a12beSStefan Roese 
510a47a12beSStefan Roese 		/* set MBECCDIS=0, SBECCDIS=0 */
511a47a12beSStefan Roese 		clrbits_be32(&l2cache->l2errdis,
512a47a12beSStefan Roese 				(MPC85xx_L2ERRDIS_MBECC |
513a47a12beSStefan Roese 				 MPC85xx_L2ERRDIS_SBECC));
514a47a12beSStefan Roese 
515a47a12beSStefan Roese 		/* set L2E=0, L2SRAM=0 */
516a47a12beSStefan Roese 		clrbits_be32(&l2cache->l2ctl,
517a47a12beSStefan Roese 				(MPC85xx_L2CTL_L2E |
518a47a12beSStefan Roese 				 MPC85xx_L2CTL_L2SRAM_ENTIRE));
519a47a12beSStefan Roese 	}
520a47a12beSStefan Roese #endif
521a47a12beSStefan Roese 
522a47a12beSStefan Roese 	l2siz_field = (cache_ctl >> 28) & 0x3;
523a47a12beSStefan Roese 
524a47a12beSStefan Roese 	switch (l2siz_field) {
525a47a12beSStefan Roese 	case 0x0:
526a47a12beSStefan Roese 		printf(" unknown size (0x%08x)\n", cache_ctl);
527a47a12beSStefan Roese 		return -1;
528a47a12beSStefan Roese 		break;
529a47a12beSStefan Roese 	case 0x1:
530a47a12beSStefan Roese 		if (ver == SVR_8540 || ver == SVR_8560   ||
53148f6a5c3SYork Sun 		    ver == SVR_8541 || ver == SVR_8555) {
5326b44d9e5SShruti Kanetkar 			puts("128 KiB ");
5336b44d9e5SShruti Kanetkar 			/* set L2E=1, L2I=1, & L2BLKSZ=1 (128 KiBibyte) */
534a47a12beSStefan Roese 			cache_ctl = 0xc4000000;
535a47a12beSStefan Roese 		} else {
5366b44d9e5SShruti Kanetkar 			puts("256 KiB ");
537a47a12beSStefan Roese 			cache_ctl = 0xc0000000; /* set L2E=1, L2I=1, & L2SRAM=0 */
538a47a12beSStefan Roese 		}
539a47a12beSStefan Roese 		break;
540a47a12beSStefan Roese 	case 0x2:
541a47a12beSStefan Roese 		if (ver == SVR_8540 || ver == SVR_8560   ||
54248f6a5c3SYork Sun 		    ver == SVR_8541 || ver == SVR_8555) {
5436b44d9e5SShruti Kanetkar 			puts("256 KiB ");
5446b44d9e5SShruti Kanetkar 			/* set L2E=1, L2I=1, & L2BLKSZ=2 (256 KiBibyte) */
545a47a12beSStefan Roese 			cache_ctl = 0xc8000000;
546a47a12beSStefan Roese 		} else {
5476b44d9e5SShruti Kanetkar 			puts("512 KiB ");
548a47a12beSStefan Roese 			/* set L2E=1, L2I=1, & L2SRAM=0 */
549a47a12beSStefan Roese 			cache_ctl = 0xc0000000;
550a47a12beSStefan Roese 		}
551a47a12beSStefan Roese 		break;
552a47a12beSStefan Roese 	case 0x3:
5536b44d9e5SShruti Kanetkar 		puts("1024 KiB ");
554a47a12beSStefan Roese 		/* set L2E=1, L2I=1, & L2SRAM=0 */
555a47a12beSStefan Roese 		cache_ctl = 0xc0000000;
556a47a12beSStefan Roese 		break;
557a47a12beSStefan Roese 	}
558a47a12beSStefan Roese 
559a47a12beSStefan Roese 	if (l2cache->l2ctl & MPC85xx_L2CTL_L2E) {
560a47a12beSStefan Roese 		puts("already enabled");
561888279b5SHaiying Wang #if defined(CONFIG_SYS_INIT_L2_ADDR) && defined(CONFIG_SYS_FLASH_BASE)
562e4c9a35dSKumar Gala 		u32 l2srbar = l2cache->l2srbar0;
563a47a12beSStefan Roese 		if (l2cache->l2ctl & MPC85xx_L2CTL_L2SRAM_ENTIRE
564a47a12beSStefan Roese 				&& l2srbar >= CONFIG_SYS_FLASH_BASE) {
565a47a12beSStefan Roese 			l2srbar = CONFIG_SYS_INIT_L2_ADDR;
566a47a12beSStefan Roese 			l2cache->l2srbar0 = l2srbar;
5679a511bd6SScott Wood 			printf(", moving to 0x%08x", CONFIG_SYS_INIT_L2_ADDR);
568a47a12beSStefan Roese 		}
569a47a12beSStefan Roese #endif /* CONFIG_SYS_INIT_L2_ADDR */
570a47a12beSStefan Roese 		puts("\n");
571a47a12beSStefan Roese 	} else {
572a47a12beSStefan Roese 		asm("msync;isync");
573a47a12beSStefan Roese 		l2cache->l2ctl = cache_ctl; /* invalidate & enable */
574a47a12beSStefan Roese 		asm("msync;isync");
575a47a12beSStefan Roese 		puts("enabled\n");
576a47a12beSStefan Roese 	}
577a47a12beSStefan Roese #elif defined(CONFIG_BACKSIDE_L2_CACHE)
57848f6a5c3SYork Sun 	if (SVR_SOC_VER(svr) == SVR_P2040) {
579acf3f8daSKumar Gala 		puts("N/A\n");
580acf3f8daSKumar Gala 		goto skip_l2;
581acf3f8daSKumar Gala 	}
582acf3f8daSKumar Gala 
583a47a12beSStefan Roese 	u32 l2cfg0 = mfspr(SPRN_L2CFG0);
584a47a12beSStefan Roese 
585a47a12beSStefan Roese 	/* invalidate the L2 cache */
586a47a12beSStefan Roese 	mtspr(SPRN_L2CSR0, (L2CSR0_L2FI|L2CSR0_L2LFC));
587a47a12beSStefan Roese 	while (mfspr(SPRN_L2CSR0) & (L2CSR0_L2FI|L2CSR0_L2LFC))
588a47a12beSStefan Roese 		;
589a47a12beSStefan Roese 
590a47a12beSStefan Roese #ifdef CONFIG_SYS_CACHE_STASHING
591a47a12beSStefan Roese 	/* set stash id to (coreID) * 2 + 32 + L2 (1) */
592a47a12beSStefan Roese 	mtspr(SPRN_L2CSR1, (32 + 1));
593a47a12beSStefan Roese #endif
594a47a12beSStefan Roese 
595a47a12beSStefan Roese 	/* enable the cache */
596a47a12beSStefan Roese 	mtspr(SPRN_L2CSR0, CONFIG_SYS_INIT_L2CSR0);
597a47a12beSStefan Roese 
598a47a12beSStefan Roese 	if (CONFIG_SYS_INIT_L2CSR0 & L2CSR0_L2E) {
599a47a12beSStefan Roese 		while (!(mfspr(SPRN_L2CSR0) & L2CSR0_L2E))
600a47a12beSStefan Roese 			;
6012f848f97SShruti Kanetkar 		print_size((l2cfg0 & 0x3fff) * 64 * 1024, " enabled\n");
602a47a12beSStefan Roese 	}
603acf3f8daSKumar Gala 
604acf3f8daSKumar Gala skip_l2:
605e9827468SPrabhakar Kushwaha #elif defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2) && defined(CONFIG_E6500)
6066d2b9da1SYork Sun 	if (l2cache->l2csr0 & L2CSR0_L2E)
6072f848f97SShruti Kanetkar 		print_size((l2cache->l2cfg0 & 0x3fff) * 64 * 1024,
6082f848f97SShruti Kanetkar 			   " enabled\n");
6096d2b9da1SYork Sun 
6106d2b9da1SYork Sun 	enable_cluster_l2();
611a47a12beSStefan Roese #else
612a47a12beSStefan Roese 	puts("disabled\n");
613a47a12beSStefan Roese #endif
6146aba33e9SKumar Gala 
615*fb4a2409SAneesh Bansal #if defined(CONFIG_RAMBOOT_PBL)
616*fb4a2409SAneesh Bansal 	disable_cpc_sram();
617*fb4a2409SAneesh Bansal #endif
6186aba33e9SKumar Gala 	enable_cpc();
6196aba33e9SKumar Gala 
620cb93071bSYork Sun #ifndef CONFIG_SYS_FSL_NO_SERDES
621af025065SKumar Gala 	/* needs to be in ram since code uses global static vars */
622af025065SKumar Gala 	fsl_serdes_init();
623cb93071bSYork Sun #endif
624af025065SKumar Gala 
625424bf942SShengzhou Liu #ifdef CONFIG_SYS_FSL_ERRATUM_SEC_A003571
626424bf942SShengzhou Liu #define MCFGR_AXIPIPE 0x000000f0
627424bf942SShengzhou Liu 	if (IS_SVR_REV(svr, 1, 0))
628424bf942SShengzhou Liu 		clrbits_be32(&sec->mcfgr, MCFGR_AXIPIPE);
629424bf942SShengzhou Liu #endif
630424bf942SShengzhou Liu 
63172bd83cdSShengzhou Liu #ifdef CONFIG_SYS_FSL_ERRATUM_A005871
63272bd83cdSShengzhou Liu 	if (IS_SVR_REV(svr, 1, 0)) {
63372bd83cdSShengzhou Liu 		int i;
63472bd83cdSShengzhou Liu 		__be32 *p = (void __iomem *)CONFIG_SYS_DCSRBAR + 0xb004c;
63572bd83cdSShengzhou Liu 
63672bd83cdSShengzhou Liu 		for (i = 0; i < 12; i++) {
63772bd83cdSShengzhou Liu 			p += i + (i > 5 ? 11 : 0);
63872bd83cdSShengzhou Liu 			out_be32(p, 0x2);
63972bd83cdSShengzhou Liu 		}
64072bd83cdSShengzhou Liu 		p = (void __iomem *)CONFIG_SYS_DCSRBAR + 0xb0108;
64172bd83cdSShengzhou Liu 		out_be32(p, 0x34);
64272bd83cdSShengzhou Liu 	}
64372bd83cdSShengzhou Liu #endif
64472bd83cdSShengzhou Liu 
645a09b9b68SKumar Gala #ifdef CONFIG_SYS_SRIO
646a09b9b68SKumar Gala 	srio_init();
647c8b28152SLiu Gang #ifdef CONFIG_SRIO_PCIE_BOOT_MASTER
648ff65f126SLiu Gang 	char *s = getenv("bootmaster");
649ff65f126SLiu Gang 	if (s) {
650ff65f126SLiu Gang 		if (!strcmp(s, "SRIO1")) {
651ff65f126SLiu Gang 			srio_boot_master(1);
652ff65f126SLiu Gang 			srio_boot_master_release_slave(1);
653ff65f126SLiu Gang 		}
654ff65f126SLiu Gang 		if (!strcmp(s, "SRIO2")) {
655ff65f126SLiu Gang 			srio_boot_master(2);
656ff65f126SLiu Gang 			srio_boot_master_release_slave(2);
657ff65f126SLiu Gang 		}
658ff65f126SLiu Gang 	}
6595ffa88ecSLiu Gang #endif
660a09b9b68SKumar Gala #endif
661a09b9b68SKumar Gala 
662a47a12beSStefan Roese #if defined(CONFIG_MP)
663a47a12beSStefan Roese 	setup_mp();
664a47a12beSStefan Roese #endif
6653f0202edSLan Chunhe 
6664e0be34aSZang Roy-R61911 #ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC13
667ae026ffdSRoy Zang 	{
6684e0be34aSZang Roy-R61911 		if (SVR_MAJ(svr) < 3) {
669ae026ffdSRoy Zang 			void *p;
670ae026ffdSRoy Zang 			p = (void *)CONFIG_SYS_DCSRBAR + 0x20520;
671ae026ffdSRoy Zang 			setbits_be32(p, 1 << (31 - 14));
672ae026ffdSRoy Zang 		}
6734e0be34aSZang Roy-R61911 	}
674ae026ffdSRoy Zang #endif
675ae026ffdSRoy Zang 
6763f0202edSLan Chunhe #ifdef CONFIG_SYS_LBC_LCRR
6773f0202edSLan Chunhe 	/*
6783f0202edSLan Chunhe 	 * Modify the CLKDIV field of LCRR register to improve the writing
6793f0202edSLan Chunhe 	 * speed for NOR flash.
6803f0202edSLan Chunhe 	 */
6813f0202edSLan Chunhe 	clrsetbits_be32(&lbc->lcrr, LCRR_CLKDIV, CONFIG_SYS_LBC_LCRR);
6823f0202edSLan Chunhe 	__raw_readl(&lbc->lcrr);
6833f0202edSLan Chunhe 	isync();
6842b3a1cddSKumar Gala #ifdef CONFIG_SYS_FSL_ERRATUM_NMG_LBC103
6852b3a1cddSKumar Gala 	udelay(100);
6862b3a1cddSKumar Gala #endif
6873f0202edSLan Chunhe #endif
6883f0202edSLan Chunhe 
68986221f09SRoy Zang #ifdef CONFIG_SYS_FSL_USB1_PHY_ENABLE
69086221f09SRoy Zang 	{
6919dee205dSramneek mehresh 		struct ccsr_usb_phy __iomem *usb_phy1 =
69286221f09SRoy Zang 			(void *)CONFIG_SYS_MPC85xx_USB1_PHY_ADDR;
6939c641a87SSuresh Gupta #ifdef CONFIG_SYS_FSL_ERRATUM_A006261
6949c641a87SSuresh Gupta 		if (has_erratum_a006261())
6959c641a87SSuresh Gupta 			fsl_erratum_a006261_workaround(usb_phy1);
6969c641a87SSuresh Gupta #endif
69786221f09SRoy Zang 		out_be32(&usb_phy1->usb_enable_override,
69886221f09SRoy Zang 				CONFIG_SYS_FSL_USB_ENABLE_OVERRIDE);
69986221f09SRoy Zang 	}
70086221f09SRoy Zang #endif
70186221f09SRoy Zang #ifdef CONFIG_SYS_FSL_USB2_PHY_ENABLE
70286221f09SRoy Zang 	{
7039dee205dSramneek mehresh 		struct ccsr_usb_phy __iomem *usb_phy2 =
70486221f09SRoy Zang 			(void *)CONFIG_SYS_MPC85xx_USB2_PHY_ADDR;
7059c641a87SSuresh Gupta #ifdef CONFIG_SYS_FSL_ERRATUM_A006261
7069c641a87SSuresh Gupta 		if (has_erratum_a006261())
7079c641a87SSuresh Gupta 			fsl_erratum_a006261_workaround(usb_phy2);
7089c641a87SSuresh Gupta #endif
70986221f09SRoy Zang 		out_be32(&usb_phy2->usb_enable_override,
71086221f09SRoy Zang 				CONFIG_SYS_FSL_USB_ENABLE_OVERRIDE);
71186221f09SRoy Zang 	}
71286221f09SRoy Zang #endif
71386221f09SRoy Zang 
71499d7b0a4SXulei #ifdef CONFIG_SYS_FSL_ERRATUM_USB14
71599d7b0a4SXulei 	/* On P204x/P304x/P50x0 Rev1.0, USB transmit will result internal
71699d7b0a4SXulei 	 * multi-bit ECC errors which has impact on performance, so software
71799d7b0a4SXulei 	 * should disable all ECC reporting from USB1 and USB2.
71899d7b0a4SXulei 	 */
71999d7b0a4SXulei 	if (IS_SVR_REV(get_svr(), 1, 0)) {
72099d7b0a4SXulei 		struct dcsr_dcfg_regs *dcfg = (struct dcsr_dcfg_regs *)
72199d7b0a4SXulei 			(CONFIG_SYS_DCSRBAR + CONFIG_SYS_DCSR_DCFG_OFFSET);
72299d7b0a4SXulei 		setbits_be32(&dcfg->ecccr1,
72399d7b0a4SXulei 				(DCSR_DCFG_ECC_DISABLE_USB1 |
72499d7b0a4SXulei 				 DCSR_DCFG_ECC_DISABLE_USB2));
72599d7b0a4SXulei 	}
72699d7b0a4SXulei #endif
72799d7b0a4SXulei 
7283fa75c87SRoy Zang #if defined(CONFIG_SYS_FSL_USB_DUAL_PHY_ENABLE)
7299dee205dSramneek mehresh 		struct ccsr_usb_phy __iomem *usb_phy =
7303fa75c87SRoy Zang 			(void *)CONFIG_SYS_MPC85xx_USB1_PHY_ADDR;
7313fa75c87SRoy Zang 		setbits_be32(&usb_phy->pllprg[1],
7323fa75c87SRoy Zang 			     CONFIG_SYS_FSL_USB_PLLPRG2_PHY2_CLK_EN |
7333fa75c87SRoy Zang 			     CONFIG_SYS_FSL_USB_PLLPRG2_PHY1_CLK_EN |
7343fa75c87SRoy Zang 			     CONFIG_SYS_FSL_USB_PLLPRG2_MFI |
7353fa75c87SRoy Zang 			     CONFIG_SYS_FSL_USB_PLLPRG2_PLL_EN);
7363fa75c87SRoy Zang 		setbits_be32(&usb_phy->port1.ctrl,
7373fa75c87SRoy Zang 			     CONFIG_SYS_FSL_USB_CTRL_PHY_EN);
7383fa75c87SRoy Zang 		setbits_be32(&usb_phy->port1.drvvbuscfg,
7393fa75c87SRoy Zang 			     CONFIG_SYS_FSL_USB_DRVVBUS_CR_EN);
7403fa75c87SRoy Zang 		setbits_be32(&usb_phy->port1.pwrfltcfg,
7413fa75c87SRoy Zang 			     CONFIG_SYS_FSL_USB_PWRFLT_CR_EN);
7423fa75c87SRoy Zang 		setbits_be32(&usb_phy->port2.ctrl,
7433fa75c87SRoy Zang 			     CONFIG_SYS_FSL_USB_CTRL_PHY_EN);
7443fa75c87SRoy Zang 		setbits_be32(&usb_phy->port2.drvvbuscfg,
7453fa75c87SRoy Zang 			     CONFIG_SYS_FSL_USB_DRVVBUS_CR_EN);
7463fa75c87SRoy Zang 		setbits_be32(&usb_phy->port2.pwrfltcfg,
7473fa75c87SRoy Zang 			     CONFIG_SYS_FSL_USB_PWRFLT_CR_EN);
7489c641a87SSuresh Gupta 
7499c641a87SSuresh Gupta #ifdef CONFIG_SYS_FSL_ERRATUM_A006261
7509c641a87SSuresh Gupta 		if (has_erratum_a006261())
7519c641a87SSuresh Gupta 			fsl_erratum_a006261_workaround(usb_phy);
7523fa75c87SRoy Zang #endif
7533fa75c87SRoy Zang 
7549c641a87SSuresh Gupta #endif /* CONFIG_SYS_FSL_USB_DUAL_PHY_ENABLE */
7559c641a87SSuresh Gupta 
756c916d7c9SKumar Gala #ifdef CONFIG_FMAN_ENET
757c916d7c9SKumar Gala 	fman_enet_init();
758c916d7c9SKumar Gala #endif
759c916d7c9SKumar Gala 
760fbc20aabSTimur Tabi #if defined(CONFIG_FSL_SATA_V2) && defined(CONFIG_FSL_SATA_ERRATUM_A001)
761fbc20aabSTimur Tabi 	/*
762fbc20aabSTimur Tabi 	 * For P1022/1013 Rev1.0 silicon, after power on SATA host
763fbc20aabSTimur Tabi 	 * controller is configured in legacy mode instead of the
764fbc20aabSTimur Tabi 	 * expected enterprise mode. Software needs to clear bit[28]
765fbc20aabSTimur Tabi 	 * of HControl register to change to enterprise mode from
766fbc20aabSTimur Tabi 	 * legacy mode.  We assume that the controller is offline.
767fbc20aabSTimur Tabi 	 */
768fbc20aabSTimur Tabi 	if (IS_SVR_REV(svr, 1, 0) &&
769fbc20aabSTimur Tabi 	    ((SVR_SOC_VER(svr) == SVR_P1022) ||
77048f6a5c3SYork Sun 	     (SVR_SOC_VER(svr) == SVR_P1013))) {
771fbc20aabSTimur Tabi 		fsl_sata_reg_t *reg;
772fbc20aabSTimur Tabi 
773fbc20aabSTimur Tabi 		/* first SATA controller */
774fbc20aabSTimur Tabi 		reg = (void *)CONFIG_SYS_MPC85xx_SATA1_ADDR;
775fbc20aabSTimur Tabi 		clrbits_le32(&reg->hcontrol, HCONTROL_ENTERPRISE_EN);
776fbc20aabSTimur Tabi 
777fbc20aabSTimur Tabi 		/* second SATA controller */
778fbc20aabSTimur Tabi 		reg = (void *)CONFIG_SYS_MPC85xx_SATA2_ADDR;
779fbc20aabSTimur Tabi 		clrbits_le32(&reg->hcontrol, HCONTROL_ENTERPRISE_EN);
780fbc20aabSTimur Tabi 	}
781fbc20aabSTimur Tabi #endif
782fbc20aabSTimur Tabi 
783fbc20aabSTimur Tabi 
784a47a12beSStefan Roese 	return 0;
785a47a12beSStefan Roese }
786a47a12beSStefan Roese 
787a47a12beSStefan Roese void arch_preboot_os(void)
788a47a12beSStefan Roese {
789a47a12beSStefan Roese 	u32 msr;
790a47a12beSStefan Roese 
791a47a12beSStefan Roese 	/*
792a47a12beSStefan Roese 	 * We are changing interrupt offsets and are about to boot the OS so
793a47a12beSStefan Roese 	 * we need to make sure we disable all async interrupts. EE is already
794a47a12beSStefan Roese 	 * disabled by the time we get called.
795a47a12beSStefan Roese 	 */
796a47a12beSStefan Roese 	msr = mfmsr();
7975344f7a2SPrabhakar Kushwaha 	msr &= ~(MSR_ME|MSR_CE);
798a47a12beSStefan Roese 	mtmsr(msr);
799a47a12beSStefan Roese }
800f54fe87aSKumar Gala 
801f54fe87aSKumar Gala #if defined(CONFIG_CMD_SATA) && defined(CONFIG_FSL_SATA)
802f54fe87aSKumar Gala int sata_initialize(void)
803f54fe87aSKumar Gala {
804f54fe87aSKumar Gala 	if (is_serdes_configured(SATA1) || is_serdes_configured(SATA2))
805f54fe87aSKumar Gala 		return __sata_initialize();
806f54fe87aSKumar Gala 
807f54fe87aSKumar Gala 	return 1;
808f54fe87aSKumar Gala }
809f54fe87aSKumar Gala #endif
810f9a33f1cSKumar Gala 
811f9a33f1cSKumar Gala void cpu_secondary_init_r(void)
812f9a33f1cSKumar Gala {
813f9a33f1cSKumar Gala #ifdef CONFIG_QE
814f9a33f1cSKumar Gala 	uint qe_base = CONFIG_SYS_IMMR + 0x00080000; /* QE immr base */
815f2717b47STimur Tabi #ifdef CONFIG_SYS_QE_FMAN_FW_IN_NAND
816a7b1e1b7SHaiying Wang 	int ret;
817f2717b47STimur Tabi 	size_t fw_length = CONFIG_SYS_QE_FMAN_FW_LENGTH;
818a7b1e1b7SHaiying Wang 
819a7b1e1b7SHaiying Wang 	/* load QE firmware from NAND flash to DDR first */
820f2717b47STimur Tabi 	ret = nand_read(&nand_info[0], (loff_t)CONFIG_SYS_QE_FMAN_FW_IN_NAND,
821f2717b47STimur Tabi 			&fw_length, (u_char *)CONFIG_SYS_QE_FMAN_FW_ADDR);
822a7b1e1b7SHaiying Wang 
823a7b1e1b7SHaiying Wang 	if (ret && ret == -EUCLEAN) {
824a7b1e1b7SHaiying Wang 		printf ("NAND read for QE firmware at offset %x failed %d\n",
825f2717b47STimur Tabi 				CONFIG_SYS_QE_FMAN_FW_IN_NAND, ret);
826a7b1e1b7SHaiying Wang 	}
827a7b1e1b7SHaiying Wang #endif
828f9a33f1cSKumar Gala 	qe_init(qe_base);
829f9a33f1cSKumar Gala 	qe_reset();
830f9a33f1cSKumar Gala #endif
831f9a33f1cSKumar Gala }
832