xref: /rk3399_rockchip-uboot/arch/powerpc/cpu/mpc85xx/cpu_init.c (revision 2a5fcb835f6e976ed0eb34c413d40f2d4a5e8d1f)
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  *
10a47a12beSStefan Roese  * See file CREDITS for list of people who contributed to this
11a47a12beSStefan Roese  * project.
12a47a12beSStefan Roese  *
13a47a12beSStefan Roese  * This program is free software; you can redistribute it and/or
14a47a12beSStefan Roese  * modify it under the terms of the GNU General Public License as
15a47a12beSStefan Roese  * published by the Free Software Foundation; either version 2 of
16a47a12beSStefan Roese  * the License, or (at your option) any later version.
17a47a12beSStefan Roese  *
18a47a12beSStefan Roese  * This program is distributed in the hope that it will be useful,
19a47a12beSStefan Roese  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20a47a12beSStefan Roese  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21a47a12beSStefan Roese  * GNU General Public License for more details.
22a47a12beSStefan Roese  *
23a47a12beSStefan Roese  * You should have received a copy of the GNU General Public License
24a47a12beSStefan Roese  * along with this program; if not, write to the Free Software
25a47a12beSStefan Roese  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26a47a12beSStefan Roese  * MA 02111-1307 USA
27a47a12beSStefan Roese  */
28a47a12beSStefan Roese 
29a47a12beSStefan Roese #include <common.h>
30a47a12beSStefan Roese #include <watchdog.h>
31a47a12beSStefan Roese #include <asm/processor.h>
32a47a12beSStefan Roese #include <ioports.h>
33f54fe87aSKumar Gala #include <sata.h>
34c916d7c9SKumar Gala #include <fm_eth.h>
35a47a12beSStefan Roese #include <asm/io.h>
36fd3c9befSKumar Gala #include <asm/cache.h>
37a47a12beSStefan Roese #include <asm/mmu.h>
38a47a12beSStefan Roese #include <asm/fsl_law.h>
39f54fe87aSKumar Gala #include <asm/fsl_serdes.h>
405ffa88ecSLiu Gang #include <asm/fsl_srio.h>
4157125f22SYork Sun #include <hwconfig.h>
42fbc20aabSTimur Tabi #include <linux/compiler.h>
43a47a12beSStefan Roese #include "mp.h"
44f2717b47STimur Tabi #ifdef CONFIG_SYS_QE_FMAN_FW_IN_NAND
45a7b1e1b7SHaiying Wang #include <nand.h>
46a7b1e1b7SHaiying Wang #include <errno.h>
47a7b1e1b7SHaiying Wang #endif
48a47a12beSStefan Roese 
49fbc20aabSTimur Tabi #include "../../../../drivers/block/fsl_sata.h"
50fbc20aabSTimur Tabi 
51a47a12beSStefan Roese DECLARE_GLOBAL_DATA_PTR;
52a47a12beSStefan Roese 
53a47a12beSStefan Roese #ifdef CONFIG_QE
54a47a12beSStefan Roese extern qe_iop_conf_t qe_iop_conf_tab[];
55a47a12beSStefan Roese extern void qe_config_iopin(u8 port, u8 pin, int dir,
56a47a12beSStefan Roese 				int open_drain, int assign);
57a47a12beSStefan Roese extern void qe_init(uint qe_base);
58a47a12beSStefan Roese extern void qe_reset(void);
59a47a12beSStefan Roese 
60a47a12beSStefan Roese static void config_qe_ioports(void)
61a47a12beSStefan Roese {
62a47a12beSStefan Roese 	u8      port, pin;
63a47a12beSStefan Roese 	int     dir, open_drain, assign;
64a47a12beSStefan Roese 	int     i;
65a47a12beSStefan Roese 
66a47a12beSStefan Roese 	for (i = 0; qe_iop_conf_tab[i].assign != QE_IOP_TAB_END; i++) {
67a47a12beSStefan Roese 		port		= qe_iop_conf_tab[i].port;
68a47a12beSStefan Roese 		pin		= qe_iop_conf_tab[i].pin;
69a47a12beSStefan Roese 		dir		= qe_iop_conf_tab[i].dir;
70a47a12beSStefan Roese 		open_drain	= qe_iop_conf_tab[i].open_drain;
71a47a12beSStefan Roese 		assign		= qe_iop_conf_tab[i].assign;
72a47a12beSStefan Roese 		qe_config_iopin(port, pin, dir, open_drain, assign);
73a47a12beSStefan Roese 	}
74a47a12beSStefan Roese }
75a47a12beSStefan Roese #endif
76a47a12beSStefan Roese 
77a47a12beSStefan Roese #ifdef CONFIG_CPM2
78a47a12beSStefan Roese void config_8560_ioports (volatile ccsr_cpm_t * cpm)
79a47a12beSStefan Roese {
80a47a12beSStefan Roese 	int portnum;
81a47a12beSStefan Roese 
82a47a12beSStefan Roese 	for (portnum = 0; portnum < 4; portnum++) {
83a47a12beSStefan Roese 		uint pmsk = 0,
84a47a12beSStefan Roese 		     ppar = 0,
85a47a12beSStefan Roese 		     psor = 0,
86a47a12beSStefan Roese 		     pdir = 0,
87a47a12beSStefan Roese 		     podr = 0,
88a47a12beSStefan Roese 		     pdat = 0;
89a47a12beSStefan Roese 		iop_conf_t *iopc = (iop_conf_t *) & iop_conf_tab[portnum][0];
90a47a12beSStefan Roese 		iop_conf_t *eiopc = iopc + 32;
91a47a12beSStefan Roese 		uint msk = 1;
92a47a12beSStefan Roese 
93a47a12beSStefan Roese 		/*
94a47a12beSStefan Roese 		 * NOTE:
95a47a12beSStefan Roese 		 * index 0 refers to pin 31,
96a47a12beSStefan Roese 		 * index 31 refers to pin 0
97a47a12beSStefan Roese 		 */
98a47a12beSStefan Roese 		while (iopc < eiopc) {
99a47a12beSStefan Roese 			if (iopc->conf) {
100a47a12beSStefan Roese 				pmsk |= msk;
101a47a12beSStefan Roese 				if (iopc->ppar)
102a47a12beSStefan Roese 					ppar |= msk;
103a47a12beSStefan Roese 				if (iopc->psor)
104a47a12beSStefan Roese 					psor |= msk;
105a47a12beSStefan Roese 				if (iopc->pdir)
106a47a12beSStefan Roese 					pdir |= msk;
107a47a12beSStefan Roese 				if (iopc->podr)
108a47a12beSStefan Roese 					podr |= msk;
109a47a12beSStefan Roese 				if (iopc->pdat)
110a47a12beSStefan Roese 					pdat |= msk;
111a47a12beSStefan Roese 			}
112a47a12beSStefan Roese 
113a47a12beSStefan Roese 			msk <<= 1;
114a47a12beSStefan Roese 			iopc++;
115a47a12beSStefan Roese 		}
116a47a12beSStefan Roese 
117a47a12beSStefan Roese 		if (pmsk != 0) {
118a47a12beSStefan Roese 			volatile ioport_t *iop = ioport_addr (cpm, portnum);
119a47a12beSStefan Roese 			uint tpmsk = ~pmsk;
120a47a12beSStefan Roese 
121a47a12beSStefan Roese 			/*
122a47a12beSStefan Roese 			 * the (somewhat confused) paragraph at the
123a47a12beSStefan Roese 			 * bottom of page 35-5 warns that there might
124a47a12beSStefan Roese 			 * be "unknown behaviour" when programming
125a47a12beSStefan Roese 			 * PSORx and PDIRx, if PPARx = 1, so I
126a47a12beSStefan Roese 			 * decided this meant I had to disable the
127a47a12beSStefan Roese 			 * dedicated function first, and enable it
128a47a12beSStefan Roese 			 * last.
129a47a12beSStefan Roese 			 */
130a47a12beSStefan Roese 			iop->ppar &= tpmsk;
131a47a12beSStefan Roese 			iop->psor = (iop->psor & tpmsk) | psor;
132a47a12beSStefan Roese 			iop->podr = (iop->podr & tpmsk) | podr;
133a47a12beSStefan Roese 			iop->pdat = (iop->pdat & tpmsk) | pdat;
134a47a12beSStefan Roese 			iop->pdir = (iop->pdir & tpmsk) | pdir;
135a47a12beSStefan Roese 			iop->ppar |= ppar;
136a47a12beSStefan Roese 		}
137a47a12beSStefan Roese 	}
138a47a12beSStefan Roese }
139a47a12beSStefan Roese #endif
140a47a12beSStefan Roese 
1416aba33e9SKumar Gala #ifdef CONFIG_SYS_FSL_CPC
1426aba33e9SKumar Gala static void enable_cpc(void)
1436aba33e9SKumar Gala {
1446aba33e9SKumar Gala 	int i;
1456aba33e9SKumar Gala 	u32 size = 0;
1466aba33e9SKumar Gala 
1476aba33e9SKumar Gala 	cpc_corenet_t *cpc = (cpc_corenet_t *)CONFIG_SYS_FSL_CPC_ADDR;
1486aba33e9SKumar Gala 
1496aba33e9SKumar Gala 	for (i = 0; i < CONFIG_SYS_NUM_CPC; i++, cpc++) {
1506aba33e9SKumar Gala 		u32 cpccfg0 = in_be32(&cpc->cpccfg0);
1516aba33e9SKumar Gala 		size += CPC_CFG0_SZ_K(cpccfg0);
1522a9fab82SShaohui Xie #ifdef CONFIG_RAMBOOT_PBL
1532a9fab82SShaohui Xie 		if (in_be32(&cpc->cpcsrcr0) & CPC_SRCR0_SRAMEN) {
1542a9fab82SShaohui Xie 			/* find and disable LAW of SRAM */
1552a9fab82SShaohui Xie 			struct law_entry law = find_law(CONFIG_SYS_INIT_L3_ADDR);
1562a9fab82SShaohui Xie 
1572a9fab82SShaohui Xie 			if (law.index == -1) {
1582a9fab82SShaohui Xie 				printf("\nFatal error happened\n");
1592a9fab82SShaohui Xie 				return;
1602a9fab82SShaohui Xie 			}
1612a9fab82SShaohui Xie 			disable_law(law.index);
1622a9fab82SShaohui Xie 
1632a9fab82SShaohui Xie 			clrbits_be32(&cpc->cpchdbcr0, CPC_HDBCR0_CDQ_SPEC_DIS);
1642a9fab82SShaohui Xie 			out_be32(&cpc->cpccsr0, 0);
1652a9fab82SShaohui Xie 			out_be32(&cpc->cpcsrcr0, 0);
1662a9fab82SShaohui Xie 		}
1672a9fab82SShaohui Xie #endif
1686aba33e9SKumar Gala 
1691d2c2a62SKumar Gala #ifdef CONFIG_SYS_FSL_ERRATUM_CPC_A002
1701d2c2a62SKumar Gala 		setbits_be32(&cpc->cpchdbcr0, CPC_HDBCR0_TAG_ECC_SCRUB_DIS);
1711d2c2a62SKumar Gala #endif
172868da593SKumar Gala #ifdef CONFIG_SYS_FSL_ERRATUM_CPC_A003
173868da593SKumar Gala 		setbits_be32(&cpc->cpchdbcr0, CPC_HDBCR0_DATA_ECC_SCRUB_DIS);
174868da593SKumar Gala #endif
1751d2c2a62SKumar Gala 
1766aba33e9SKumar Gala 		out_be32(&cpc->cpccsr0, CPC_CSR0_CE | CPC_CSR0_PE);
1776aba33e9SKumar Gala 		/* Read back to sync write */
1786aba33e9SKumar Gala 		in_be32(&cpc->cpccsr0);
1796aba33e9SKumar Gala 
1806aba33e9SKumar Gala 	}
1816aba33e9SKumar Gala 
1826aba33e9SKumar Gala 	printf("Corenet Platform Cache: %d KB enabled\n", size);
1836aba33e9SKumar Gala }
1846aba33e9SKumar Gala 
185e56143e5SKim Phillips static void invalidate_cpc(void)
1866aba33e9SKumar Gala {
1876aba33e9SKumar Gala 	int i;
1886aba33e9SKumar Gala 	cpc_corenet_t *cpc = (cpc_corenet_t *)CONFIG_SYS_FSL_CPC_ADDR;
1896aba33e9SKumar Gala 
1906aba33e9SKumar Gala 	for (i = 0; i < CONFIG_SYS_NUM_CPC; i++, cpc++) {
1912a9fab82SShaohui Xie 		/* skip CPC when it used as all SRAM */
1922a9fab82SShaohui Xie 		if (in_be32(&cpc->cpcsrcr0) & CPC_SRCR0_SRAMEN)
1932a9fab82SShaohui Xie 			continue;
1946aba33e9SKumar Gala 		/* Flash invalidate the CPC and clear all the locks */
1956aba33e9SKumar Gala 		out_be32(&cpc->cpccsr0, CPC_CSR0_FI | CPC_CSR0_LFC);
1966aba33e9SKumar Gala 		while (in_be32(&cpc->cpccsr0) & (CPC_CSR0_FI | CPC_CSR0_LFC))
1976aba33e9SKumar Gala 			;
1986aba33e9SKumar Gala 	}
1996aba33e9SKumar Gala }
2006aba33e9SKumar Gala #else
2016aba33e9SKumar Gala #define enable_cpc()
2026aba33e9SKumar Gala #define invalidate_cpc()
2036aba33e9SKumar Gala #endif /* CONFIG_SYS_FSL_CPC */
2046aba33e9SKumar Gala 
205a47a12beSStefan Roese /*
206a47a12beSStefan Roese  * Breathe some life into the CPU...
207a47a12beSStefan Roese  *
208a47a12beSStefan Roese  * Set up the memory map
209a47a12beSStefan Roese  * initialize a bunch of registers
210a47a12beSStefan Roese  */
211a47a12beSStefan Roese 
212a47a12beSStefan Roese #ifdef CONFIG_FSL_CORENET
213a47a12beSStefan Roese static void corenet_tb_init(void)
214a47a12beSStefan Roese {
215a47a12beSStefan Roese 	volatile ccsr_rcpm_t *rcpm =
216a47a12beSStefan Roese 		(void *)(CONFIG_SYS_FSL_CORENET_RCPM_ADDR);
217a47a12beSStefan Roese 	volatile ccsr_pic_t *pic =
218680c613aSKim Phillips 		(void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
219a47a12beSStefan Roese 	u32 whoami = in_be32(&pic->whoami);
220a47a12beSStefan Roese 
221a47a12beSStefan Roese 	/* Enable the timebase register for this core */
222a47a12beSStefan Roese 	out_be32(&rcpm->ctbenrl, (1 << whoami));
223a47a12beSStefan Roese }
224a47a12beSStefan Roese #endif
225a47a12beSStefan Roese 
226a47a12beSStefan Roese void cpu_init_f (void)
227a47a12beSStefan Roese {
228a47a12beSStefan Roese 	extern void m8560_cpm_reset (void);
229f110fe94SStephen George #ifdef CONFIG_SYS_DCSRBAR_PHYS
230f110fe94SStephen George 	ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
231f110fe94SStephen George #endif
2327065b7d4SRuchika Gupta #if defined(CONFIG_SECURE_BOOT)
2337065b7d4SRuchika Gupta 	struct law_entry law;
2347065b7d4SRuchika Gupta #endif
235a47a12beSStefan Roese #ifdef CONFIG_MPC8548
236a47a12beSStefan Roese 	ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR);
237a47a12beSStefan Roese 	uint svr = get_svr();
238a47a12beSStefan Roese 
239a47a12beSStefan Roese 	/*
240a47a12beSStefan Roese 	 * CPU2 errata workaround: A core hang possible while executing
241a47a12beSStefan Roese 	 * a msync instruction and a snoopable transaction from an I/O
242a47a12beSStefan Roese 	 * master tagged to make quick forward progress is present.
243a47a12beSStefan Roese 	 * Fixed in silicon rev 2.1.
244a47a12beSStefan Roese 	 */
245a47a12beSStefan Roese 	if ((SVR_MAJ(svr) == 1) || ((SVR_MAJ(svr) == 2 && SVR_MIN(svr) == 0x0)))
246a47a12beSStefan Roese 		out_be32(&ecm->eebpcr, in_be32(&ecm->eebpcr) | (1 << 16));
247a47a12beSStefan Roese #endif
248a47a12beSStefan Roese 
249a47a12beSStefan Roese 	disable_tlb(14);
250a47a12beSStefan Roese 	disable_tlb(15);
251a47a12beSStefan Roese 
2527065b7d4SRuchika Gupta #if defined(CONFIG_SECURE_BOOT)
2537065b7d4SRuchika Gupta 	/* Disable the LAW created for NOR flash by the PBI commands */
2547065b7d4SRuchika Gupta 	law = find_law(CONFIG_SYS_PBI_FLASH_BASE);
2557065b7d4SRuchika Gupta 	if (law.index != -1)
2567065b7d4SRuchika Gupta 		disable_law(law.index);
2577065b7d4SRuchika Gupta #endif
2587065b7d4SRuchika Gupta 
259a47a12beSStefan Roese #ifdef CONFIG_CPM2
260a47a12beSStefan Roese 	config_8560_ioports((ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR);
261a47a12beSStefan Roese #endif
262a47a12beSStefan Roese 
263f51cdaf1SBecky Bruce        init_early_memctl_regs();
264a47a12beSStefan Roese 
265a47a12beSStefan Roese #if defined(CONFIG_CPM2)
266a47a12beSStefan Roese 	m8560_cpm_reset();
267a47a12beSStefan Roese #endif
268a47a12beSStefan Roese #ifdef CONFIG_QE
269a47a12beSStefan Roese 	/* Config QE ioports */
270a47a12beSStefan Roese 	config_qe_ioports();
271a47a12beSStefan Roese #endif
272a47a12beSStefan Roese #if defined(CONFIG_FSL_DMA)
273a47a12beSStefan Roese 	dma_init();
274a47a12beSStefan Roese #endif
275a47a12beSStefan Roese #ifdef CONFIG_FSL_CORENET
276a47a12beSStefan Roese 	corenet_tb_init();
277a47a12beSStefan Roese #endif
278a47a12beSStefan Roese 	init_used_tlb_cams();
2796aba33e9SKumar Gala 
2806aba33e9SKumar Gala 	/* Invalidate the CPC before DDR gets enabled */
2816aba33e9SKumar Gala 	invalidate_cpc();
282f110fe94SStephen George 
283f110fe94SStephen George  #ifdef CONFIG_SYS_DCSRBAR_PHYS
284f110fe94SStephen George 	/* set DCSRCR so that DCSR space is 1G */
285f110fe94SStephen George 	setbits_be32(&gur->dcsrcr, FSL_CORENET_DCSR_SZ_1G);
286f110fe94SStephen George 	in_be32(&gur->dcsrcr);
287f110fe94SStephen George #endif
288f110fe94SStephen George 
289a47a12beSStefan Roese }
290a47a12beSStefan Roese 
29135079aa9SKumar Gala /* Implement a dummy function for those platforms w/o SERDES */
29235079aa9SKumar Gala static void __fsl_serdes__init(void)
29335079aa9SKumar Gala {
29435079aa9SKumar Gala 	return ;
29535079aa9SKumar Gala }
29635079aa9SKumar Gala __attribute__((weak, alias("__fsl_serdes__init"))) void fsl_serdes_init(void);
297a47a12beSStefan Roese 
2986d2b9da1SYork Sun #ifdef CONFIG_SYS_FSL_QORIQ_CHASSIS2
2996d2b9da1SYork Sun int enable_cluster_l2(void)
3006d2b9da1SYork Sun {
3016d2b9da1SYork Sun 	int i = 0;
3026d2b9da1SYork Sun 	u32 cluster;
3036d2b9da1SYork Sun 	ccsr_gur_t *gur = (void __iomem *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
3046d2b9da1SYork Sun 	struct ccsr_cluster_l2 __iomem *l2cache;
3056d2b9da1SYork Sun 
3066d2b9da1SYork Sun 	cluster = in_be32(&gur->tp_cluster[i].lower);
3076d2b9da1SYork Sun 	if (cluster & TP_CLUSTER_EOC)
3086d2b9da1SYork Sun 		return 0;
3096d2b9da1SYork Sun 
3106d2b9da1SYork Sun 	/* The first cache has already been set up, so skip it */
3116d2b9da1SYork Sun 	i++;
3126d2b9da1SYork Sun 
3136d2b9da1SYork Sun 	/* Look through the remaining clusters, and set up their caches */
3146d2b9da1SYork Sun 	do {
3156d2b9da1SYork Sun 		l2cache = (void __iomem *)(CONFIG_SYS_FSL_CLUSTER_1_L2 + i * 0x40000);
3166d2b9da1SYork Sun 		cluster = in_be32(&gur->tp_cluster[i].lower);
3176d2b9da1SYork Sun 
3186d2b9da1SYork Sun 		/* set stash ID to (cluster) * 2 + 32 + 1 */
3196d2b9da1SYork Sun 		clrsetbits_be32(&l2cache->l2csr1, 0xff, 32 + i * 2 + 1);
3206d2b9da1SYork Sun 
3216d2b9da1SYork Sun 		printf("enable l2 for cluster %d %p\n", i, l2cache);
3226d2b9da1SYork Sun 
3236d2b9da1SYork Sun 		out_be32(&l2cache->l2csr0, L2CSR0_L2FI|L2CSR0_L2LFC);
3246d2b9da1SYork Sun 		while ((in_be32(&l2cache->l2csr0) &
3256d2b9da1SYork Sun 			(L2CSR0_L2FI|L2CSR0_L2LFC)) != 0)
3266d2b9da1SYork Sun 			;
3276d2b9da1SYork Sun 		out_be32(&l2cache->l2csr0, L2CSR0_L2E);
3286d2b9da1SYork Sun 		i++;
3296d2b9da1SYork Sun 	} while (!(cluster & TP_CLUSTER_EOC));
3306d2b9da1SYork Sun 
3316d2b9da1SYork Sun 	return 0;
3326d2b9da1SYork Sun }
3336d2b9da1SYork Sun #endif
3346d2b9da1SYork Sun 
335a47a12beSStefan Roese /*
336a47a12beSStefan Roese  * Initialize L2 as cache.
337a47a12beSStefan Roese  *
338a47a12beSStefan Roese  * The newer 8548, etc, parts have twice as much cache, but
339a47a12beSStefan Roese  * use the same bit-encoding as the older 8555, etc, parts.
340a47a12beSStefan Roese  *
341a47a12beSStefan Roese  */
342a47a12beSStefan Roese int cpu_init_r(void)
343a47a12beSStefan Roese {
344fbc20aabSTimur Tabi 	__maybe_unused u32 svr = get_svr();
3453f0202edSLan Chunhe #ifdef CONFIG_SYS_LBC_LCRR
3466d2b9da1SYork Sun 	fsl_lbc_t *lbc = (void __iomem *)LBC_BASE_ADDR;
3476d2b9da1SYork Sun #endif
3486d2b9da1SYork Sun #ifdef CONFIG_L2_CACHE
3496d2b9da1SYork Sun 	ccsr_l2cache_t *l2cache = (void __iomem *)CONFIG_SYS_MPC85xx_L2_ADDR;
3506d2b9da1SYork Sun #elif defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2)
3516d2b9da1SYork Sun 	struct ccsr_cluster_l2 * l2cache = (void __iomem *)CONFIG_SYS_FSL_CLUSTER_1_L2;
3523f0202edSLan Chunhe #endif
353*2a5fcb83SYork Sun #ifdef CONFIG_PPC_SPINTABLE_COMPATIBLE
354*2a5fcb83SYork Sun 	extern int spin_table_compat;
355*2a5fcb83SYork Sun 	const char *spin;
356*2a5fcb83SYork Sun #endif
3573f0202edSLan Chunhe 
3585e23ab0aSYork Sun #if defined(CONFIG_SYS_P4080_ERRATUM_CPU22) || \
3595e23ab0aSYork Sun 	defined(CONFIG_SYS_FSL_ERRATUM_NMG_CPU_A011)
3605e23ab0aSYork Sun 	/*
36157125f22SYork Sun 	 * CPU22 and NMG_CPU_A011 share the same workaround.
3625e23ab0aSYork Sun 	 * CPU22 applies to P4080 rev 1.0, 2.0, fixed in 3.0
3635e23ab0aSYork Sun 	 * NMG_CPU_A011 applies to P4080 rev 1.0, 2.0, fixed in 3.0
36457125f22SYork Sun 	 * also applies to P3041 rev 1.0, 1.1, P2041 rev 1.0, 1.1, both
36557125f22SYork Sun 	 * fixed in 2.0. NMG_CPU_A011 is activated by default and can
36657125f22SYork Sun 	 * be disabled by hwconfig with syntax:
36757125f22SYork Sun 	 *
36857125f22SYork Sun 	 * fsl_cpu_a011:disable
3695e23ab0aSYork Sun 	 */
37057125f22SYork Sun 	extern int enable_cpu_a011_workaround;
37157125f22SYork Sun #ifdef CONFIG_SYS_P4080_ERRATUM_CPU22
37257125f22SYork Sun 	enable_cpu_a011_workaround = (SVR_MAJ(svr) < 3);
37357125f22SYork Sun #else
37457125f22SYork Sun 	char buffer[HWCONFIG_BUFFER_SIZE];
37557125f22SYork Sun 	char *buf = NULL;
37657125f22SYork Sun 	int n, res;
37757125f22SYork Sun 
37857125f22SYork Sun 	n = getenv_f("hwconfig", buffer, sizeof(buffer));
37957125f22SYork Sun 	if (n > 0)
38057125f22SYork Sun 		buf = buffer;
38157125f22SYork Sun 
38257125f22SYork Sun 	res = hwconfig_arg_cmp_f("fsl_cpu_a011", "disable", buf);
38357125f22SYork Sun 	if (res > 0)
38457125f22SYork Sun 		enable_cpu_a011_workaround = 0;
38557125f22SYork Sun 	else {
38657125f22SYork Sun 		if (n >= HWCONFIG_BUFFER_SIZE) {
38757125f22SYork Sun 			printf("fsl_cpu_a011 was not found. hwconfig variable "
38857125f22SYork Sun 				"may be too long\n");
38957125f22SYork Sun 		}
39057125f22SYork Sun 		enable_cpu_a011_workaround =
39157125f22SYork Sun 			(SVR_SOC_VER(svr) == SVR_P4080 && SVR_MAJ(svr) < 3) ||
39257125f22SYork Sun 			(SVR_SOC_VER(svr) != SVR_P4080 && SVR_MAJ(svr) < 2);
39357125f22SYork Sun 	}
39457125f22SYork Sun #endif
39557125f22SYork Sun 	if (enable_cpu_a011_workaround) {
396fd3c9befSKumar Gala 		flush_dcache();
397fd3c9befSKumar Gala 		mtspr(L1CSR2, (mfspr(L1CSR2) | L1CSR2_DCWS));
398fd3c9befSKumar Gala 		sync();
3991e9ea85fSYork Sun 	}
400fd3c9befSKumar Gala #endif
401fd3c9befSKumar Gala 
402*2a5fcb83SYork Sun #ifdef CONFIG_PPC_SPINTABLE_COMPATIBLE
403*2a5fcb83SYork Sun 	spin = getenv("spin_table_compat");
404*2a5fcb83SYork Sun 	if (spin && (*spin == 'n'))
405*2a5fcb83SYork Sun 		spin_table_compat = 0;
406*2a5fcb83SYork Sun 	else
407*2a5fcb83SYork Sun 		spin_table_compat = 1;
408*2a5fcb83SYork Sun #endif
409*2a5fcb83SYork Sun 
410a47a12beSStefan Roese 	puts ("L2:    ");
411a47a12beSStefan Roese 
412a47a12beSStefan Roese #if defined(CONFIG_L2_CACHE)
413a47a12beSStefan Roese 	volatile uint cache_ctl;
414fbc20aabSTimur Tabi 	uint ver;
415a47a12beSStefan Roese 	u32 l2siz_field;
416a47a12beSStefan Roese 
417a47a12beSStefan Roese 	ver = SVR_SOC_VER(svr);
418a47a12beSStefan Roese 
419a47a12beSStefan Roese 	asm("msync;isync");
420a47a12beSStefan Roese 	cache_ctl = l2cache->l2ctl;
421a47a12beSStefan Roese 
422a47a12beSStefan Roese #if defined(CONFIG_SYS_RAMBOOT) && defined(CONFIG_SYS_INIT_L2_ADDR)
423a47a12beSStefan Roese 	if (cache_ctl & MPC85xx_L2CTL_L2E) {
424a47a12beSStefan Roese 		/* Clear L2 SRAM memory-mapped base address */
425a47a12beSStefan Roese 		out_be32(&l2cache->l2srbar0, 0x0);
426a47a12beSStefan Roese 		out_be32(&l2cache->l2srbar1, 0x0);
427a47a12beSStefan Roese 
428a47a12beSStefan Roese 		/* set MBECCDIS=0, SBECCDIS=0 */
429a47a12beSStefan Roese 		clrbits_be32(&l2cache->l2errdis,
430a47a12beSStefan Roese 				(MPC85xx_L2ERRDIS_MBECC |
431a47a12beSStefan Roese 				 MPC85xx_L2ERRDIS_SBECC));
432a47a12beSStefan Roese 
433a47a12beSStefan Roese 		/* set L2E=0, L2SRAM=0 */
434a47a12beSStefan Roese 		clrbits_be32(&l2cache->l2ctl,
435a47a12beSStefan Roese 				(MPC85xx_L2CTL_L2E |
436a47a12beSStefan Roese 				 MPC85xx_L2CTL_L2SRAM_ENTIRE));
437a47a12beSStefan Roese 	}
438a47a12beSStefan Roese #endif
439a47a12beSStefan Roese 
440a47a12beSStefan Roese 	l2siz_field = (cache_ctl >> 28) & 0x3;
441a47a12beSStefan Roese 
442a47a12beSStefan Roese 	switch (l2siz_field) {
443a47a12beSStefan Roese 	case 0x0:
444a47a12beSStefan Roese 		printf(" unknown size (0x%08x)\n", cache_ctl);
445a47a12beSStefan Roese 		return -1;
446a47a12beSStefan Roese 		break;
447a47a12beSStefan Roese 	case 0x1:
448a47a12beSStefan Roese 		if (ver == SVR_8540 || ver == SVR_8560   ||
44948f6a5c3SYork Sun 		    ver == SVR_8541 || ver == SVR_8555) {
450a47a12beSStefan Roese 			puts("128 KB ");
451a47a12beSStefan Roese 			/* set L2E=1, L2I=1, & L2BLKSZ=1 (128 Kbyte) */
452a47a12beSStefan Roese 			cache_ctl = 0xc4000000;
453a47a12beSStefan Roese 		} else {
454a47a12beSStefan Roese 			puts("256 KB ");
455a47a12beSStefan Roese 			cache_ctl = 0xc0000000; /* set L2E=1, L2I=1, & L2SRAM=0 */
456a47a12beSStefan Roese 		}
457a47a12beSStefan Roese 		break;
458a47a12beSStefan Roese 	case 0x2:
459a47a12beSStefan Roese 		if (ver == SVR_8540 || ver == SVR_8560   ||
46048f6a5c3SYork Sun 		    ver == SVR_8541 || ver == SVR_8555) {
461a47a12beSStefan Roese 			puts("256 KB ");
462a47a12beSStefan Roese 			/* set L2E=1, L2I=1, & L2BLKSZ=2 (256 Kbyte) */
463a47a12beSStefan Roese 			cache_ctl = 0xc8000000;
464a47a12beSStefan Roese 		} else {
465a47a12beSStefan Roese 			puts ("512 KB ");
466a47a12beSStefan Roese 			/* set L2E=1, L2I=1, & L2SRAM=0 */
467a47a12beSStefan Roese 			cache_ctl = 0xc0000000;
468a47a12beSStefan Roese 		}
469a47a12beSStefan Roese 		break;
470a47a12beSStefan Roese 	case 0x3:
471a47a12beSStefan Roese 		puts("1024 KB ");
472a47a12beSStefan Roese 		/* set L2E=1, L2I=1, & L2SRAM=0 */
473a47a12beSStefan Roese 		cache_ctl = 0xc0000000;
474a47a12beSStefan Roese 		break;
475a47a12beSStefan Roese 	}
476a47a12beSStefan Roese 
477a47a12beSStefan Roese 	if (l2cache->l2ctl & MPC85xx_L2CTL_L2E) {
478a47a12beSStefan Roese 		puts("already enabled");
479888279b5SHaiying Wang #if defined(CONFIG_SYS_INIT_L2_ADDR) && defined(CONFIG_SYS_FLASH_BASE)
480e4c9a35dSKumar Gala 		u32 l2srbar = l2cache->l2srbar0;
481a47a12beSStefan Roese 		if (l2cache->l2ctl & MPC85xx_L2CTL_L2SRAM_ENTIRE
482a47a12beSStefan Roese 				&& l2srbar >= CONFIG_SYS_FLASH_BASE) {
483a47a12beSStefan Roese 			l2srbar = CONFIG_SYS_INIT_L2_ADDR;
484a47a12beSStefan Roese 			l2cache->l2srbar0 = l2srbar;
4859a511bd6SScott Wood 			printf(", moving to 0x%08x", CONFIG_SYS_INIT_L2_ADDR);
486a47a12beSStefan Roese 		}
487a47a12beSStefan Roese #endif /* CONFIG_SYS_INIT_L2_ADDR */
488a47a12beSStefan Roese 		puts("\n");
489a47a12beSStefan Roese 	} else {
490a47a12beSStefan Roese 		asm("msync;isync");
491a47a12beSStefan Roese 		l2cache->l2ctl = cache_ctl; /* invalidate & enable */
492a47a12beSStefan Roese 		asm("msync;isync");
493a47a12beSStefan Roese 		puts("enabled\n");
494a47a12beSStefan Roese 	}
495a47a12beSStefan Roese #elif defined(CONFIG_BACKSIDE_L2_CACHE)
49648f6a5c3SYork Sun 	if (SVR_SOC_VER(svr) == SVR_P2040) {
497acf3f8daSKumar Gala 		puts("N/A\n");
498acf3f8daSKumar Gala 		goto skip_l2;
499acf3f8daSKumar Gala 	}
500acf3f8daSKumar Gala 
501a47a12beSStefan Roese 	u32 l2cfg0 = mfspr(SPRN_L2CFG0);
502a47a12beSStefan Roese 
503a47a12beSStefan Roese 	/* invalidate the L2 cache */
504a47a12beSStefan Roese 	mtspr(SPRN_L2CSR0, (L2CSR0_L2FI|L2CSR0_L2LFC));
505a47a12beSStefan Roese 	while (mfspr(SPRN_L2CSR0) & (L2CSR0_L2FI|L2CSR0_L2LFC))
506a47a12beSStefan Roese 		;
507a47a12beSStefan Roese 
508a47a12beSStefan Roese #ifdef CONFIG_SYS_CACHE_STASHING
509a47a12beSStefan Roese 	/* set stash id to (coreID) * 2 + 32 + L2 (1) */
510a47a12beSStefan Roese 	mtspr(SPRN_L2CSR1, (32 + 1));
511a47a12beSStefan Roese #endif
512a47a12beSStefan Roese 
513a47a12beSStefan Roese 	/* enable the cache */
514a47a12beSStefan Roese 	mtspr(SPRN_L2CSR0, CONFIG_SYS_INIT_L2CSR0);
515a47a12beSStefan Roese 
516a47a12beSStefan Roese 	if (CONFIG_SYS_INIT_L2CSR0 & L2CSR0_L2E) {
517a47a12beSStefan Roese 		while (!(mfspr(SPRN_L2CSR0) & L2CSR0_L2E))
518a47a12beSStefan Roese 			;
519a47a12beSStefan Roese 		printf("%d KB enabled\n", (l2cfg0 & 0x3fff) * 64);
520a47a12beSStefan Roese 	}
521acf3f8daSKumar Gala 
522acf3f8daSKumar Gala skip_l2:
5236d2b9da1SYork Sun #elif defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2)
5246d2b9da1SYork Sun 	if (l2cache->l2csr0 & L2CSR0_L2E)
5256d2b9da1SYork Sun 		printf("%d KB enabled\n", (l2cache->l2cfg0 & 0x3fff) * 64);
5266d2b9da1SYork Sun 
5276d2b9da1SYork Sun 	enable_cluster_l2();
528a47a12beSStefan Roese #else
529a47a12beSStefan Roese 	puts("disabled\n");
530a47a12beSStefan Roese #endif
5316aba33e9SKumar Gala 
5326aba33e9SKumar Gala 	enable_cpc();
5336aba33e9SKumar Gala 
534af025065SKumar Gala 	/* needs to be in ram since code uses global static vars */
535af025065SKumar Gala 	fsl_serdes_init();
536af025065SKumar Gala 
537a09b9b68SKumar Gala #ifdef CONFIG_SYS_SRIO
538a09b9b68SKumar Gala 	srio_init();
53919e4a009SLiu Gang #ifdef CONFIG_SYS_FSL_SRIO_PCIE_BOOT_MASTER
540ff65f126SLiu Gang 	char *s = getenv("bootmaster");
541ff65f126SLiu Gang 	if (s) {
542ff65f126SLiu Gang 		if (!strcmp(s, "SRIO1")) {
543ff65f126SLiu Gang 			srio_boot_master(1);
544ff65f126SLiu Gang 			srio_boot_master_release_slave(1);
545ff65f126SLiu Gang 		}
546ff65f126SLiu Gang 		if (!strcmp(s, "SRIO2")) {
547ff65f126SLiu Gang 			srio_boot_master(2);
548ff65f126SLiu Gang 			srio_boot_master_release_slave(2);
549ff65f126SLiu Gang 		}
550ff65f126SLiu Gang 	}
5515ffa88ecSLiu Gang #endif
552a09b9b68SKumar Gala #endif
553a09b9b68SKumar Gala 
554a47a12beSStefan Roese #if defined(CONFIG_MP)
555a47a12beSStefan Roese 	setup_mp();
556a47a12beSStefan Roese #endif
5573f0202edSLan Chunhe 
5584e0be34aSZang Roy-R61911 #ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC13
559ae026ffdSRoy Zang 	{
5604e0be34aSZang Roy-R61911 		if (SVR_MAJ(svr) < 3) {
561ae026ffdSRoy Zang 			void *p;
562ae026ffdSRoy Zang 			p = (void *)CONFIG_SYS_DCSRBAR + 0x20520;
563ae026ffdSRoy Zang 			setbits_be32(p, 1 << (31 - 14));
564ae026ffdSRoy Zang 		}
5654e0be34aSZang Roy-R61911 	}
566ae026ffdSRoy Zang #endif
567ae026ffdSRoy Zang 
5683f0202edSLan Chunhe #ifdef CONFIG_SYS_LBC_LCRR
5693f0202edSLan Chunhe 	/*
5703f0202edSLan Chunhe 	 * Modify the CLKDIV field of LCRR register to improve the writing
5713f0202edSLan Chunhe 	 * speed for NOR flash.
5723f0202edSLan Chunhe 	 */
5733f0202edSLan Chunhe 	clrsetbits_be32(&lbc->lcrr, LCRR_CLKDIV, CONFIG_SYS_LBC_LCRR);
5743f0202edSLan Chunhe 	__raw_readl(&lbc->lcrr);
5753f0202edSLan Chunhe 	isync();
5762b3a1cddSKumar Gala #ifdef CONFIG_SYS_FSL_ERRATUM_NMG_LBC103
5772b3a1cddSKumar Gala 	udelay(100);
5782b3a1cddSKumar Gala #endif
5793f0202edSLan Chunhe #endif
5803f0202edSLan Chunhe 
58186221f09SRoy Zang #ifdef CONFIG_SYS_FSL_USB1_PHY_ENABLE
58286221f09SRoy Zang 	{
58386221f09SRoy Zang 		ccsr_usb_phy_t *usb_phy1 =
58486221f09SRoy Zang 			(void *)CONFIG_SYS_MPC85xx_USB1_PHY_ADDR;
58586221f09SRoy Zang 		out_be32(&usb_phy1->usb_enable_override,
58686221f09SRoy Zang 				CONFIG_SYS_FSL_USB_ENABLE_OVERRIDE);
58786221f09SRoy Zang 	}
58886221f09SRoy Zang #endif
58986221f09SRoy Zang #ifdef CONFIG_SYS_FSL_USB2_PHY_ENABLE
59086221f09SRoy Zang 	{
59186221f09SRoy Zang 		ccsr_usb_phy_t *usb_phy2 =
59286221f09SRoy Zang 			(void *)CONFIG_SYS_MPC85xx_USB2_PHY_ADDR;
59386221f09SRoy Zang 		out_be32(&usb_phy2->usb_enable_override,
59486221f09SRoy Zang 				CONFIG_SYS_FSL_USB_ENABLE_OVERRIDE);
59586221f09SRoy Zang 	}
59686221f09SRoy Zang #endif
59786221f09SRoy Zang 
598c916d7c9SKumar Gala #ifdef CONFIG_FMAN_ENET
599c916d7c9SKumar Gala 	fman_enet_init();
600c916d7c9SKumar Gala #endif
601c916d7c9SKumar Gala 
602fbc20aabSTimur Tabi #if defined(CONFIG_FSL_SATA_V2) && defined(CONFIG_FSL_SATA_ERRATUM_A001)
603fbc20aabSTimur Tabi 	/*
604fbc20aabSTimur Tabi 	 * For P1022/1013 Rev1.0 silicon, after power on SATA host
605fbc20aabSTimur Tabi 	 * controller is configured in legacy mode instead of the
606fbc20aabSTimur Tabi 	 * expected enterprise mode. Software needs to clear bit[28]
607fbc20aabSTimur Tabi 	 * of HControl register to change to enterprise mode from
608fbc20aabSTimur Tabi 	 * legacy mode.  We assume that the controller is offline.
609fbc20aabSTimur Tabi 	 */
610fbc20aabSTimur Tabi 	if (IS_SVR_REV(svr, 1, 0) &&
611fbc20aabSTimur Tabi 	    ((SVR_SOC_VER(svr) == SVR_P1022) ||
61248f6a5c3SYork Sun 	     (SVR_SOC_VER(svr) == SVR_P1013))) {
613fbc20aabSTimur Tabi 		fsl_sata_reg_t *reg;
614fbc20aabSTimur Tabi 
615fbc20aabSTimur Tabi 		/* first SATA controller */
616fbc20aabSTimur Tabi 		reg = (void *)CONFIG_SYS_MPC85xx_SATA1_ADDR;
617fbc20aabSTimur Tabi 		clrbits_le32(&reg->hcontrol, HCONTROL_ENTERPRISE_EN);
618fbc20aabSTimur Tabi 
619fbc20aabSTimur Tabi 		/* second SATA controller */
620fbc20aabSTimur Tabi 		reg = (void *)CONFIG_SYS_MPC85xx_SATA2_ADDR;
621fbc20aabSTimur Tabi 		clrbits_le32(&reg->hcontrol, HCONTROL_ENTERPRISE_EN);
622fbc20aabSTimur Tabi 	}
623fbc20aabSTimur Tabi #endif
624fbc20aabSTimur Tabi 
625fbc20aabSTimur Tabi 
626a47a12beSStefan Roese 	return 0;
627a47a12beSStefan Roese }
628a47a12beSStefan Roese 
629a47a12beSStefan Roese extern void setup_ivors(void);
630a47a12beSStefan Roese 
631a47a12beSStefan Roese void arch_preboot_os(void)
632a47a12beSStefan Roese {
633a47a12beSStefan Roese 	u32 msr;
634a47a12beSStefan Roese 
635a47a12beSStefan Roese 	/*
636a47a12beSStefan Roese 	 * We are changing interrupt offsets and are about to boot the OS so
637a47a12beSStefan Roese 	 * we need to make sure we disable all async interrupts. EE is already
638a47a12beSStefan Roese 	 * disabled by the time we get called.
639a47a12beSStefan Roese 	 */
640a47a12beSStefan Roese 	msr = mfmsr();
6415344f7a2SPrabhakar Kushwaha 	msr &= ~(MSR_ME|MSR_CE);
642a47a12beSStefan Roese 	mtmsr(msr);
643a47a12beSStefan Roese 
644a47a12beSStefan Roese 	setup_ivors();
645a47a12beSStefan Roese }
646f54fe87aSKumar Gala 
647f54fe87aSKumar Gala #if defined(CONFIG_CMD_SATA) && defined(CONFIG_FSL_SATA)
648f54fe87aSKumar Gala int sata_initialize(void)
649f54fe87aSKumar Gala {
650f54fe87aSKumar Gala 	if (is_serdes_configured(SATA1) || is_serdes_configured(SATA2))
651f54fe87aSKumar Gala 		return __sata_initialize();
652f54fe87aSKumar Gala 
653f54fe87aSKumar Gala 	return 1;
654f54fe87aSKumar Gala }
655f54fe87aSKumar Gala #endif
656f9a33f1cSKumar Gala 
657f9a33f1cSKumar Gala void cpu_secondary_init_r(void)
658f9a33f1cSKumar Gala {
659f9a33f1cSKumar Gala #ifdef CONFIG_QE
660f9a33f1cSKumar Gala 	uint qe_base = CONFIG_SYS_IMMR + 0x00080000; /* QE immr base */
661f2717b47STimur Tabi #ifdef CONFIG_SYS_QE_FMAN_FW_IN_NAND
662a7b1e1b7SHaiying Wang 	int ret;
663f2717b47STimur Tabi 	size_t fw_length = CONFIG_SYS_QE_FMAN_FW_LENGTH;
664a7b1e1b7SHaiying Wang 
665a7b1e1b7SHaiying Wang 	/* load QE firmware from NAND flash to DDR first */
666f2717b47STimur Tabi 	ret = nand_read(&nand_info[0], (loff_t)CONFIG_SYS_QE_FMAN_FW_IN_NAND,
667f2717b47STimur Tabi 			&fw_length, (u_char *)CONFIG_SYS_QE_FMAN_FW_ADDR);
668a7b1e1b7SHaiying Wang 
669a7b1e1b7SHaiying Wang 	if (ret && ret == -EUCLEAN) {
670a7b1e1b7SHaiying Wang 		printf ("NAND read for QE firmware at offset %x failed %d\n",
671f2717b47STimur Tabi 				CONFIG_SYS_QE_FMAN_FW_IN_NAND, ret);
672a7b1e1b7SHaiying Wang 	}
673a7b1e1b7SHaiying Wang #endif
674f9a33f1cSKumar Gala 	qe_init(qe_base);
675f9a33f1cSKumar Gala 	qe_reset();
676f9a33f1cSKumar Gala #endif
677f9a33f1cSKumar Gala }
678