xref: /rk3399_rockchip-uboot/board/freescale/mpc8548cds/mpc8548cds.c (revision 415a613babb84d5e5d5b42e8e553868c71fc3a64)
1*415a613bSKumar Gala /*
2*415a613bSKumar Gala  * Copyright 2004, 2007 Freescale Semiconductor.
3*415a613bSKumar Gala  *
4*415a613bSKumar Gala  * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com>
5*415a613bSKumar Gala  *
6*415a613bSKumar Gala  * See file CREDITS for list of people who contributed to this
7*415a613bSKumar Gala  * project.
8*415a613bSKumar Gala  *
9*415a613bSKumar Gala  * This program is free software; you can redistribute it and/or
10*415a613bSKumar Gala  * modify it under the terms of the GNU General Public License as
11*415a613bSKumar Gala  * published by the Free Software Foundation; either version 2 of
12*415a613bSKumar Gala  * the License, or (at your option) any later version.
13*415a613bSKumar Gala  *
14*415a613bSKumar Gala  * This program is distributed in the hope that it will be useful,
15*415a613bSKumar Gala  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16*415a613bSKumar Gala  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
17*415a613bSKumar Gala  * GNU General Public License for more details.
18*415a613bSKumar Gala  *
19*415a613bSKumar Gala  * You should have received a copy of the GNU General Public License
20*415a613bSKumar Gala  * along with this program; if not, write to the Free Software
21*415a613bSKumar Gala  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22*415a613bSKumar Gala  * MA 02111-1307 USA
23*415a613bSKumar Gala  */
24*415a613bSKumar Gala 
25*415a613bSKumar Gala #include <common.h>
26*415a613bSKumar Gala #include <pci.h>
27*415a613bSKumar Gala #include <asm/processor.h>
28*415a613bSKumar Gala #include <asm/immap_85xx.h>
29*415a613bSKumar Gala #include <asm/immap_fsl_pci.h>
30*415a613bSKumar Gala #include <spd.h>
31*415a613bSKumar Gala #include <miiphy.h>
32*415a613bSKumar Gala #include <libfdt.h>
33*415a613bSKumar Gala #include <fdt_support.h>
34*415a613bSKumar Gala 
35*415a613bSKumar Gala #include "../common/cadmus.h"
36*415a613bSKumar Gala #include "../common/eeprom.h"
37*415a613bSKumar Gala #include "../common/via.h"
38*415a613bSKumar Gala 
39*415a613bSKumar Gala #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
40*415a613bSKumar Gala extern void ddr_enable_ecc(unsigned int dram_size);
41*415a613bSKumar Gala #endif
42*415a613bSKumar Gala 
43*415a613bSKumar Gala DECLARE_GLOBAL_DATA_PTR;
44*415a613bSKumar Gala 
45*415a613bSKumar Gala extern long int spd_sdram(void);
46*415a613bSKumar Gala 
47*415a613bSKumar Gala void local_bus_init(void);
48*415a613bSKumar Gala void sdram_init(void);
49*415a613bSKumar Gala 
50*415a613bSKumar Gala int board_early_init_f (void)
51*415a613bSKumar Gala {
52*415a613bSKumar Gala 	return 0;
53*415a613bSKumar Gala }
54*415a613bSKumar Gala 
55*415a613bSKumar Gala int checkboard (void)
56*415a613bSKumar Gala {
57*415a613bSKumar Gala 	volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
58*415a613bSKumar Gala 	volatile ccsr_local_ecm_t *ecm = (void *)(CFG_MPC85xx_ECM_ADDR);
59*415a613bSKumar Gala 
60*415a613bSKumar Gala 	/* PCI slot in USER bits CSR[6:7] by convention. */
61*415a613bSKumar Gala 	uint pci_slot = get_pci_slot ();
62*415a613bSKumar Gala 
63*415a613bSKumar Gala 	uint cpu_board_rev = get_cpu_board_revision ();
64*415a613bSKumar Gala 
65*415a613bSKumar Gala 	printf ("Board: CDS Version 0x%02x, PCI Slot %d\n",
66*415a613bSKumar Gala 		get_board_version (), pci_slot);
67*415a613bSKumar Gala 
68*415a613bSKumar Gala 	printf ("CPU Board Revision %d.%d (0x%04x)\n",
69*415a613bSKumar Gala 		MPC85XX_CPU_BOARD_MAJOR (cpu_board_rev),
70*415a613bSKumar Gala 		MPC85XX_CPU_BOARD_MINOR (cpu_board_rev), cpu_board_rev);
71*415a613bSKumar Gala 	/*
72*415a613bSKumar Gala 	 * Initialize local bus.
73*415a613bSKumar Gala 	 */
74*415a613bSKumar Gala 	local_bus_init ();
75*415a613bSKumar Gala 
76*415a613bSKumar Gala 	/*
77*415a613bSKumar Gala 	 * Fix CPU2 errata: A core hang possible while executing a
78*415a613bSKumar Gala 	 * msync instruction and a snoopable transaction from an I/O
79*415a613bSKumar Gala 	 * master tagged to make quick forward progress is present.
80*415a613bSKumar Gala 	 */
81*415a613bSKumar Gala 	ecm->eebpcr |= (1 << 16);
82*415a613bSKumar Gala 
83*415a613bSKumar Gala 	/*
84*415a613bSKumar Gala 	 * Hack TSEC 3 and 4 IO voltages.
85*415a613bSKumar Gala 	 */
86*415a613bSKumar Gala 	gur->tsec34ioovcr = 0xe7e0;	/*  1110 0111 1110 0xxx */
87*415a613bSKumar Gala 
88*415a613bSKumar Gala 	ecm->eedr = 0xffffffff;		/* clear ecm errors */
89*415a613bSKumar Gala 	ecm->eeer = 0xffffffff;		/* enable ecm errors */
90*415a613bSKumar Gala 	return 0;
91*415a613bSKumar Gala }
92*415a613bSKumar Gala 
93*415a613bSKumar Gala long int
94*415a613bSKumar Gala initdram(int board_type)
95*415a613bSKumar Gala {
96*415a613bSKumar Gala 	long dram_size = 0;
97*415a613bSKumar Gala 
98*415a613bSKumar Gala 	puts("Initializing\n");
99*415a613bSKumar Gala 
100*415a613bSKumar Gala #if defined(CONFIG_DDR_DLL)
101*415a613bSKumar Gala 	{
102*415a613bSKumar Gala 		/*
103*415a613bSKumar Gala 		 * Work around to stabilize DDR DLL MSYNC_IN.
104*415a613bSKumar Gala 		 * Errata DDR9 seems to have been fixed.
105*415a613bSKumar Gala 		 * This is now the workaround for Errata DDR11:
106*415a613bSKumar Gala 		 *    Override DLL = 1, Course Adj = 1, Tap Select = 0
107*415a613bSKumar Gala 		 */
108*415a613bSKumar Gala 
109*415a613bSKumar Gala 		volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
110*415a613bSKumar Gala 
111*415a613bSKumar Gala 		gur->ddrdllcr = 0x81000000;
112*415a613bSKumar Gala 		asm("sync;isync;msync");
113*415a613bSKumar Gala 		udelay(200);
114*415a613bSKumar Gala 	}
115*415a613bSKumar Gala #endif
116*415a613bSKumar Gala 	dram_size = spd_sdram();
117*415a613bSKumar Gala 
118*415a613bSKumar Gala #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
119*415a613bSKumar Gala 	/*
120*415a613bSKumar Gala 	 * Initialize and enable DDR ECC.
121*415a613bSKumar Gala 	 */
122*415a613bSKumar Gala 	ddr_enable_ecc(dram_size);
123*415a613bSKumar Gala #endif
124*415a613bSKumar Gala 	/*
125*415a613bSKumar Gala 	 * SDRAM Initialization
126*415a613bSKumar Gala 	 */
127*415a613bSKumar Gala 	sdram_init();
128*415a613bSKumar Gala 
129*415a613bSKumar Gala 	puts("    DDR: ");
130*415a613bSKumar Gala 	return dram_size;
131*415a613bSKumar Gala }
132*415a613bSKumar Gala 
133*415a613bSKumar Gala /*
134*415a613bSKumar Gala  * Initialize Local Bus
135*415a613bSKumar Gala  */
136*415a613bSKumar Gala void
137*415a613bSKumar Gala local_bus_init(void)
138*415a613bSKumar Gala {
139*415a613bSKumar Gala 	volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
140*415a613bSKumar Gala 	volatile ccsr_lbc_t *lbc = (void *)(CFG_MPC85xx_LBC_ADDR);
141*415a613bSKumar Gala 
142*415a613bSKumar Gala 	uint clkdiv;
143*415a613bSKumar Gala 	uint lbc_hz;
144*415a613bSKumar Gala 	sys_info_t sysinfo;
145*415a613bSKumar Gala 
146*415a613bSKumar Gala 	get_sys_info(&sysinfo);
147*415a613bSKumar Gala 	clkdiv = (lbc->lcrr & 0x0f) * 2;
148*415a613bSKumar Gala 	lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
149*415a613bSKumar Gala 
150*415a613bSKumar Gala 	gur->lbiuiplldcr1 = 0x00078080;
151*415a613bSKumar Gala 	if (clkdiv == 16) {
152*415a613bSKumar Gala 		gur->lbiuiplldcr0 = 0x7c0f1bf0;
153*415a613bSKumar Gala 	} else if (clkdiv == 8) {
154*415a613bSKumar Gala 		gur->lbiuiplldcr0 = 0x6c0f1bf0;
155*415a613bSKumar Gala 	} else if (clkdiv == 4) {
156*415a613bSKumar Gala 		gur->lbiuiplldcr0 = 0x5c0f1bf0;
157*415a613bSKumar Gala 	}
158*415a613bSKumar Gala 
159*415a613bSKumar Gala 	lbc->lcrr |= 0x00030000;
160*415a613bSKumar Gala 
161*415a613bSKumar Gala 	asm("sync;isync;msync");
162*415a613bSKumar Gala 
163*415a613bSKumar Gala 	lbc->ltesr = 0xffffffff;	/* Clear LBC error interrupts */
164*415a613bSKumar Gala 	lbc->lteir = 0xffffffff;	/* Enable LBC error interrupts */
165*415a613bSKumar Gala }
166*415a613bSKumar Gala 
167*415a613bSKumar Gala /*
168*415a613bSKumar Gala  * Initialize SDRAM memory on the Local Bus.
169*415a613bSKumar Gala  */
170*415a613bSKumar Gala void
171*415a613bSKumar Gala sdram_init(void)
172*415a613bSKumar Gala {
173*415a613bSKumar Gala #if defined(CFG_OR2_PRELIM) && defined(CFG_BR2_PRELIM)
174*415a613bSKumar Gala 
175*415a613bSKumar Gala 	uint idx;
176*415a613bSKumar Gala 	volatile ccsr_lbc_t *lbc = (void *)(CFG_MPC85xx_LBC_ADDR);
177*415a613bSKumar Gala 	uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE;
178*415a613bSKumar Gala 	uint cpu_board_rev;
179*415a613bSKumar Gala 	uint lsdmr_common;
180*415a613bSKumar Gala 
181*415a613bSKumar Gala 	puts("    SDRAM: ");
182*415a613bSKumar Gala 
183*415a613bSKumar Gala 	print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
184*415a613bSKumar Gala 
185*415a613bSKumar Gala 	/*
186*415a613bSKumar Gala 	 * Setup SDRAM Base and Option Registers
187*415a613bSKumar Gala 	 */
188*415a613bSKumar Gala 	lbc->or2 = CFG_OR2_PRELIM;
189*415a613bSKumar Gala 	asm("msync");
190*415a613bSKumar Gala 
191*415a613bSKumar Gala 	lbc->br2 = CFG_BR2_PRELIM;
192*415a613bSKumar Gala 	asm("msync");
193*415a613bSKumar Gala 
194*415a613bSKumar Gala 	lbc->lbcr = CFG_LBC_LBCR;
195*415a613bSKumar Gala 	asm("msync");
196*415a613bSKumar Gala 
197*415a613bSKumar Gala 
198*415a613bSKumar Gala 	lbc->lsrt = CFG_LBC_LSRT;
199*415a613bSKumar Gala 	lbc->mrtpr = CFG_LBC_MRTPR;
200*415a613bSKumar Gala 	asm("msync");
201*415a613bSKumar Gala 
202*415a613bSKumar Gala 	/*
203*415a613bSKumar Gala 	 * MPC8548 uses "new" 15-16 style addressing.
204*415a613bSKumar Gala 	 */
205*415a613bSKumar Gala 	cpu_board_rev = get_cpu_board_revision();
206*415a613bSKumar Gala 	lsdmr_common = CFG_LBC_LSDMR_COMMON;
207*415a613bSKumar Gala 	lsdmr_common |= CFG_LBC_LSDMR_BSMA1516;
208*415a613bSKumar Gala 
209*415a613bSKumar Gala 	/*
210*415a613bSKumar Gala 	 * Issue PRECHARGE ALL command.
211*415a613bSKumar Gala 	 */
212*415a613bSKumar Gala 	lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_PCHALL;
213*415a613bSKumar Gala 	asm("sync;msync");
214*415a613bSKumar Gala 	*sdram_addr = 0xff;
215*415a613bSKumar Gala 	ppcDcbf((unsigned long) sdram_addr);
216*415a613bSKumar Gala 	udelay(100);
217*415a613bSKumar Gala 
218*415a613bSKumar Gala 	/*
219*415a613bSKumar Gala 	 * Issue 8 AUTO REFRESH commands.
220*415a613bSKumar Gala 	 */
221*415a613bSKumar Gala 	for (idx = 0; idx < 8; idx++) {
222*415a613bSKumar Gala 		lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_ARFRSH;
223*415a613bSKumar Gala 		asm("sync;msync");
224*415a613bSKumar Gala 		*sdram_addr = 0xff;
225*415a613bSKumar Gala 		ppcDcbf((unsigned long) sdram_addr);
226*415a613bSKumar Gala 		udelay(100);
227*415a613bSKumar Gala 	}
228*415a613bSKumar Gala 
229*415a613bSKumar Gala 	/*
230*415a613bSKumar Gala 	 * Issue 8 MODE-set command.
231*415a613bSKumar Gala 	 */
232*415a613bSKumar Gala 	lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_MRW;
233*415a613bSKumar Gala 	asm("sync;msync");
234*415a613bSKumar Gala 	*sdram_addr = 0xff;
235*415a613bSKumar Gala 	ppcDcbf((unsigned long) sdram_addr);
236*415a613bSKumar Gala 	udelay(100);
237*415a613bSKumar Gala 
238*415a613bSKumar Gala 	/*
239*415a613bSKumar Gala 	 * Issue NORMAL OP command.
240*415a613bSKumar Gala 	 */
241*415a613bSKumar Gala 	lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_NORMAL;
242*415a613bSKumar Gala 	asm("sync;msync");
243*415a613bSKumar Gala 	*sdram_addr = 0xff;
244*415a613bSKumar Gala 	ppcDcbf((unsigned long) sdram_addr);
245*415a613bSKumar Gala 	udelay(200);    /* Overkill. Must wait > 200 bus cycles */
246*415a613bSKumar Gala 
247*415a613bSKumar Gala #endif	/* enable SDRAM init */
248*415a613bSKumar Gala }
249*415a613bSKumar Gala 
250*415a613bSKumar Gala #if defined(CFG_DRAM_TEST)
251*415a613bSKumar Gala int
252*415a613bSKumar Gala testdram(void)
253*415a613bSKumar Gala {
254*415a613bSKumar Gala 	uint *pstart = (uint *) CFG_MEMTEST_START;
255*415a613bSKumar Gala 	uint *pend = (uint *) CFG_MEMTEST_END;
256*415a613bSKumar Gala 	uint *p;
257*415a613bSKumar Gala 
258*415a613bSKumar Gala 	printf("Testing DRAM from 0x%08x to 0x%08x\n",
259*415a613bSKumar Gala 	       CFG_MEMTEST_START,
260*415a613bSKumar Gala 	       CFG_MEMTEST_END);
261*415a613bSKumar Gala 
262*415a613bSKumar Gala 	printf("DRAM test phase 1:\n");
263*415a613bSKumar Gala 	for (p = pstart; p < pend; p++)
264*415a613bSKumar Gala 		*p = 0xaaaaaaaa;
265*415a613bSKumar Gala 
266*415a613bSKumar Gala 	for (p = pstart; p < pend; p++) {
267*415a613bSKumar Gala 		if (*p != 0xaaaaaaaa) {
268*415a613bSKumar Gala 			printf ("DRAM test fails at: %08x\n", (uint) p);
269*415a613bSKumar Gala 			return 1;
270*415a613bSKumar Gala 		}
271*415a613bSKumar Gala 	}
272*415a613bSKumar Gala 
273*415a613bSKumar Gala 	printf("DRAM test phase 2:\n");
274*415a613bSKumar Gala 	for (p = pstart; p < pend; p++)
275*415a613bSKumar Gala 		*p = 0x55555555;
276*415a613bSKumar Gala 
277*415a613bSKumar Gala 	for (p = pstart; p < pend; p++) {
278*415a613bSKumar Gala 		if (*p != 0x55555555) {
279*415a613bSKumar Gala 			printf ("DRAM test fails at: %08x\n", (uint) p);
280*415a613bSKumar Gala 			return 1;
281*415a613bSKumar Gala 		}
282*415a613bSKumar Gala 	}
283*415a613bSKumar Gala 
284*415a613bSKumar Gala 	printf("DRAM test passed.\n");
285*415a613bSKumar Gala 	return 0;
286*415a613bSKumar Gala }
287*415a613bSKumar Gala #endif
288*415a613bSKumar Gala 
289*415a613bSKumar Gala #if defined(CONFIG_PCI) || defined(CONFIG_PCI1)
290*415a613bSKumar Gala /* For some reason the Tundra PCI bridge shows up on itself as a
291*415a613bSKumar Gala  * different device.  Work around that by refusing to configure it.
292*415a613bSKumar Gala  */
293*415a613bSKumar Gala void dummy_func(struct pci_controller* hose, pci_dev_t dev, struct pci_config_table *tab) { }
294*415a613bSKumar Gala 
295*415a613bSKumar Gala static struct pci_config_table pci_mpc85xxcds_config_table[] = {
296*415a613bSKumar Gala 	{0x10e3, 0x0513, PCI_ANY_ID, 1, 3, PCI_ANY_ID, dummy_func, {0,0,0}},
297*415a613bSKumar Gala 	{0x1106, 0x0686, PCI_ANY_ID, 1, VIA_ID, 0, mpc85xx_config_via, {0,0,0}},
298*415a613bSKumar Gala 	{0x1106, 0x0571, PCI_ANY_ID, 1, VIA_ID, 1,
299*415a613bSKumar Gala 		mpc85xx_config_via_usbide, {0,0,0}},
300*415a613bSKumar Gala 	{0x1105, 0x3038, PCI_ANY_ID, 1, VIA_ID, 2,
301*415a613bSKumar Gala 		mpc85xx_config_via_usb, {0,0,0}},
302*415a613bSKumar Gala 	{0x1106, 0x3038, PCI_ANY_ID, 1, VIA_ID, 3,
303*415a613bSKumar Gala 		mpc85xx_config_via_usb2, {0,0,0}},
304*415a613bSKumar Gala 	{0x1106, 0x3058, PCI_ANY_ID, 1, VIA_ID, 5,
305*415a613bSKumar Gala 		mpc85xx_config_via_power, {0,0,0}},
306*415a613bSKumar Gala 	{0x1106, 0x3068, PCI_ANY_ID, 1, VIA_ID, 6,
307*415a613bSKumar Gala 		mpc85xx_config_via_ac97, {0,0,0}},
308*415a613bSKumar Gala 	{},
309*415a613bSKumar Gala };
310*415a613bSKumar Gala 
311*415a613bSKumar Gala static struct pci_controller pci1_hose = {
312*415a613bSKumar Gala 	config_table: pci_mpc85xxcds_config_table};
313*415a613bSKumar Gala #endif	/* CONFIG_PCI */
314*415a613bSKumar Gala 
315*415a613bSKumar Gala #ifdef CONFIG_PCI2
316*415a613bSKumar Gala static struct pci_controller pci2_hose;
317*415a613bSKumar Gala #endif	/* CONFIG_PCI2 */
318*415a613bSKumar Gala 
319*415a613bSKumar Gala #ifdef CONFIG_PCIE1
320*415a613bSKumar Gala static struct pci_controller pcie1_hose;
321*415a613bSKumar Gala #endif	/* CONFIG_PCIE1 */
322*415a613bSKumar Gala 
323*415a613bSKumar Gala int first_free_busno=0;
324*415a613bSKumar Gala 
325*415a613bSKumar Gala void
326*415a613bSKumar Gala pci_init_board(void)
327*415a613bSKumar Gala {
328*415a613bSKumar Gala 	volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
329*415a613bSKumar Gala 	uint io_sel = (gur->pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
330*415a613bSKumar Gala 	uint host_agent = (gur->porbmsr & MPC85xx_PORBMSR_HA) >> 16;
331*415a613bSKumar Gala 
332*415a613bSKumar Gala 
333*415a613bSKumar Gala #ifdef CONFIG_PCI1
334*415a613bSKumar Gala {
335*415a613bSKumar Gala 	volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCI1_ADDR;
336*415a613bSKumar Gala 	extern void fsl_pci_init(struct pci_controller *hose);
337*415a613bSKumar Gala 	struct pci_controller *hose = &pci1_hose;
338*415a613bSKumar Gala 	struct pci_config_table *table;
339*415a613bSKumar Gala 
340*415a613bSKumar Gala 	uint pci_32 = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_PCI32;	/* PORDEVSR[15] */
341*415a613bSKumar Gala 	uint pci_arb = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_ARB;	/* PORDEVSR[14] */
342*415a613bSKumar Gala 	uint pci_clk_sel = gur->porpllsr & MPC85xx_PORDEVSR_PCI1_SPD;	/* PORPLLSR[16] */
343*415a613bSKumar Gala 
344*415a613bSKumar Gala 	uint pci_agent = (host_agent == 3) || (host_agent == 4 ) || (host_agent == 6);
345*415a613bSKumar Gala 
346*415a613bSKumar Gala 	uint pci_speed = get_clock_freq ();	/* PCI PSPEED in [4:5] */
347*415a613bSKumar Gala 
348*415a613bSKumar Gala 	if (!(gur->devdisr & MPC85xx_DEVDISR_PCI1)) {
349*415a613bSKumar Gala 		printf ("    PCI: %d bit, %s MHz, %s, %s, %s\n",
350*415a613bSKumar Gala 			(pci_32) ? 32 : 64,
351*415a613bSKumar Gala 			(pci_speed == 33333000) ? "33" :
352*415a613bSKumar Gala 			(pci_speed == 66666000) ? "66" : "unknown",
353*415a613bSKumar Gala 			pci_clk_sel ? "sync" : "async",
354*415a613bSKumar Gala 			pci_agent ? "agent" : "host",
355*415a613bSKumar Gala 			pci_arb ? "arbiter" : "external-arbiter"
356*415a613bSKumar Gala 			);
357*415a613bSKumar Gala 
358*415a613bSKumar Gala 
359*415a613bSKumar Gala 		/* inbound */
360*415a613bSKumar Gala 		pci_set_region(hose->regions + 0,
361*415a613bSKumar Gala 			       CFG_PCI_MEMORY_BUS,
362*415a613bSKumar Gala 			       CFG_PCI_MEMORY_PHYS,
363*415a613bSKumar Gala 			       CFG_PCI_MEMORY_SIZE,
364*415a613bSKumar Gala 			       PCI_REGION_MEM | PCI_REGION_MEMORY);
365*415a613bSKumar Gala 
366*415a613bSKumar Gala 
367*415a613bSKumar Gala 		/* outbound memory */
368*415a613bSKumar Gala 		pci_set_region(hose->regions + 1,
369*415a613bSKumar Gala 			       CFG_PCI1_MEM_BASE,
370*415a613bSKumar Gala 			       CFG_PCI1_MEM_PHYS,
371*415a613bSKumar Gala 			       CFG_PCI1_MEM_SIZE,
372*415a613bSKumar Gala 			       PCI_REGION_MEM);
373*415a613bSKumar Gala 
374*415a613bSKumar Gala 		/* outbound io */
375*415a613bSKumar Gala 		pci_set_region(hose->regions + 2,
376*415a613bSKumar Gala 			       CFG_PCI1_IO_BASE,
377*415a613bSKumar Gala 			       CFG_PCI1_IO_PHYS,
378*415a613bSKumar Gala 			       CFG_PCI1_IO_SIZE,
379*415a613bSKumar Gala 			       PCI_REGION_IO);
380*415a613bSKumar Gala 		hose->region_count = 3;
381*415a613bSKumar Gala 
382*415a613bSKumar Gala 		/* relocate config table pointers */
383*415a613bSKumar Gala 		hose->config_table = \
384*415a613bSKumar Gala 			(struct pci_config_table *)((uint)hose->config_table + gd->reloc_off);
385*415a613bSKumar Gala 		for (table = hose->config_table; table && table->vendor; table++)
386*415a613bSKumar Gala 			table->config_device += gd->reloc_off;
387*415a613bSKumar Gala 
388*415a613bSKumar Gala 		hose->first_busno=first_free_busno;
389*415a613bSKumar Gala 		pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
390*415a613bSKumar Gala 
391*415a613bSKumar Gala 		fsl_pci_init(hose);
392*415a613bSKumar Gala 		first_free_busno=hose->last_busno+1;
393*415a613bSKumar Gala 		printf ("PCI on bus %02x - %02x\n",hose->first_busno,hose->last_busno);
394*415a613bSKumar Gala #ifdef CONFIG_PCIX_CHECK
395*415a613bSKumar Gala 		if (!(gur->pordevsr & PORDEVSR_PCI)) {
396*415a613bSKumar Gala 			/* PCI-X init */
397*415a613bSKumar Gala 			if (CONFIG_SYS_CLK_FREQ < 66000000)
398*415a613bSKumar Gala 				printf("PCI-X will only work at 66 MHz\n");
399*415a613bSKumar Gala 
400*415a613bSKumar Gala 			reg16 = PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ
401*415a613bSKumar Gala 				| PCI_X_CMD_ERO | PCI_X_CMD_DPERR_E;
402*415a613bSKumar Gala 			pci_hose_write_config_word(hose, bus, PCIX_COMMAND, reg16);
403*415a613bSKumar Gala 		}
404*415a613bSKumar Gala #endif
405*415a613bSKumar Gala 	} else {
406*415a613bSKumar Gala 		printf ("    PCI: disabled\n");
407*415a613bSKumar Gala 	}
408*415a613bSKumar Gala }
409*415a613bSKumar Gala #else
410*415a613bSKumar Gala 	gur->devdisr |= MPC85xx_DEVDISR_PCI1; /* disable */
411*415a613bSKumar Gala #endif
412*415a613bSKumar Gala 
413*415a613bSKumar Gala #ifdef CONFIG_PCI2
414*415a613bSKumar Gala {
415*415a613bSKumar Gala 	uint pci2_clk_sel = gur->porpllsr & 0x4000;	/* PORPLLSR[17] */
416*415a613bSKumar Gala 	uint pci_dual = get_pci_dual ();	/* PCI DUAL in CM_PCI[3] */
417*415a613bSKumar Gala 	if (pci_dual) {
418*415a613bSKumar Gala 		printf ("    PCI2: 32 bit, 66 MHz, %s\n",
419*415a613bSKumar Gala 			pci2_clk_sel ? "sync" : "async");
420*415a613bSKumar Gala 	} else {
421*415a613bSKumar Gala 		printf ("    PCI2: disabled\n");
422*415a613bSKumar Gala 	}
423*415a613bSKumar Gala }
424*415a613bSKumar Gala #else
425*415a613bSKumar Gala 	gur->devdisr |= MPC85xx_DEVDISR_PCI2; /* disable */
426*415a613bSKumar Gala #endif /* CONFIG_PCI2 */
427*415a613bSKumar Gala 
428*415a613bSKumar Gala #ifdef CONFIG_PCIE1
429*415a613bSKumar Gala {
430*415a613bSKumar Gala 	volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCIE1_ADDR;
431*415a613bSKumar Gala 	extern void fsl_pci_init(struct pci_controller *hose);
432*415a613bSKumar Gala 	struct pci_controller *hose = &pcie1_hose;
433*415a613bSKumar Gala 	int pcie_ep =  (host_agent == 0) || (host_agent == 2 ) || (host_agent == 3);
434*415a613bSKumar Gala 
435*415a613bSKumar Gala 	int pcie_configured  = io_sel >= 1;
436*415a613bSKumar Gala 
437*415a613bSKumar Gala 	if (pcie_configured && !(gur->devdisr & MPC85xx_DEVDISR_PCIE)){
438*415a613bSKumar Gala 		printf ("\n    PCIE connected to slot as %s (base address %x)",
439*415a613bSKumar Gala 			pcie_ep ? "End Point" : "Root Complex",
440*415a613bSKumar Gala 			(uint)pci);
441*415a613bSKumar Gala 
442*415a613bSKumar Gala 		if (pci->pme_msg_det) {
443*415a613bSKumar Gala 			pci->pme_msg_det = 0xffffffff;
444*415a613bSKumar Gala 			debug (" with errors.  Clearing.  Now 0x%08x",pci->pme_msg_det);
445*415a613bSKumar Gala 		}
446*415a613bSKumar Gala 		printf ("\n");
447*415a613bSKumar Gala 
448*415a613bSKumar Gala 		/* inbound */
449*415a613bSKumar Gala 		pci_set_region(hose->regions + 0,
450*415a613bSKumar Gala 			       CFG_PCI_MEMORY_BUS,
451*415a613bSKumar Gala 			       CFG_PCI_MEMORY_PHYS,
452*415a613bSKumar Gala 			       CFG_PCI_MEMORY_SIZE,
453*415a613bSKumar Gala 			       PCI_REGION_MEM | PCI_REGION_MEMORY);
454*415a613bSKumar Gala 
455*415a613bSKumar Gala 		/* outbound memory */
456*415a613bSKumar Gala 		pci_set_region(hose->regions + 1,
457*415a613bSKumar Gala 			       CFG_PCIE1_MEM_BASE,
458*415a613bSKumar Gala 			       CFG_PCIE1_MEM_PHYS,
459*415a613bSKumar Gala 			       CFG_PCIE1_MEM_SIZE,
460*415a613bSKumar Gala 			       PCI_REGION_MEM);
461*415a613bSKumar Gala 
462*415a613bSKumar Gala 		/* outbound io */
463*415a613bSKumar Gala 		pci_set_region(hose->regions + 2,
464*415a613bSKumar Gala 			       CFG_PCIE1_IO_BASE,
465*415a613bSKumar Gala 			       CFG_PCIE1_IO_PHYS,
466*415a613bSKumar Gala 			       CFG_PCIE1_IO_SIZE,
467*415a613bSKumar Gala 			       PCI_REGION_IO);
468*415a613bSKumar Gala 
469*415a613bSKumar Gala 		hose->region_count = 3;
470*415a613bSKumar Gala 
471*415a613bSKumar Gala 		hose->first_busno=first_free_busno;
472*415a613bSKumar Gala 		pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
473*415a613bSKumar Gala 
474*415a613bSKumar Gala 		fsl_pci_init(hose);
475*415a613bSKumar Gala 		printf ("PCIE on bus %d - %d\n",hose->first_busno,hose->last_busno);
476*415a613bSKumar Gala 
477*415a613bSKumar Gala 		first_free_busno=hose->last_busno+1;
478*415a613bSKumar Gala 
479*415a613bSKumar Gala 	} else {
480*415a613bSKumar Gala 		printf ("    PCIE: disabled\n");
481*415a613bSKumar Gala 	}
482*415a613bSKumar Gala  }
483*415a613bSKumar Gala #else
484*415a613bSKumar Gala 	gur->devdisr |= MPC85xx_DEVDISR_PCIE; /* disable */
485*415a613bSKumar Gala #endif
486*415a613bSKumar Gala 
487*415a613bSKumar Gala }
488*415a613bSKumar Gala 
489*415a613bSKumar Gala int last_stage_init(void)
490*415a613bSKumar Gala {
491*415a613bSKumar Gala 	unsigned short temp;
492*415a613bSKumar Gala 
493*415a613bSKumar Gala 	/* Change the resistors for the PHY */
494*415a613bSKumar Gala 	/* This is needed to get the RGMII working for the 1.3+
495*415a613bSKumar Gala 	 * CDS cards */
496*415a613bSKumar Gala 	if (get_board_version() ==  0x13) {
497*415a613bSKumar Gala 		miiphy_write(CONFIG_TSEC1_NAME,
498*415a613bSKumar Gala 				TSEC1_PHY_ADDR, 29, 18);
499*415a613bSKumar Gala 
500*415a613bSKumar Gala 		miiphy_read(CONFIG_TSEC1_NAME,
501*415a613bSKumar Gala 				TSEC1_PHY_ADDR, 30, &temp);
502*415a613bSKumar Gala 
503*415a613bSKumar Gala 		temp = (temp & 0xf03f);
504*415a613bSKumar Gala 		temp |= 2 << 9;		/* 36 ohm */
505*415a613bSKumar Gala 		temp |= 2 << 6;		/* 39 ohm */
506*415a613bSKumar Gala 
507*415a613bSKumar Gala 		miiphy_write(CONFIG_TSEC1_NAME,
508*415a613bSKumar Gala 				TSEC1_PHY_ADDR, 30, temp);
509*415a613bSKumar Gala 
510*415a613bSKumar Gala 		miiphy_write(CONFIG_TSEC1_NAME,
511*415a613bSKumar Gala 				TSEC1_PHY_ADDR, 29, 3);
512*415a613bSKumar Gala 
513*415a613bSKumar Gala 		miiphy_write(CONFIG_TSEC1_NAME,
514*415a613bSKumar Gala 				TSEC1_PHY_ADDR, 30, 0x8000);
515*415a613bSKumar Gala 	}
516*415a613bSKumar Gala 
517*415a613bSKumar Gala 	return 0;
518*415a613bSKumar Gala }
519*415a613bSKumar Gala 
520*415a613bSKumar Gala 
521*415a613bSKumar Gala #if defined(CONFIG_OF_BOARD_SETUP)
522*415a613bSKumar Gala void
523*415a613bSKumar Gala ft_pci_setup(void *blob, bd_t *bd)
524*415a613bSKumar Gala {
525*415a613bSKumar Gala 	int node, tmp[2];
526*415a613bSKumar Gala 	const char *path;
527*415a613bSKumar Gala 
528*415a613bSKumar Gala 	node = fdt_path_offset(blob, "/aliases");
529*415a613bSKumar Gala 	tmp[0] = 0;
530*415a613bSKumar Gala 	if (node >= 0) {
531*415a613bSKumar Gala #ifdef CONFIG_PCI1
532*415a613bSKumar Gala 		path = fdt_getprop(blob, node, "pci0", NULL);
533*415a613bSKumar Gala 		if (path) {
534*415a613bSKumar Gala 			tmp[1] = pci1_hose.last_busno - pci1_hose.first_busno;
535*415a613bSKumar Gala 			do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
536*415a613bSKumar Gala 		}
537*415a613bSKumar Gala #endif
538*415a613bSKumar Gala #ifdef CONFIG_PCIE1
539*415a613bSKumar Gala 		path = fdt_getprop(blob, node, "pci1", NULL);
540*415a613bSKumar Gala 		if (path) {
541*415a613bSKumar Gala 			tmp[1] = pcie1_hose.last_busno - pcie1_hose.first_busno;
542*415a613bSKumar Gala 			do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
543*415a613bSKumar Gala 		}
544*415a613bSKumar Gala #endif
545*415a613bSKumar Gala 	}
546*415a613bSKumar Gala }
547*415a613bSKumar Gala #endif
548