xref: /rk3399_rockchip-uboot/board/freescale/mpc8548cds/mpc8548cds.c (revision 2dba0dea98c0dee1799ffd6fd6eb541645dbbd98)
1415a613bSKumar Gala /*
2415a613bSKumar Gala  * Copyright 2004, 2007 Freescale Semiconductor.
3415a613bSKumar Gala  *
4415a613bSKumar Gala  * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com>
5415a613bSKumar Gala  *
6415a613bSKumar Gala  * See file CREDITS for list of people who contributed to this
7415a613bSKumar Gala  * project.
8415a613bSKumar Gala  *
9415a613bSKumar Gala  * This program is free software; you can redistribute it and/or
10415a613bSKumar Gala  * modify it under the terms of the GNU General Public License as
11415a613bSKumar Gala  * published by the Free Software Foundation; either version 2 of
12415a613bSKumar Gala  * the License, or (at your option) any later version.
13415a613bSKumar Gala  *
14415a613bSKumar Gala  * This program is distributed in the hope that it will be useful,
15415a613bSKumar Gala  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16415a613bSKumar Gala  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
17415a613bSKumar Gala  * GNU General Public License for more details.
18415a613bSKumar Gala  *
19415a613bSKumar Gala  * You should have received a copy of the GNU General Public License
20415a613bSKumar Gala  * along with this program; if not, write to the Free Software
21415a613bSKumar Gala  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22415a613bSKumar Gala  * MA 02111-1307 USA
23415a613bSKumar Gala  */
24415a613bSKumar Gala 
25415a613bSKumar Gala #include <common.h>
26415a613bSKumar Gala #include <pci.h>
27415a613bSKumar Gala #include <asm/processor.h>
28e31d2c1eSJon Loeliger #include <asm/mmu.h>
29415a613bSKumar Gala #include <asm/immap_85xx.h>
30415a613bSKumar Gala #include <asm/immap_fsl_pci.h>
31e31d2c1eSJon Loeliger #include <asm/fsl_ddr_sdram.h>
32a30a549aSJon Loeliger #include <spd_sdram.h>
33415a613bSKumar Gala #include <miiphy.h>
34415a613bSKumar Gala #include <libfdt.h>
35415a613bSKumar Gala #include <fdt_support.h>
36415a613bSKumar Gala 
37415a613bSKumar Gala #include "../common/cadmus.h"
38415a613bSKumar Gala #include "../common/eeprom.h"
39415a613bSKumar Gala #include "../common/via.h"
40415a613bSKumar Gala 
41415a613bSKumar Gala #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
42415a613bSKumar Gala extern void ddr_enable_ecc(unsigned int dram_size);
43415a613bSKumar Gala #endif
44415a613bSKumar Gala 
45415a613bSKumar Gala DECLARE_GLOBAL_DATA_PTR;
46415a613bSKumar Gala 
47415a613bSKumar Gala void local_bus_init(void);
48415a613bSKumar Gala void sdram_init(void);
49415a613bSKumar Gala 
50415a613bSKumar Gala int checkboard (void)
51415a613bSKumar Gala {
526d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
536d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	volatile ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR);
54415a613bSKumar Gala 
55415a613bSKumar Gala 	/* PCI slot in USER bits CSR[6:7] by convention. */
56415a613bSKumar Gala 	uint pci_slot = get_pci_slot ();
57415a613bSKumar Gala 
58415a613bSKumar Gala 	uint cpu_board_rev = get_cpu_board_revision ();
5966f5fa92SAndy Fleming 	uint svr;
60415a613bSKumar Gala 
61415a613bSKumar Gala 	printf ("Board: CDS Version 0x%02x, PCI Slot %d\n",
62415a613bSKumar Gala 		get_board_version (), pci_slot);
63415a613bSKumar Gala 
64415a613bSKumar Gala 	printf ("CPU Board Revision %d.%d (0x%04x)\n",
65415a613bSKumar Gala 		MPC85XX_CPU_BOARD_MAJOR (cpu_board_rev),
66415a613bSKumar Gala 		MPC85XX_CPU_BOARD_MINOR (cpu_board_rev), cpu_board_rev);
67415a613bSKumar Gala 	/*
68415a613bSKumar Gala 	 * Initialize local bus.
69415a613bSKumar Gala 	 */
70415a613bSKumar Gala 	local_bus_init ();
71415a613bSKumar Gala 
7266f5fa92SAndy Fleming 	svr = get_svr();
7366f5fa92SAndy Fleming 
74415a613bSKumar Gala 	/*
75415a613bSKumar Gala 	 * Fix CPU2 errata: A core hang possible while executing a
76415a613bSKumar Gala 	 * msync instruction and a snoopable transaction from an I/O
77415a613bSKumar Gala 	 * master tagged to make quick forward progress is present.
7866f5fa92SAndy Fleming 	 * Fixed in Silicon Rev.2.1
79415a613bSKumar Gala 	 */
8066f5fa92SAndy Fleming 	if (!(SVR_MAJ(svr) >= 2 && SVR_MIN(svr) >= 1))
81415a613bSKumar Gala 		ecm->eebpcr |= (1 << 16);
82415a613bSKumar Gala 
83415a613bSKumar Gala 	/*
84415a613bSKumar Gala 	 * Hack TSEC 3 and 4 IO voltages.
85415a613bSKumar Gala 	 */
86415a613bSKumar Gala 	gur->tsec34ioovcr = 0xe7e0;	/*  1110 0111 1110 0xxx */
87415a613bSKumar Gala 
88415a613bSKumar Gala 	ecm->eedr = 0xffffffff;		/* clear ecm errors */
89415a613bSKumar Gala 	ecm->eeer = 0xffffffff;		/* enable ecm errors */
90415a613bSKumar Gala 	return 0;
91415a613bSKumar Gala }
92415a613bSKumar Gala 
939973e3c6SBecky Bruce phys_size_t
94415a613bSKumar Gala initdram(int board_type)
95415a613bSKumar Gala {
96415a613bSKumar Gala 	long dram_size = 0;
97415a613bSKumar Gala 
98415a613bSKumar Gala 	puts("Initializing\n");
99415a613bSKumar Gala 
100415a613bSKumar Gala #if defined(CONFIG_DDR_DLL)
101415a613bSKumar Gala 	{
102415a613bSKumar Gala 		/*
103415a613bSKumar Gala 		 * Work around to stabilize DDR DLL MSYNC_IN.
104415a613bSKumar Gala 		 * Errata DDR9 seems to have been fixed.
105415a613bSKumar Gala 		 * This is now the workaround for Errata DDR11:
106415a613bSKumar Gala 		 *    Override DLL = 1, Course Adj = 1, Tap Select = 0
107415a613bSKumar Gala 		 */
108415a613bSKumar Gala 
1096d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 		volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
110415a613bSKumar Gala 
111415a613bSKumar Gala 		gur->ddrdllcr = 0x81000000;
112415a613bSKumar Gala 		asm("sync;isync;msync");
113415a613bSKumar Gala 		udelay(200);
114415a613bSKumar Gala 	}
115415a613bSKumar Gala #endif
116e31d2c1eSJon Loeliger 
117e31d2c1eSJon Loeliger 	dram_size = fsl_ddr_sdram();
118e31d2c1eSJon Loeliger 	dram_size = setup_ddr_tlbs(dram_size / 0x100000);
119e31d2c1eSJon Loeliger 	dram_size *= 0x100000;
120415a613bSKumar Gala 
121415a613bSKumar Gala #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
122415a613bSKumar Gala 	/*
123415a613bSKumar Gala 	 * Initialize and enable DDR ECC.
124415a613bSKumar Gala 	 */
125415a613bSKumar Gala 	ddr_enable_ecc(dram_size);
126415a613bSKumar Gala #endif
127e31d2c1eSJon Loeliger 
128415a613bSKumar Gala 	/*
129415a613bSKumar Gala 	 * SDRAM Initialization
130415a613bSKumar Gala 	 */
131415a613bSKumar Gala 	sdram_init();
132415a613bSKumar Gala 
133415a613bSKumar Gala 	puts("    DDR: ");
134415a613bSKumar Gala 	return dram_size;
135415a613bSKumar Gala }
136415a613bSKumar Gala 
137415a613bSKumar Gala /*
138415a613bSKumar Gala  * Initialize Local Bus
139415a613bSKumar Gala  */
140415a613bSKumar Gala void
141415a613bSKumar Gala local_bus_init(void)
142415a613bSKumar Gala {
1436d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
1446d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
145415a613bSKumar Gala 
146415a613bSKumar Gala 	uint clkdiv;
147415a613bSKumar Gala 	uint lbc_hz;
148415a613bSKumar Gala 	sys_info_t sysinfo;
149415a613bSKumar Gala 
150415a613bSKumar Gala 	get_sys_info(&sysinfo);
151415a613bSKumar Gala 	clkdiv = (lbc->lcrr & 0x0f) * 2;
152415a613bSKumar Gala 	lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
153415a613bSKumar Gala 
154415a613bSKumar Gala 	gur->lbiuiplldcr1 = 0x00078080;
155415a613bSKumar Gala 	if (clkdiv == 16) {
156415a613bSKumar Gala 		gur->lbiuiplldcr0 = 0x7c0f1bf0;
157415a613bSKumar Gala 	} else if (clkdiv == 8) {
158415a613bSKumar Gala 		gur->lbiuiplldcr0 = 0x6c0f1bf0;
159415a613bSKumar Gala 	} else if (clkdiv == 4) {
160415a613bSKumar Gala 		gur->lbiuiplldcr0 = 0x5c0f1bf0;
161415a613bSKumar Gala 	}
162415a613bSKumar Gala 
163415a613bSKumar Gala 	lbc->lcrr |= 0x00030000;
164415a613bSKumar Gala 
165415a613bSKumar Gala 	asm("sync;isync;msync");
166415a613bSKumar Gala 
167415a613bSKumar Gala 	lbc->ltesr = 0xffffffff;	/* Clear LBC error interrupts */
168415a613bSKumar Gala 	lbc->lteir = 0xffffffff;	/* Enable LBC error interrupts */
169415a613bSKumar Gala }
170415a613bSKumar Gala 
171415a613bSKumar Gala /*
172415a613bSKumar Gala  * Initialize SDRAM memory on the Local Bus.
173415a613bSKumar Gala  */
174415a613bSKumar Gala void
175415a613bSKumar Gala sdram_init(void)
176415a613bSKumar Gala {
1776d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #if defined(CONFIG_SYS_OR2_PRELIM) && defined(CONFIG_SYS_BR2_PRELIM)
178415a613bSKumar Gala 
179415a613bSKumar Gala 	uint idx;
1806d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
1816d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE;
182415a613bSKumar Gala 	uint cpu_board_rev;
183415a613bSKumar Gala 	uint lsdmr_common;
184415a613bSKumar Gala 
185415a613bSKumar Gala 	puts("    SDRAM: ");
186415a613bSKumar Gala 
1876d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	print_size (CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
188415a613bSKumar Gala 
189415a613bSKumar Gala 	/*
190415a613bSKumar Gala 	 * Setup SDRAM Base and Option Registers
191415a613bSKumar Gala 	 */
1926d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	lbc->or2 = CONFIG_SYS_OR2_PRELIM;
193415a613bSKumar Gala 	asm("msync");
194415a613bSKumar Gala 
1956d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	lbc->br2 = CONFIG_SYS_BR2_PRELIM;
196415a613bSKumar Gala 	asm("msync");
197415a613bSKumar Gala 
1986d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	lbc->lbcr = CONFIG_SYS_LBC_LBCR;
199415a613bSKumar Gala 	asm("msync");
200415a613bSKumar Gala 
201415a613bSKumar Gala 
2026d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	lbc->lsrt = CONFIG_SYS_LBC_LSRT;
2036d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	lbc->mrtpr = CONFIG_SYS_LBC_MRTPR;
204415a613bSKumar Gala 	asm("msync");
205415a613bSKumar Gala 
206415a613bSKumar Gala 	/*
207415a613bSKumar Gala 	 * MPC8548 uses "new" 15-16 style addressing.
208415a613bSKumar Gala 	 */
209415a613bSKumar Gala 	cpu_board_rev = get_cpu_board_revision();
2106d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	lsdmr_common = CONFIG_SYS_LBC_LSDMR_COMMON;
2116d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	lsdmr_common |= CONFIG_SYS_LBC_LSDMR_BSMA1516;
212415a613bSKumar Gala 
213415a613bSKumar Gala 	/*
214415a613bSKumar Gala 	 * Issue PRECHARGE ALL command.
215415a613bSKumar Gala 	 */
2166d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	lbc->lsdmr = lsdmr_common | CONFIG_SYS_LBC_LSDMR_OP_PCHALL;
217415a613bSKumar Gala 	asm("sync;msync");
218415a613bSKumar Gala 	*sdram_addr = 0xff;
219415a613bSKumar Gala 	ppcDcbf((unsigned long) sdram_addr);
220415a613bSKumar Gala 	udelay(100);
221415a613bSKumar Gala 
222415a613bSKumar Gala 	/*
223415a613bSKumar Gala 	 * Issue 8 AUTO REFRESH commands.
224415a613bSKumar Gala 	 */
225415a613bSKumar Gala 	for (idx = 0; idx < 8; idx++) {
2266d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 		lbc->lsdmr = lsdmr_common | CONFIG_SYS_LBC_LSDMR_OP_ARFRSH;
227415a613bSKumar Gala 		asm("sync;msync");
228415a613bSKumar Gala 		*sdram_addr = 0xff;
229415a613bSKumar Gala 		ppcDcbf((unsigned long) sdram_addr);
230415a613bSKumar Gala 		udelay(100);
231415a613bSKumar Gala 	}
232415a613bSKumar Gala 
233415a613bSKumar Gala 	/*
234415a613bSKumar Gala 	 * Issue 8 MODE-set command.
235415a613bSKumar Gala 	 */
2366d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	lbc->lsdmr = lsdmr_common | CONFIG_SYS_LBC_LSDMR_OP_MRW;
237415a613bSKumar Gala 	asm("sync;msync");
238415a613bSKumar Gala 	*sdram_addr = 0xff;
239415a613bSKumar Gala 	ppcDcbf((unsigned long) sdram_addr);
240415a613bSKumar Gala 	udelay(100);
241415a613bSKumar Gala 
242415a613bSKumar Gala 	/*
243415a613bSKumar Gala 	 * Issue NORMAL OP command.
244415a613bSKumar Gala 	 */
2456d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	lbc->lsdmr = lsdmr_common | CONFIG_SYS_LBC_LSDMR_OP_NORMAL;
246415a613bSKumar Gala 	asm("sync;msync");
247415a613bSKumar Gala 	*sdram_addr = 0xff;
248415a613bSKumar Gala 	ppcDcbf((unsigned long) sdram_addr);
249415a613bSKumar Gala 	udelay(200);    /* Overkill. Must wait > 200 bus cycles */
250415a613bSKumar Gala 
251415a613bSKumar Gala #endif	/* enable SDRAM init */
252415a613bSKumar Gala }
253415a613bSKumar Gala 
254415a613bSKumar Gala #if defined(CONFIG_PCI) || defined(CONFIG_PCI1)
255415a613bSKumar Gala /* For some reason the Tundra PCI bridge shows up on itself as a
256415a613bSKumar Gala  * different device.  Work around that by refusing to configure it.
257415a613bSKumar Gala  */
258415a613bSKumar Gala void dummy_func(struct pci_controller* hose, pci_dev_t dev, struct pci_config_table *tab) { }
259415a613bSKumar Gala 
260415a613bSKumar Gala static struct pci_config_table pci_mpc85xxcds_config_table[] = {
261415a613bSKumar Gala 	{0x10e3, 0x0513, PCI_ANY_ID, 1, 3, PCI_ANY_ID, dummy_func, {0,0,0}},
262415a613bSKumar Gala 	{0x1106, 0x0686, PCI_ANY_ID, 1, VIA_ID, 0, mpc85xx_config_via, {0,0,0}},
263415a613bSKumar Gala 	{0x1106, 0x0571, PCI_ANY_ID, 1, VIA_ID, 1,
264415a613bSKumar Gala 		mpc85xx_config_via_usbide, {0,0,0}},
265415a613bSKumar Gala 	{0x1105, 0x3038, PCI_ANY_ID, 1, VIA_ID, 2,
266415a613bSKumar Gala 		mpc85xx_config_via_usb, {0,0,0}},
267415a613bSKumar Gala 	{0x1106, 0x3038, PCI_ANY_ID, 1, VIA_ID, 3,
268415a613bSKumar Gala 		mpc85xx_config_via_usb2, {0,0,0}},
269415a613bSKumar Gala 	{0x1106, 0x3058, PCI_ANY_ID, 1, VIA_ID, 5,
270415a613bSKumar Gala 		mpc85xx_config_via_power, {0,0,0}},
271415a613bSKumar Gala 	{0x1106, 0x3068, PCI_ANY_ID, 1, VIA_ID, 6,
272415a613bSKumar Gala 		mpc85xx_config_via_ac97, {0,0,0}},
273415a613bSKumar Gala 	{},
274415a613bSKumar Gala };
275415a613bSKumar Gala 
276415a613bSKumar Gala static struct pci_controller pci1_hose = {
277415a613bSKumar Gala 	config_table: pci_mpc85xxcds_config_table};
278415a613bSKumar Gala #endif	/* CONFIG_PCI */
279415a613bSKumar Gala 
280415a613bSKumar Gala #ifdef CONFIG_PCI2
281415a613bSKumar Gala static struct pci_controller pci2_hose;
282415a613bSKumar Gala #endif	/* CONFIG_PCI2 */
283415a613bSKumar Gala 
284415a613bSKumar Gala #ifdef CONFIG_PCIE1
285415a613bSKumar Gala static struct pci_controller pcie1_hose;
286415a613bSKumar Gala #endif	/* CONFIG_PCIE1 */
287415a613bSKumar Gala 
288*2dba0deaSKumar Gala extern int fsl_pci_setup_inbound_windows(struct pci_region *r);
289*2dba0deaSKumar Gala extern void fsl_pci_init(struct pci_controller *hose);
290*2dba0deaSKumar Gala 
291415a613bSKumar Gala int first_free_busno=0;
292415a613bSKumar Gala 
293415a613bSKumar Gala void
294415a613bSKumar Gala pci_init_board(void)
295415a613bSKumar Gala {
2966d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
297415a613bSKumar Gala 	uint io_sel = (gur->pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
298415a613bSKumar Gala 	uint host_agent = (gur->porbmsr & MPC85xx_PORBMSR_HA) >> 16;
299415a613bSKumar Gala 
300415a613bSKumar Gala 
301415a613bSKumar Gala #ifdef CONFIG_PCI1
302415a613bSKumar Gala {
3036d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCI1_ADDR;
304415a613bSKumar Gala 	struct pci_controller *hose = &pci1_hose;
305415a613bSKumar Gala 	struct pci_config_table *table;
306*2dba0deaSKumar Gala 	struct pci_region *r = hose->regions;
307415a613bSKumar Gala 
308415a613bSKumar Gala 	uint pci_32 = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_PCI32;	/* PORDEVSR[15] */
309415a613bSKumar Gala 	uint pci_arb = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_ARB;	/* PORDEVSR[14] */
310415a613bSKumar Gala 	uint pci_clk_sel = gur->porpllsr & MPC85xx_PORDEVSR_PCI1_SPD;	/* PORPLLSR[16] */
311415a613bSKumar Gala 
312415a613bSKumar Gala 	uint pci_agent = (host_agent == 3) || (host_agent == 4 ) || (host_agent == 6);
313415a613bSKumar Gala 
314415a613bSKumar Gala 	uint pci_speed = get_clock_freq ();	/* PCI PSPEED in [4:5] */
315415a613bSKumar Gala 
316415a613bSKumar Gala 	if (!(gur->devdisr & MPC85xx_DEVDISR_PCI1)) {
317415a613bSKumar Gala 		printf ("    PCI: %d bit, %s MHz, %s, %s, %s\n",
318415a613bSKumar Gala 			(pci_32) ? 32 : 64,
319415a613bSKumar Gala 			(pci_speed == 33333000) ? "33" :
320415a613bSKumar Gala 			(pci_speed == 66666000) ? "66" : "unknown",
321415a613bSKumar Gala 			pci_clk_sel ? "sync" : "async",
322415a613bSKumar Gala 			pci_agent ? "agent" : "host",
323415a613bSKumar Gala 			pci_arb ? "arbiter" : "external-arbiter"
324415a613bSKumar Gala 			);
325415a613bSKumar Gala 
326415a613bSKumar Gala 
327415a613bSKumar Gala 		/* inbound */
328*2dba0deaSKumar Gala 		r += fsl_pci_setup_inbound_windows(r);
329415a613bSKumar Gala 
330415a613bSKumar Gala 		/* outbound memory */
331*2dba0deaSKumar Gala 		pci_set_region(r++,
3326d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 			       CONFIG_SYS_PCI1_MEM_BASE,
3336d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 			       CONFIG_SYS_PCI1_MEM_PHYS,
3346d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 			       CONFIG_SYS_PCI1_MEM_SIZE,
335415a613bSKumar Gala 			       PCI_REGION_MEM);
336415a613bSKumar Gala 
337415a613bSKumar Gala 		/* outbound io */
338*2dba0deaSKumar Gala 		pci_set_region(r++,
3396d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 			       CONFIG_SYS_PCI1_IO_BASE,
3406d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 			       CONFIG_SYS_PCI1_IO_PHYS,
3416d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 			       CONFIG_SYS_PCI1_IO_SIZE,
342415a613bSKumar Gala 			       PCI_REGION_IO);
343*2dba0deaSKumar Gala 		hose->region_count = r - hose->regions;
344415a613bSKumar Gala 
345415a613bSKumar Gala 		/* relocate config table pointers */
346415a613bSKumar Gala 		hose->config_table = \
347415a613bSKumar Gala 			(struct pci_config_table *)((uint)hose->config_table + gd->reloc_off);
348415a613bSKumar Gala 		for (table = hose->config_table; table && table->vendor; table++)
349415a613bSKumar Gala 			table->config_device += gd->reloc_off;
350415a613bSKumar Gala 
351415a613bSKumar Gala 		hose->first_busno=first_free_busno;
352415a613bSKumar Gala 		pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
353415a613bSKumar Gala 
354415a613bSKumar Gala 		fsl_pci_init(hose);
355415a613bSKumar Gala 		first_free_busno=hose->last_busno+1;
356415a613bSKumar Gala 		printf ("PCI on bus %02x - %02x\n",hose->first_busno,hose->last_busno);
357415a613bSKumar Gala #ifdef CONFIG_PCIX_CHECK
358415a613bSKumar Gala 		if (!(gur->pordevsr & PORDEVSR_PCI)) {
359415a613bSKumar Gala 			/* PCI-X init */
360415a613bSKumar Gala 			if (CONFIG_SYS_CLK_FREQ < 66000000)
361415a613bSKumar Gala 				printf("PCI-X will only work at 66 MHz\n");
362415a613bSKumar Gala 
363415a613bSKumar Gala 			reg16 = PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ
364415a613bSKumar Gala 				| PCI_X_CMD_ERO | PCI_X_CMD_DPERR_E;
365415a613bSKumar Gala 			pci_hose_write_config_word(hose, bus, PCIX_COMMAND, reg16);
366415a613bSKumar Gala 		}
367415a613bSKumar Gala #endif
368415a613bSKumar Gala 	} else {
369415a613bSKumar Gala 		printf ("    PCI: disabled\n");
370415a613bSKumar Gala 	}
371415a613bSKumar Gala }
372415a613bSKumar Gala #else
373415a613bSKumar Gala 	gur->devdisr |= MPC85xx_DEVDISR_PCI1; /* disable */
374415a613bSKumar Gala #endif
375415a613bSKumar Gala 
376415a613bSKumar Gala #ifdef CONFIG_PCI2
377415a613bSKumar Gala {
378415a613bSKumar Gala 	uint pci2_clk_sel = gur->porpllsr & 0x4000;	/* PORPLLSR[17] */
379415a613bSKumar Gala 	uint pci_dual = get_pci_dual ();	/* PCI DUAL in CM_PCI[3] */
380415a613bSKumar Gala 	if (pci_dual) {
381415a613bSKumar Gala 		printf ("    PCI2: 32 bit, 66 MHz, %s\n",
382415a613bSKumar Gala 			pci2_clk_sel ? "sync" : "async");
383415a613bSKumar Gala 	} else {
384415a613bSKumar Gala 		printf ("    PCI2: disabled\n");
385415a613bSKumar Gala 	}
386415a613bSKumar Gala }
387415a613bSKumar Gala #else
388415a613bSKumar Gala 	gur->devdisr |= MPC85xx_DEVDISR_PCI2; /* disable */
389415a613bSKumar Gala #endif /* CONFIG_PCI2 */
390415a613bSKumar Gala 
391415a613bSKumar Gala #ifdef CONFIG_PCIE1
392415a613bSKumar Gala {
3936d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE1_ADDR;
394415a613bSKumar Gala 	struct pci_controller *hose = &pcie1_hose;
395415a613bSKumar Gala 	int pcie_ep =  (host_agent == 0) || (host_agent == 2 ) || (host_agent == 3);
396*2dba0deaSKumar Gala 	struct pci_region *r = hose->regions;
397415a613bSKumar Gala 
398415a613bSKumar Gala 	int pcie_configured  = io_sel >= 1;
399415a613bSKumar Gala 
400415a613bSKumar Gala 	if (pcie_configured && !(gur->devdisr & MPC85xx_DEVDISR_PCIE)){
401415a613bSKumar Gala 		printf ("\n    PCIE connected to slot as %s (base address %x)",
402415a613bSKumar Gala 			pcie_ep ? "End Point" : "Root Complex",
403415a613bSKumar Gala 			(uint)pci);
404415a613bSKumar Gala 
405415a613bSKumar Gala 		if (pci->pme_msg_det) {
406415a613bSKumar Gala 			pci->pme_msg_det = 0xffffffff;
407415a613bSKumar Gala 			debug (" with errors.  Clearing.  Now 0x%08x",pci->pme_msg_det);
408415a613bSKumar Gala 		}
409415a613bSKumar Gala 		printf ("\n");
410415a613bSKumar Gala 
411415a613bSKumar Gala 		/* inbound */
412*2dba0deaSKumar Gala 		r += fsl_pci_setup_inbound_windows(r);
413415a613bSKumar Gala 
414415a613bSKumar Gala 		/* outbound memory */
415*2dba0deaSKumar Gala 		pci_set_region(r++,
4166d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 			       CONFIG_SYS_PCIE1_MEM_BASE,
4176d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 			       CONFIG_SYS_PCIE1_MEM_PHYS,
4186d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 			       CONFIG_SYS_PCIE1_MEM_SIZE,
419415a613bSKumar Gala 			       PCI_REGION_MEM);
420415a613bSKumar Gala 
421415a613bSKumar Gala 		/* outbound io */
422*2dba0deaSKumar Gala 		pci_set_region(r++,
4236d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 			       CONFIG_SYS_PCIE1_IO_BASE,
4246d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 			       CONFIG_SYS_PCIE1_IO_PHYS,
4256d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 			       CONFIG_SYS_PCIE1_IO_SIZE,
426415a613bSKumar Gala 			       PCI_REGION_IO);
427415a613bSKumar Gala 
428*2dba0deaSKumar Gala 		hose->region_count = r - hose->regions;
429415a613bSKumar Gala 
430415a613bSKumar Gala 		hose->first_busno=first_free_busno;
431415a613bSKumar Gala 		pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
432415a613bSKumar Gala 
433415a613bSKumar Gala 		fsl_pci_init(hose);
434415a613bSKumar Gala 		printf ("PCIE on bus %d - %d\n",hose->first_busno,hose->last_busno);
435415a613bSKumar Gala 
436415a613bSKumar Gala 		first_free_busno=hose->last_busno+1;
437415a613bSKumar Gala 
438415a613bSKumar Gala 	} else {
439415a613bSKumar Gala 		printf ("    PCIE: disabled\n");
440415a613bSKumar Gala 	}
441415a613bSKumar Gala  }
442415a613bSKumar Gala #else
443415a613bSKumar Gala 	gur->devdisr |= MPC85xx_DEVDISR_PCIE; /* disable */
444415a613bSKumar Gala #endif
445415a613bSKumar Gala 
446415a613bSKumar Gala }
447415a613bSKumar Gala 
448415a613bSKumar Gala int last_stage_init(void)
449415a613bSKumar Gala {
450415a613bSKumar Gala 	unsigned short temp;
451415a613bSKumar Gala 
452415a613bSKumar Gala 	/* Change the resistors for the PHY */
453415a613bSKumar Gala 	/* This is needed to get the RGMII working for the 1.3+
454415a613bSKumar Gala 	 * CDS cards */
455415a613bSKumar Gala 	if (get_board_version() ==  0x13) {
456415a613bSKumar Gala 		miiphy_write(CONFIG_TSEC1_NAME,
457415a613bSKumar Gala 				TSEC1_PHY_ADDR, 29, 18);
458415a613bSKumar Gala 
459415a613bSKumar Gala 		miiphy_read(CONFIG_TSEC1_NAME,
460415a613bSKumar Gala 				TSEC1_PHY_ADDR, 30, &temp);
461415a613bSKumar Gala 
462415a613bSKumar Gala 		temp = (temp & 0xf03f);
463415a613bSKumar Gala 		temp |= 2 << 9;		/* 36 ohm */
464415a613bSKumar Gala 		temp |= 2 << 6;		/* 39 ohm */
465415a613bSKumar Gala 
466415a613bSKumar Gala 		miiphy_write(CONFIG_TSEC1_NAME,
467415a613bSKumar Gala 				TSEC1_PHY_ADDR, 30, temp);
468415a613bSKumar Gala 
469415a613bSKumar Gala 		miiphy_write(CONFIG_TSEC1_NAME,
470415a613bSKumar Gala 				TSEC1_PHY_ADDR, 29, 3);
471415a613bSKumar Gala 
472415a613bSKumar Gala 		miiphy_write(CONFIG_TSEC1_NAME,
473415a613bSKumar Gala 				TSEC1_PHY_ADDR, 30, 0x8000);
474415a613bSKumar Gala 	}
475415a613bSKumar Gala 
476415a613bSKumar Gala 	return 0;
477415a613bSKumar Gala }
478415a613bSKumar Gala 
479415a613bSKumar Gala 
480415a613bSKumar Gala #if defined(CONFIG_OF_BOARD_SETUP)
481*2dba0deaSKumar Gala extern void ft_fsl_pci_setup(void *blob, const char *pci_alias,
482*2dba0deaSKumar Gala                         struct pci_controller *hose);
483415a613bSKumar Gala 
484*2dba0deaSKumar Gala void ft_pci_setup(void *blob, bd_t *bd)
485*2dba0deaSKumar Gala {
486415a613bSKumar Gala #ifdef CONFIG_PCI1
487*2dba0deaSKumar Gala 	ft_fsl_pci_setup(blob, "pci0", &pci1_hose);
488415a613bSKumar Gala #endif
489415a613bSKumar Gala #ifdef CONFIG_PCIE1
490*2dba0deaSKumar Gala 	ft_fsl_pci_setup(blob, "pci1", &pcie1_hose);
491415a613bSKumar Gala #endif
492415a613bSKumar Gala }
493415a613bSKumar Gala #endif
494