xref: /OK3568_Linux_fs/u-boot/arch/powerpc/cpu/mpc85xx/cpu_init_early.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright 2009-2012 Freescale Semiconductor, Inc
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * SPDX-License-Identifier:	GPL-2.0+
5*4882a593Smuzhiyun  */
6*4882a593Smuzhiyun 
7*4882a593Smuzhiyun #include <common.h>
8*4882a593Smuzhiyun #include <asm/processor.h>
9*4882a593Smuzhiyun #include <asm/mmu.h>
10*4882a593Smuzhiyun #include <asm/fsl_law.h>
11*4882a593Smuzhiyun #include <asm/io.h>
12*4882a593Smuzhiyun 
13*4882a593Smuzhiyun DECLARE_GLOBAL_DATA_PTR;
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun #ifdef CONFIG_A003399_NOR_WORKAROUND
setup_ifc(void)16*4882a593Smuzhiyun void setup_ifc(void)
17*4882a593Smuzhiyun {
18*4882a593Smuzhiyun 	struct fsl_ifc ifc_regs = {(void *)CONFIG_SYS_IFC_ADDR, (void *)NULL};
19*4882a593Smuzhiyun 	u32 _mas0, _mas1, _mas2, _mas3, _mas7;
20*4882a593Smuzhiyun 	phys_addr_t flash_phys = CONFIG_SYS_FLASH_BASE_PHYS;
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun 	/*
23*4882a593Smuzhiyun 	 * Adjust the TLB we were running out of to match the phys addr of the
24*4882a593Smuzhiyun 	 * chip select we are adjusting and will return to.
25*4882a593Smuzhiyun 	 */
26*4882a593Smuzhiyun 	flash_phys += (~CONFIG_SYS_AMASK0) + 1 - 4*1024*1024;
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun 	_mas0 = MAS0_TLBSEL(1) | MAS0_ESEL(15);
29*4882a593Smuzhiyun 	_mas1 = MAS1_VALID | MAS1_TID(0) | MAS1_TS | MAS1_IPROT |
30*4882a593Smuzhiyun 			MAS1_TSIZE(BOOKE_PAGESZ_4M);
31*4882a593Smuzhiyun 	_mas2 = FSL_BOOKE_MAS2(CONFIG_SYS_TEXT_BASE, MAS2_I|MAS2_G);
32*4882a593Smuzhiyun 	_mas3 = FSL_BOOKE_MAS3(flash_phys, 0, MAS3_SW|MAS3_SR|MAS3_SX);
33*4882a593Smuzhiyun 	_mas7 = FSL_BOOKE_MAS7(flash_phys);
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun 	mtspr(MAS0, _mas0);
36*4882a593Smuzhiyun 	mtspr(MAS1, _mas1);
37*4882a593Smuzhiyun 	mtspr(MAS2, _mas2);
38*4882a593Smuzhiyun 	mtspr(MAS3, _mas3);
39*4882a593Smuzhiyun 	mtspr(MAS7, _mas7);
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun 	asm volatile("isync;msync;tlbwe;isync");
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun #if defined(CONFIG_SYS_PPC_E500_DEBUG_TLB)
44*4882a593Smuzhiyun /*
45*4882a593Smuzhiyun  * TLB entry for debuggging in AS1
46*4882a593Smuzhiyun  * Create temporary TLB entry in AS0 to handle debug exception
47*4882a593Smuzhiyun  * As on debug exception MSR is cleared i.e. Address space is changed
48*4882a593Smuzhiyun  * to 0. A TLB entry (in AS0) is required to handle debug exception generated
49*4882a593Smuzhiyun  * in AS1.
50*4882a593Smuzhiyun  *
51*4882a593Smuzhiyun  * TLB entry is created for IVPR + IVOR15 to map on valid OP code address
52*4882a593Smuzhiyun  * bacause flash's physical address is going to change as
53*4882a593Smuzhiyun  * CONFIG_SYS_FLASH_BASE_PHYS.
54*4882a593Smuzhiyun  */
55*4882a593Smuzhiyun 	_mas0 = MAS0_TLBSEL(1) |
56*4882a593Smuzhiyun 			MAS0_ESEL(CONFIG_SYS_PPC_E500_DEBUG_TLB);
57*4882a593Smuzhiyun 	_mas1 = MAS1_VALID | MAS1_TID(0) | MAS1_IPROT |
58*4882a593Smuzhiyun 			MAS1_TSIZE(BOOKE_PAGESZ_4M);
59*4882a593Smuzhiyun 	_mas2 = FSL_BOOKE_MAS2(CONFIG_SYS_TEXT_BASE, MAS2_I|MAS2_G);
60*4882a593Smuzhiyun 	_mas3 = FSL_BOOKE_MAS3(flash_phys, 0, MAS3_SW|MAS3_SR|MAS3_SX);
61*4882a593Smuzhiyun 	_mas7 = FSL_BOOKE_MAS7(flash_phys);
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun 	mtspr(MAS0, _mas0);
64*4882a593Smuzhiyun 	mtspr(MAS1, _mas1);
65*4882a593Smuzhiyun 	mtspr(MAS2, _mas2);
66*4882a593Smuzhiyun 	mtspr(MAS3, _mas3);
67*4882a593Smuzhiyun 	mtspr(MAS7, _mas7);
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun 	asm volatile("isync;msync;tlbwe;isync");
70*4882a593Smuzhiyun #endif
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun 	/* Change flash's physical address */
73*4882a593Smuzhiyun 	ifc_out32(&(ifc_regs.gregs->cspr_cs[0].cspr), CONFIG_SYS_CSPR0);
74*4882a593Smuzhiyun 	ifc_out32(&(ifc_regs.gregs->csor_cs[0].csor), CONFIG_SYS_CSOR0);
75*4882a593Smuzhiyun 	ifc_out32(&(ifc_regs.gregs->amask_cs[0].amask), CONFIG_SYS_AMASK0);
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun 	return ;
78*4882a593Smuzhiyun }
79*4882a593Smuzhiyun #endif
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun /* We run cpu_init_early_f in AS = 1 */
cpu_init_early_f(void * fdt)82*4882a593Smuzhiyun void cpu_init_early_f(void *fdt)
83*4882a593Smuzhiyun {
84*4882a593Smuzhiyun 	u32 mas0, mas1, mas2, mas3, mas7;
85*4882a593Smuzhiyun #ifdef CONFIG_SYS_FSL_ERRATUM_P1010_A003549
86*4882a593Smuzhiyun 	ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
87*4882a593Smuzhiyun #endif
88*4882a593Smuzhiyun #ifdef CONFIG_A003399_NOR_WORKAROUND
89*4882a593Smuzhiyun 	ccsr_l2cache_t *l2cache = (void *)CONFIG_SYS_MPC85xx_L2_ADDR;
90*4882a593Smuzhiyun 	u32  *dst, *src;
91*4882a593Smuzhiyun 	void (*setup_ifc_sram)(void);
92*4882a593Smuzhiyun 	int i;
93*4882a593Smuzhiyun #endif
94*4882a593Smuzhiyun 
95*4882a593Smuzhiyun 	/* Pointer is writable since we allocated a register for it */
96*4882a593Smuzhiyun 	gd = (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
97*4882a593Smuzhiyun 
98*4882a593Smuzhiyun 	/* gd area was zeroed during startup */
99*4882a593Smuzhiyun 
100*4882a593Smuzhiyun #ifdef CONFIG_ARCH_QEMU_E500
101*4882a593Smuzhiyun 	/*
102*4882a593Smuzhiyun 	 * CONFIG_SYS_CCSRBAR_PHYS below may use gd->fdt_blob on ePAPR systems,
103*4882a593Smuzhiyun 	 * so we need to populate it before it accesses it.
104*4882a593Smuzhiyun 	 */
105*4882a593Smuzhiyun 	gd->fdt_blob = fdt;
106*4882a593Smuzhiyun #endif
107*4882a593Smuzhiyun 
108*4882a593Smuzhiyun 	mas0 = MAS0_TLBSEL(1) | MAS0_ESEL(13);
109*4882a593Smuzhiyun 	mas1 = MAS1_VALID | MAS1_TID(0) | MAS1_TS | MAS1_TSIZE(BOOKE_PAGESZ_1M);
110*4882a593Smuzhiyun 	mas2 = FSL_BOOKE_MAS2(CONFIG_SYS_CCSRBAR, MAS2_I|MAS2_G);
111*4882a593Smuzhiyun 	mas3 = FSL_BOOKE_MAS3(CONFIG_SYS_CCSRBAR_PHYS, 0, MAS3_SW|MAS3_SR);
112*4882a593Smuzhiyun 	mas7 = FSL_BOOKE_MAS7(CONFIG_SYS_CCSRBAR_PHYS);
113*4882a593Smuzhiyun 
114*4882a593Smuzhiyun 	write_tlb(mas0, mas1, mas2, mas3, mas7);
115*4882a593Smuzhiyun 
116*4882a593Smuzhiyun /*
117*4882a593Smuzhiyun  * Work Around for IFC Erratum A-003549. This issue is P1010
118*4882a593Smuzhiyun  * specific. LCLK(a free running clk signal) is muxed with IFC_CS3 on P1010 SOC
119*4882a593Smuzhiyun  * Hence specifically selecting CS3.
120*4882a593Smuzhiyun  */
121*4882a593Smuzhiyun #ifdef CONFIG_SYS_FSL_ERRATUM_P1010_A003549
122*4882a593Smuzhiyun 	setbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_LCLK_IFC_CS3);
123*4882a593Smuzhiyun #endif
124*4882a593Smuzhiyun 
125*4882a593Smuzhiyun 	init_laws();
126*4882a593Smuzhiyun 
127*4882a593Smuzhiyun /*
128*4882a593Smuzhiyun  * Work Around for IFC Erratum A003399, issue will hit only when execution
129*4882a593Smuzhiyun  * from NOR Flash
130*4882a593Smuzhiyun  */
131*4882a593Smuzhiyun #ifdef CONFIG_A003399_NOR_WORKAROUND
132*4882a593Smuzhiyun #define SRAM_BASE_ADDR	(0x00000000)
133*4882a593Smuzhiyun 	/* TLB for SRAM */
134*4882a593Smuzhiyun 	mas0 = MAS0_TLBSEL(1) | MAS0_ESEL(9);
135*4882a593Smuzhiyun 	mas1 = MAS1_VALID | MAS1_TID(0) | MAS1_TS |
136*4882a593Smuzhiyun 		MAS1_TSIZE(BOOKE_PAGESZ_1M);
137*4882a593Smuzhiyun 	mas2 = FSL_BOOKE_MAS2(SRAM_BASE_ADDR, MAS2_I);
138*4882a593Smuzhiyun 	mas3 = FSL_BOOKE_MAS3(SRAM_BASE_ADDR, 0, MAS3_SX|MAS3_SW|MAS3_SR);
139*4882a593Smuzhiyun 	mas7 = FSL_BOOKE_MAS7(0);
140*4882a593Smuzhiyun 
141*4882a593Smuzhiyun 	write_tlb(mas0, mas1, mas2, mas3, mas7);
142*4882a593Smuzhiyun 
143*4882a593Smuzhiyun 	out_be32(&l2cache->l2srbar0, SRAM_BASE_ADDR);
144*4882a593Smuzhiyun 
145*4882a593Smuzhiyun 	out_be32(&l2cache->l2errdis,
146*4882a593Smuzhiyun 		(MPC85xx_L2ERRDIS_MBECC | MPC85xx_L2ERRDIS_SBECC));
147*4882a593Smuzhiyun 
148*4882a593Smuzhiyun 	out_be32(&l2cache->l2ctl,
149*4882a593Smuzhiyun 		(MPC85xx_L2CTL_L2E | MPC85xx_L2CTL_L2SRAM_ENTIRE));
150*4882a593Smuzhiyun 
151*4882a593Smuzhiyun 	/*
152*4882a593Smuzhiyun 	 * Copy the code in setup_ifc to L2SRAM. Do a word copy
153*4882a593Smuzhiyun 	 * because NOR Flash on P1010 does not support byte
154*4882a593Smuzhiyun 	 * access (Erratum IFC-A002769)
155*4882a593Smuzhiyun 	 */
156*4882a593Smuzhiyun 	setup_ifc_sram = (void *)SRAM_BASE_ADDR;
157*4882a593Smuzhiyun 	dst = (u32 *) SRAM_BASE_ADDR;
158*4882a593Smuzhiyun 	src = (u32 *) setup_ifc;
159*4882a593Smuzhiyun 	for (i = 0; i < 1024; i++) {
160*4882a593Smuzhiyun 		/* cppcheck-suppress nullPointer */
161*4882a593Smuzhiyun 		*dst++ = *src++;
162*4882a593Smuzhiyun 	}
163*4882a593Smuzhiyun 
164*4882a593Smuzhiyun 	/* cppcheck-suppress nullPointer */
165*4882a593Smuzhiyun 	setup_ifc_sram();
166*4882a593Smuzhiyun 
167*4882a593Smuzhiyun 	/* CLEANUP */
168*4882a593Smuzhiyun 	clrbits_be32(&l2cache->l2ctl,
169*4882a593Smuzhiyun 			(MPC85xx_L2CTL_L2E |
170*4882a593Smuzhiyun 			 MPC85xx_L2CTL_L2SRAM_ENTIRE));
171*4882a593Smuzhiyun 	out_be32(&l2cache->l2srbar0, 0x0);
172*4882a593Smuzhiyun #endif
173*4882a593Smuzhiyun 
174*4882a593Smuzhiyun 	invalidate_tlb(1);
175*4882a593Smuzhiyun 
176*4882a593Smuzhiyun #if defined(CONFIG_SYS_PPC_E500_DEBUG_TLB) && \
177*4882a593Smuzhiyun 	!(defined(CONFIG_SPL_INIT_MINIMAL) && defined(CONFIG_SPL_BUILD)) && \
178*4882a593Smuzhiyun 	!defined(CONFIG_NAND_SPL)
179*4882a593Smuzhiyun 	disable_tlb(CONFIG_SYS_PPC_E500_DEBUG_TLB);
180*4882a593Smuzhiyun #endif
181*4882a593Smuzhiyun 
182*4882a593Smuzhiyun 	init_tlbs();
183*4882a593Smuzhiyun }
184