xref: /rk3399_rockchip-uboot/board/freescale/mpc8544ds/mpc8544ds.c (revision feede8b07013b33fca8dd2a916b3ac86bf4d4c0a)
125d83d7fSJon Loeliger /*
225d83d7fSJon Loeliger  * Copyright 2007 Freescale Semiconductor, Inc.
325d83d7fSJon Loeliger  *
425d83d7fSJon Loeliger  * See file CREDITS for list of people who contributed to this
525d83d7fSJon Loeliger  * project.
625d83d7fSJon Loeliger  *
725d83d7fSJon Loeliger  * This program is free software; you can redistribute it and/or
825d83d7fSJon Loeliger  * modify it under the terms of the GNU General Public License as
925d83d7fSJon Loeliger  * published by the Free Software Foundation; either version 2 of
1025d83d7fSJon Loeliger  * the License, or (at your option) any later version.
1125d83d7fSJon Loeliger  *
1225d83d7fSJon Loeliger  * This program is distributed in the hope that it will be useful,
1325d83d7fSJon Loeliger  * but WITHOUT ANY WARRANTY; without even the implied warranty of
1425d83d7fSJon Loeliger  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1525d83d7fSJon Loeliger  * GNU General Public License for more details.
1625d83d7fSJon Loeliger  *
1725d83d7fSJon Loeliger  * You should have received a copy of the GNU General Public License
1825d83d7fSJon Loeliger  * along with this program; if not, write to the Free Software
1925d83d7fSJon Loeliger  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
2025d83d7fSJon Loeliger  * MA 02111-1307 USA
2125d83d7fSJon Loeliger  */
2225d83d7fSJon Loeliger 
2325d83d7fSJon Loeliger #include <common.h>
2425d83d7fSJon Loeliger #include <command.h>
25837f1ba0SEd Swarthout #include <pci.h>
2625d83d7fSJon Loeliger #include <asm/processor.h>
271167a2fdSKumar Gala #include <asm/mmu.h>
2825d83d7fSJon Loeliger #include <asm/immap_85xx.h>
29837f1ba0SEd Swarthout #include <asm/immap_fsl_pci.h>
301167a2fdSKumar Gala #include <asm/fsl_ddr_sdram.h>
3156a92705SKumar Gala #include <asm/io.h>
3225d83d7fSJon Loeliger #include <miiphy.h>
33addce57eSKumar Gala #include <libfdt.h>
34addce57eSKumar Gala #include <fdt_support.h>
35216f2a71SAndy Fleming #include <tsec.h>
360b252f50SBen Warren #include <netdev.h>
3725d83d7fSJon Loeliger 
3825d83d7fSJon Loeliger #include "../common/pixis.h"
39216f2a71SAndy Fleming #include "../common/sgmii_riser.h"
4025d83d7fSJon Loeliger 
4125d83d7fSJon Loeliger int checkboard (void)
4225d83d7fSJon Loeliger {
436d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
446d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
456d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	volatile ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR);
4625d83d7fSJon Loeliger 
4725d83d7fSJon Loeliger 	if ((uint)&gur->porpllsr != 0xe00e0000) {
489b55a253SWolfgang Denk 		printf("immap size error %lx\n",(ulong)&gur->porpllsr);
4925d83d7fSJon Loeliger 	}
50e5852787SKumar Gala 	printf ("Board: MPC8544DS, System ID: 0x%02x, "
51e5852787SKumar Gala 		"System Version: 0x%02x, FPGA Version: 0x%02x\n",
52e5852787SKumar Gala 		in8(PIXIS_BASE + PIXIS_ID), in8(PIXIS_BASE + PIXIS_VER),
53e5852787SKumar Gala 		in8(PIXIS_BASE + PIXIS_PVER));
5425d83d7fSJon Loeliger 
55837f1ba0SEd Swarthout 	lbc->ltesr = 0xffffffff;	/* Clear LBC error interrupts */
56837f1ba0SEd Swarthout 	lbc->lteir = 0xffffffff;	/* Enable LBC error interrupts */
57837f1ba0SEd Swarthout 	ecm->eedr = 0xffffffff;		/* Clear ecm errors */
58837f1ba0SEd Swarthout 	ecm->eeer = 0xffffffff;		/* Enable ecm errors */
59837f1ba0SEd Swarthout 
6025d83d7fSJon Loeliger 	return 0;
6125d83d7fSJon Loeliger }
6225d83d7fSJon Loeliger 
639973e3c6SBecky Bruce phys_size_t
6425d83d7fSJon Loeliger initdram(int board_type)
6525d83d7fSJon Loeliger {
6625d83d7fSJon Loeliger 	long dram_size = 0;
6725d83d7fSJon Loeliger 
6825d83d7fSJon Loeliger 	puts("Initializing\n");
6925d83d7fSJon Loeliger 
701167a2fdSKumar Gala 	dram_size = fsl_ddr_sdram();
711167a2fdSKumar Gala 
721167a2fdSKumar Gala 	dram_size = setup_ddr_tlbs(dram_size / 0x100000);
731167a2fdSKumar Gala 
741167a2fdSKumar Gala 	dram_size *= 0x100000;
7525d83d7fSJon Loeliger 
7625d83d7fSJon Loeliger 	puts("    DDR: ");
7725d83d7fSJon Loeliger 	return dram_size;
7825d83d7fSJon Loeliger }
7925d83d7fSJon Loeliger 
80837f1ba0SEd Swarthout #ifdef CONFIG_PCI1
81837f1ba0SEd Swarthout static struct pci_controller pci1_hose;
82837f1ba0SEd Swarthout #endif
83837f1ba0SEd Swarthout 
84837f1ba0SEd Swarthout #ifdef CONFIG_PCIE1
85837f1ba0SEd Swarthout static struct pci_controller pcie1_hose;
86837f1ba0SEd Swarthout #endif
87837f1ba0SEd Swarthout 
88837f1ba0SEd Swarthout #ifdef CONFIG_PCIE2
89837f1ba0SEd Swarthout static struct pci_controller pcie2_hose;
90837f1ba0SEd Swarthout #endif
91837f1ba0SEd Swarthout 
92837f1ba0SEd Swarthout #ifdef CONFIG_PCIE3
93837f1ba0SEd Swarthout static struct pci_controller pcie3_hose;
94837f1ba0SEd Swarthout #endif
95837f1ba0SEd Swarthout 
962dba0deaSKumar Gala extern int fsl_pci_setup_inbound_windows(struct pci_region *r);
972dba0deaSKumar Gala extern void fsl_pci_init(struct pci_controller *hose);
982dba0deaSKumar Gala 
99837f1ba0SEd Swarthout int first_free_busno=0;
100837f1ba0SEd Swarthout 
101837f1ba0SEd Swarthout void
102837f1ba0SEd Swarthout pci_init_board(void)
103837f1ba0SEd Swarthout {
1046d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
105837f1ba0SEd Swarthout 	uint devdisr = gur->devdisr;
106837f1ba0SEd Swarthout 	uint io_sel = (gur->pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
107837f1ba0SEd Swarthout 	uint host_agent = (gur->porbmsr & MPC85xx_PORBMSR_HA) >> 16;
108837f1ba0SEd Swarthout 
109837f1ba0SEd Swarthout 	debug ("   pci_init_board: devdisr=%x, io_sel=%x, host_agent=%x\n",
110837f1ba0SEd Swarthout 		devdisr, io_sel, host_agent);
111837f1ba0SEd Swarthout 
112837f1ba0SEd Swarthout 	if (io_sel & 1) {
113837f1ba0SEd Swarthout 		if (!(gur->pordevsr & MPC85xx_PORDEVSR_SGMII1_DIS))
114837f1ba0SEd Swarthout 			printf ("    eTSEC1 is in sgmii mode.\n");
115837f1ba0SEd Swarthout 		if (!(gur->pordevsr & MPC85xx_PORDEVSR_SGMII3_DIS))
116837f1ba0SEd Swarthout 			printf ("    eTSEC3 is in sgmii mode.\n");
117837f1ba0SEd Swarthout 	}
118837f1ba0SEd Swarthout 
119837f1ba0SEd Swarthout #ifdef CONFIG_PCIE3
120837f1ba0SEd Swarthout {
1216d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE3_ADDR;
122837f1ba0SEd Swarthout 	struct pci_controller *hose = &pcie3_hose;
123f97abbfbSEd Swarthout 	int pcie_ep = (host_agent == 1);
1249afc2ef0SRoy Zang 	int pcie_configured  = io_sel >= 6;
1252dba0deaSKumar Gala 	struct pci_region *r = hose->regions;
126837f1ba0SEd Swarthout 
127837f1ba0SEd Swarthout 	if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE)){
128837f1ba0SEd Swarthout 		printf ("\n    PCIE3 connected to ULI as %s (base address %x)",
129837f1ba0SEd Swarthout 			pcie_ep ? "End Point" : "Root Complex",
130837f1ba0SEd Swarthout 			(uint)pci);
131837f1ba0SEd Swarthout 		if (pci->pme_msg_det) {
132837f1ba0SEd Swarthout 			pci->pme_msg_det = 0xffffffff;
133837f1ba0SEd Swarthout 			debug (" with errors.  Clearing.  Now 0x%08x",pci->pme_msg_det);
134837f1ba0SEd Swarthout 		}
135837f1ba0SEd Swarthout 		printf ("\n");
136837f1ba0SEd Swarthout 
137837f1ba0SEd Swarthout 		/* inbound */
1382dba0deaSKumar Gala 		r += fsl_pci_setup_inbound_windows(r);
139837f1ba0SEd Swarthout 
140837f1ba0SEd Swarthout 		/* outbound memory */
1412dba0deaSKumar Gala 		pci_set_region(r++,
14210795f42SKumar Gala 			       CONFIG_SYS_PCIE3_MEM_BUS,
1436d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 			       CONFIG_SYS_PCIE3_MEM_PHYS,
1446d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 			       CONFIG_SYS_PCIE3_MEM_SIZE,
145837f1ba0SEd Swarthout 			       PCI_REGION_MEM);
146837f1ba0SEd Swarthout 
147837f1ba0SEd Swarthout 		/* outbound io */
1482dba0deaSKumar Gala 		pci_set_region(r++,
1495f91ef6aSKumar Gala 			       CONFIG_SYS_PCIE3_IO_BUS,
1506d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 			       CONFIG_SYS_PCIE3_IO_PHYS,
1516d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 			       CONFIG_SYS_PCIE3_IO_SIZE,
152837f1ba0SEd Swarthout 			       PCI_REGION_IO);
153837f1ba0SEd Swarthout 
15410795f42SKumar Gala #ifdef CONFIG_SYS_PCIE3_MEM_BUS2
155837f1ba0SEd Swarthout 		/* outbound memory */
1562dba0deaSKumar Gala 		pci_set_region(r++,
15710795f42SKumar Gala 			       CONFIG_SYS_PCIE3_MEM_BUS2,
1586d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 			       CONFIG_SYS_PCIE3_MEM_PHYS2,
1596d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 			       CONFIG_SYS_PCIE3_MEM_SIZE2,
160837f1ba0SEd Swarthout 			       PCI_REGION_MEM);
161837f1ba0SEd Swarthout #endif
1622dba0deaSKumar Gala 		hose->region_count = r - hose->regions;
163837f1ba0SEd Swarthout 		hose->first_busno=first_free_busno;
164837f1ba0SEd Swarthout 		pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
165837f1ba0SEd Swarthout 
166837f1ba0SEd Swarthout 		fsl_pci_init(hose);
167837f1ba0SEd Swarthout 
168837f1ba0SEd Swarthout 		first_free_busno=hose->last_busno+1;
169837f1ba0SEd Swarthout 		printf ("    PCIE3 on bus %02x - %02x\n",
170837f1ba0SEd Swarthout 			hose->first_busno,hose->last_busno);
171837f1ba0SEd Swarthout 
17256a92705SKumar Gala 		/*
17356a92705SKumar Gala 		 * Activate ULI1575 legacy chip by performing a fake
17456a92705SKumar Gala 		 * memory access.  Needed to make ULI RTC work.
17556a92705SKumar Gala 		 */
17610795f42SKumar Gala 		in_be32((u32 *)CONFIG_SYS_PCIE3_MEM_BUS);
177837f1ba0SEd Swarthout 	} else {
178837f1ba0SEd Swarthout 		printf ("    PCIE3: disabled\n");
179837f1ba0SEd Swarthout 	}
180837f1ba0SEd Swarthout 
181837f1ba0SEd Swarthout  }
182837f1ba0SEd Swarthout #else
183837f1ba0SEd Swarthout 	gur->devdisr |= MPC85xx_DEVDISR_PCIE3; /* disable */
184837f1ba0SEd Swarthout #endif
185837f1ba0SEd Swarthout 
186837f1ba0SEd Swarthout #ifdef CONFIG_PCIE1
187837f1ba0SEd Swarthout  {
1886d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE1_ADDR;
189837f1ba0SEd Swarthout 	struct pci_controller *hose = &pcie1_hose;
190837f1ba0SEd Swarthout 	int pcie_ep = (host_agent == 5);
1916d3a10f7SRoy Zang 	int pcie_configured  = io_sel >= 2;
1922dba0deaSKumar Gala 	struct pci_region *r = hose->regions;
193837f1ba0SEd Swarthout 
194837f1ba0SEd Swarthout 	if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE)){
195837f1ba0SEd Swarthout 		printf ("\n    PCIE1 connected to Slot2 as %s (base address %x)",
196837f1ba0SEd Swarthout 			pcie_ep ? "End Point" : "Root Complex",
197837f1ba0SEd Swarthout 			(uint)pci);
198837f1ba0SEd Swarthout 		if (pci->pme_msg_det) {
199837f1ba0SEd Swarthout 			pci->pme_msg_det = 0xffffffff;
200837f1ba0SEd Swarthout 			debug (" with errors.  Clearing.  Now 0x%08x",pci->pme_msg_det);
201837f1ba0SEd Swarthout 		}
202837f1ba0SEd Swarthout 		printf ("\n");
203837f1ba0SEd Swarthout 
204837f1ba0SEd Swarthout 		/* inbound */
2052dba0deaSKumar Gala 		r += fsl_pci_setup_inbound_windows(r);
206837f1ba0SEd Swarthout 
207837f1ba0SEd Swarthout 		/* outbound memory */
2082dba0deaSKumar Gala 		pci_set_region(r++,
20910795f42SKumar Gala 			       CONFIG_SYS_PCIE1_MEM_BUS,
2106d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 			       CONFIG_SYS_PCIE1_MEM_PHYS,
2116d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 			       CONFIG_SYS_PCIE1_MEM_SIZE,
212837f1ba0SEd Swarthout 			       PCI_REGION_MEM);
213837f1ba0SEd Swarthout 
214837f1ba0SEd Swarthout 		/* outbound io */
2152dba0deaSKumar Gala 		pci_set_region(r++,
2165f91ef6aSKumar Gala 			       CONFIG_SYS_PCIE1_IO_BUS,
2176d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 			       CONFIG_SYS_PCIE1_IO_PHYS,
2186d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 			       CONFIG_SYS_PCIE1_IO_SIZE,
219837f1ba0SEd Swarthout 			       PCI_REGION_IO);
220837f1ba0SEd Swarthout 
22110795f42SKumar Gala #ifdef CONFIG_SYS_PCIE1_MEM_BUS2
222837f1ba0SEd Swarthout 		/* outbound memory */
2232dba0deaSKumar Gala 		pci_set_region(r++,
22410795f42SKumar Gala 			       CONFIG_SYS_PCIE1_MEM_BUS2,
2256d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 			       CONFIG_SYS_PCIE1_MEM_PHYS2,
2266d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 			       CONFIG_SYS_PCIE1_MEM_SIZE2,
227837f1ba0SEd Swarthout 			       PCI_REGION_MEM);
228837f1ba0SEd Swarthout #endif
2292dba0deaSKumar Gala 		hose->region_count = r - hose->regions;
230837f1ba0SEd Swarthout 		hose->first_busno=first_free_busno;
231837f1ba0SEd Swarthout 
232837f1ba0SEd Swarthout 		pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
233837f1ba0SEd Swarthout 
234837f1ba0SEd Swarthout 		fsl_pci_init(hose);
235837f1ba0SEd Swarthout 
236837f1ba0SEd Swarthout 		first_free_busno=hose->last_busno+1;
237837f1ba0SEd Swarthout 		printf("    PCIE1 on bus %02x - %02x\n",
238837f1ba0SEd Swarthout 		       hose->first_busno,hose->last_busno);
239837f1ba0SEd Swarthout 
240837f1ba0SEd Swarthout 	} else {
241837f1ba0SEd Swarthout 		printf ("    PCIE1: disabled\n");
242837f1ba0SEd Swarthout 	}
243837f1ba0SEd Swarthout 
244837f1ba0SEd Swarthout  }
245837f1ba0SEd Swarthout #else
246837f1ba0SEd Swarthout 	gur->devdisr |= MPC85xx_DEVDISR_PCIE; /* disable */
247837f1ba0SEd Swarthout #endif
248837f1ba0SEd Swarthout 
249837f1ba0SEd Swarthout #ifdef CONFIG_PCIE2
250837f1ba0SEd Swarthout  {
2516d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE2_ADDR;
252837f1ba0SEd Swarthout 	struct pci_controller *hose = &pcie2_hose;
253837f1ba0SEd Swarthout 	int pcie_ep = (host_agent == 3);
2546d3a10f7SRoy Zang 	int pcie_configured  = io_sel >= 4;
2552dba0deaSKumar Gala 	struct pci_region *r = hose->regions;
256837f1ba0SEd Swarthout 
257837f1ba0SEd Swarthout 	if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE)){
258837f1ba0SEd Swarthout 		printf ("\n    PCIE2 connected to Slot 1 as %s (base address %x)",
259837f1ba0SEd Swarthout 			pcie_ep ? "End Point" : "Root Complex",
260837f1ba0SEd Swarthout 			(uint)pci);
261837f1ba0SEd Swarthout 		if (pci->pme_msg_det) {
262837f1ba0SEd Swarthout 			pci->pme_msg_det = 0xffffffff;
263837f1ba0SEd Swarthout 			debug (" with errors.  Clearing.  Now 0x%08x",pci->pme_msg_det);
264837f1ba0SEd Swarthout 		}
265837f1ba0SEd Swarthout 		printf ("\n");
266837f1ba0SEd Swarthout 
267837f1ba0SEd Swarthout 		/* inbound */
2682dba0deaSKumar Gala 		r += fsl_pci_setup_inbound_windows(r);
269837f1ba0SEd Swarthout 
270837f1ba0SEd Swarthout 		/* outbound memory */
2712dba0deaSKumar Gala 		pci_set_region(r++,
27210795f42SKumar Gala 			       CONFIG_SYS_PCIE2_MEM_BUS,
2736d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 			       CONFIG_SYS_PCIE2_MEM_PHYS,
2746d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 			       CONFIG_SYS_PCIE2_MEM_SIZE,
275837f1ba0SEd Swarthout 			       PCI_REGION_MEM);
276837f1ba0SEd Swarthout 
277837f1ba0SEd Swarthout 		/* outbound io */
2782dba0deaSKumar Gala 		pci_set_region(r++,
2795f91ef6aSKumar Gala 			       CONFIG_SYS_PCIE2_IO_BUS,
2806d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 			       CONFIG_SYS_PCIE2_IO_PHYS,
2816d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 			       CONFIG_SYS_PCIE2_IO_SIZE,
282837f1ba0SEd Swarthout 			       PCI_REGION_IO);
283837f1ba0SEd Swarthout 
28410795f42SKumar Gala #ifdef CONFIG_SYS_PCIE2_MEM_BUS2
285837f1ba0SEd Swarthout 		/* outbound memory */
2862dba0deaSKumar Gala 		pci_set_region(r++,
28710795f42SKumar Gala 			       CONFIG_SYS_PCIE2_MEM_BUS2,
2886d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 			       CONFIG_SYS_PCIE2_MEM_PHYS2,
2896d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 			       CONFIG_SYS_PCIE2_MEM_SIZE2,
290837f1ba0SEd Swarthout 			       PCI_REGION_MEM);
291837f1ba0SEd Swarthout #endif
2922dba0deaSKumar Gala 		hose->region_count = r - hose->regions;
293837f1ba0SEd Swarthout 		hose->first_busno=first_free_busno;
294837f1ba0SEd Swarthout 		pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
295837f1ba0SEd Swarthout 
296837f1ba0SEd Swarthout 		fsl_pci_init(hose);
297837f1ba0SEd Swarthout 		first_free_busno=hose->last_busno+1;
298837f1ba0SEd Swarthout 		printf ("    PCIE2 on bus %02x - %02x\n",
299837f1ba0SEd Swarthout 			hose->first_busno,hose->last_busno);
300837f1ba0SEd Swarthout 
301837f1ba0SEd Swarthout 	} else {
302837f1ba0SEd Swarthout 		printf ("    PCIE2: disabled\n");
303837f1ba0SEd Swarthout 	}
304837f1ba0SEd Swarthout 
305837f1ba0SEd Swarthout  }
306837f1ba0SEd Swarthout #else
307837f1ba0SEd Swarthout 	gur->devdisr |= MPC85xx_DEVDISR_PCIE2; /* disable */
308837f1ba0SEd Swarthout #endif
309837f1ba0SEd Swarthout 
310837f1ba0SEd Swarthout 
311837f1ba0SEd Swarthout #ifdef CONFIG_PCI1
312837f1ba0SEd Swarthout {
3136d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCI1_ADDR;
314837f1ba0SEd Swarthout 	struct pci_controller *hose = &pci1_hose;
3152dba0deaSKumar Gala 	struct pci_region *r = hose->regions;
316837f1ba0SEd Swarthout 
317837f1ba0SEd Swarthout 	uint pci_agent = (host_agent == 6);
318837f1ba0SEd Swarthout 	uint pci_speed = 66666000; /*get_clock_freq (); PCI PSPEED in [4:5] */
319837f1ba0SEd Swarthout 	uint pci_32 = 1;
320837f1ba0SEd Swarthout 	uint pci_arb = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_ARB;	/* PORDEVSR[14] */
321837f1ba0SEd Swarthout 	uint pci_clk_sel = gur->porpllsr & MPC85xx_PORDEVSR_PCI1_SPD;	/* PORPLLSR[16] */
322837f1ba0SEd Swarthout 
323837f1ba0SEd Swarthout 
324837f1ba0SEd Swarthout 	if (!(devdisr & MPC85xx_DEVDISR_PCI1)) {
325837f1ba0SEd Swarthout 		printf ("\n    PCI: %d bit, %s MHz, %s, %s, %s (base address %x)\n",
326837f1ba0SEd Swarthout 			(pci_32) ? 32 : 64,
327837f1ba0SEd Swarthout 			(pci_speed == 33333000) ? "33" :
328837f1ba0SEd Swarthout 			(pci_speed == 66666000) ? "66" : "unknown",
329837f1ba0SEd Swarthout 			pci_clk_sel ? "sync" : "async",
330837f1ba0SEd Swarthout 			pci_agent ? "agent" : "host",
331837f1ba0SEd Swarthout 			pci_arb ? "arbiter" : "external-arbiter",
332837f1ba0SEd Swarthout 			(uint)pci
333837f1ba0SEd Swarthout 			);
334837f1ba0SEd Swarthout 
335837f1ba0SEd Swarthout 		/* inbound */
3362dba0deaSKumar Gala 		r += fsl_pci_setup_inbound_windows(r);
337837f1ba0SEd Swarthout 
338837f1ba0SEd Swarthout 		/* outbound memory */
3392dba0deaSKumar Gala 		pci_set_region(r++,
34010795f42SKumar Gala 			       CONFIG_SYS_PCI1_MEM_BUS,
3416d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 			       CONFIG_SYS_PCI1_MEM_PHYS,
3426d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 			       CONFIG_SYS_PCI1_MEM_SIZE,
343837f1ba0SEd Swarthout 			       PCI_REGION_MEM);
344837f1ba0SEd Swarthout 
345837f1ba0SEd Swarthout 		/* outbound io */
3462dba0deaSKumar Gala 		pci_set_region(r++,
3475f91ef6aSKumar Gala 			       CONFIG_SYS_PCI1_IO_BUS,
3486d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 			       CONFIG_SYS_PCI1_IO_PHYS,
3496d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 			       CONFIG_SYS_PCI1_IO_SIZE,
350837f1ba0SEd Swarthout 			       PCI_REGION_IO);
3512dba0deaSKumar Gala 
35210795f42SKumar Gala #ifdef CONFIG_SYS_PCIE3_MEM_BUS2
353837f1ba0SEd Swarthout 		/* outbound memory */
3542dba0deaSKumar Gala 		pci_set_region(r++,
35510795f42SKumar Gala 			       CONFIG_SYS_PCIE3_MEM_BUS2,
3566d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 			       CONFIG_SYS_PCIE3_MEM_PHYS2,
3576d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 			       CONFIG_SYS_PCIE3_MEM_SIZE2,
358837f1ba0SEd Swarthout 			       PCI_REGION_MEM);
359837f1ba0SEd Swarthout #endif
3602dba0deaSKumar Gala 		hose->region_count = r - hose->regions;
361837f1ba0SEd Swarthout 		hose->first_busno=first_free_busno;
362837f1ba0SEd Swarthout 		pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
363837f1ba0SEd Swarthout 
364837f1ba0SEd Swarthout 		fsl_pci_init(hose);
365837f1ba0SEd Swarthout 		first_free_busno=hose->last_busno+1;
366837f1ba0SEd Swarthout 		printf ("PCI on bus %02x - %02x\n",
367837f1ba0SEd Swarthout 			hose->first_busno,hose->last_busno);
368837f1ba0SEd Swarthout 	} else {
369837f1ba0SEd Swarthout 		printf ("    PCI: disabled\n");
370837f1ba0SEd Swarthout 	}
371837f1ba0SEd Swarthout }
372837f1ba0SEd Swarthout #else
373837f1ba0SEd Swarthout 	gur->devdisr |= MPC85xx_DEVDISR_PCI1; /* disable */
374837f1ba0SEd Swarthout #endif
375837f1ba0SEd Swarthout }
376837f1ba0SEd Swarthout 
377837f1ba0SEd Swarthout 
37825d83d7fSJon Loeliger int last_stage_init(void)
37925d83d7fSJon Loeliger {
38025d83d7fSJon Loeliger 	return 0;
38125d83d7fSJon Loeliger }
38225d83d7fSJon Loeliger 
38325d83d7fSJon Loeliger 
38425d83d7fSJon Loeliger unsigned long
38525d83d7fSJon Loeliger get_board_sys_clk(ulong dummy)
38625d83d7fSJon Loeliger {
38725d83d7fSJon Loeliger 	u8 i, go_bit, rd_clks;
38825d83d7fSJon Loeliger 	ulong val = 0;
38925d83d7fSJon Loeliger 
39025d83d7fSJon Loeliger 	go_bit = in8(PIXIS_BASE + PIXIS_VCTL);
39125d83d7fSJon Loeliger 	go_bit &= 0x01;
39225d83d7fSJon Loeliger 
39325d83d7fSJon Loeliger 	rd_clks = in8(PIXIS_BASE + PIXIS_VCFGEN0);
39425d83d7fSJon Loeliger 	rd_clks &= 0x1C;
39525d83d7fSJon Loeliger 
39625d83d7fSJon Loeliger 	/*
39725d83d7fSJon Loeliger 	 * Only if both go bit and the SCLK bit in VCFGEN0 are set
39825d83d7fSJon Loeliger 	 * should we be using the AUX register. Remember, we also set the
39925d83d7fSJon Loeliger 	 * GO bit to boot from the alternate bank on the on-board flash
40025d83d7fSJon Loeliger 	 */
40125d83d7fSJon Loeliger 
40225d83d7fSJon Loeliger 	if (go_bit) {
40325d83d7fSJon Loeliger 		if (rd_clks == 0x1c)
40425d83d7fSJon Loeliger 			i = in8(PIXIS_BASE + PIXIS_AUX);
40525d83d7fSJon Loeliger 		else
40625d83d7fSJon Loeliger 			i = in8(PIXIS_BASE + PIXIS_SPD);
40725d83d7fSJon Loeliger 	} else {
40825d83d7fSJon Loeliger 		i = in8(PIXIS_BASE + PIXIS_SPD);
40925d83d7fSJon Loeliger 	}
41025d83d7fSJon Loeliger 
41125d83d7fSJon Loeliger 	i &= 0x07;
41225d83d7fSJon Loeliger 
41325d83d7fSJon Loeliger 	switch (i) {
41425d83d7fSJon Loeliger 	case 0:
41525d83d7fSJon Loeliger 		val = 33333333;
41625d83d7fSJon Loeliger 		break;
41725d83d7fSJon Loeliger 	case 1:
41825d83d7fSJon Loeliger 		val = 40000000;
41925d83d7fSJon Loeliger 		break;
42025d83d7fSJon Loeliger 	case 2:
42125d83d7fSJon Loeliger 		val = 50000000;
42225d83d7fSJon Loeliger 		break;
42325d83d7fSJon Loeliger 	case 3:
42425d83d7fSJon Loeliger 		val = 66666666;
42525d83d7fSJon Loeliger 		break;
42625d83d7fSJon Loeliger 	case 4:
42725d83d7fSJon Loeliger 		val = 83000000;
42825d83d7fSJon Loeliger 		break;
42925d83d7fSJon Loeliger 	case 5:
43025d83d7fSJon Loeliger 		val = 100000000;
43125d83d7fSJon Loeliger 		break;
43225d83d7fSJon Loeliger 	case 6:
43325d83d7fSJon Loeliger 		val = 133333333;
43425d83d7fSJon Loeliger 		break;
43525d83d7fSJon Loeliger 	case 7:
43625d83d7fSJon Loeliger 		val = 166666666;
43725d83d7fSJon Loeliger 		break;
43825d83d7fSJon Loeliger 	}
43925d83d7fSJon Loeliger 
44025d83d7fSJon Loeliger 	return val;
44125d83d7fSJon Loeliger }
44225d83d7fSJon Loeliger 
443216f2a71SAndy Fleming int board_eth_init(bd_t *bis)
444216f2a71SAndy Fleming {
4450b252f50SBen Warren #ifdef CONFIG_TSEC_ENET
446216f2a71SAndy Fleming 	struct tsec_info_struct tsec_info[2];
4476d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
448216f2a71SAndy Fleming 	uint io_sel = (gur->pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
449216f2a71SAndy Fleming 	int num = 0;
450216f2a71SAndy Fleming 
451216f2a71SAndy Fleming #ifdef CONFIG_TSEC1
452216f2a71SAndy Fleming 	SET_STD_TSEC_INFO(tsec_info[num], 1);
453216f2a71SAndy Fleming 	if (!(gur->pordevsr & MPC85xx_PORDEVSR_SGMII1_DIS))
454216f2a71SAndy Fleming 		tsec_info[num].flags |= TSEC_SGMII;
455216f2a71SAndy Fleming 	num++;
456216f2a71SAndy Fleming #endif
457216f2a71SAndy Fleming #ifdef CONFIG_TSEC3
458216f2a71SAndy Fleming 	SET_STD_TSEC_INFO(tsec_info[num], 3);
459216f2a71SAndy Fleming 	if (!(gur->pordevsr & MPC85xx_PORDEVSR_SGMII3_DIS))
460216f2a71SAndy Fleming 		tsec_info[num].flags |= TSEC_SGMII;
461216f2a71SAndy Fleming 	num++;
462216f2a71SAndy Fleming #endif
463216f2a71SAndy Fleming 
464216f2a71SAndy Fleming 	if (!num) {
465216f2a71SAndy Fleming 		printf("No TSECs initialized\n");
466216f2a71SAndy Fleming 
467216f2a71SAndy Fleming 		return 0;
468216f2a71SAndy Fleming 	}
469216f2a71SAndy Fleming 
470216f2a71SAndy Fleming 	if (io_sel & 1)
471216f2a71SAndy Fleming 		fsl_sgmii_riser_init(tsec_info, num);
472216f2a71SAndy Fleming 
473216f2a71SAndy Fleming 
474216f2a71SAndy Fleming 	tsec_eth_init(bis, tsec_info, num);
475216f2a71SAndy Fleming #endif
4760b252f50SBen Warren 	return pci_eth_init(bis);
4770b252f50SBen Warren }
478216f2a71SAndy Fleming 
479addce57eSKumar Gala #if defined(CONFIG_OF_BOARD_SETUP)
4802dba0deaSKumar Gala extern void ft_fsl_pci_setup(void *blob, const char *pci_alias,
4812dba0deaSKumar Gala 			struct pci_controller *hose);
482addce57eSKumar Gala 
4832dba0deaSKumar Gala void ft_board_setup(void *blob, bd_t *bd)
48425d83d7fSJon Loeliger {
48525d83d7fSJon Loeliger 	ft_cpu_setup(blob, bd);
48625d83d7fSJon Loeliger 
4872dba0deaSKumar Gala 
488f75e89e9SEd Swarthout #ifdef CONFIG_PCI1
4892dba0deaSKumar Gala 	ft_fsl_pci_setup(blob, "pci0", &pci1_hose);
490837f1ba0SEd Swarthout #endif
491837f1ba0SEd Swarthout #ifdef CONFIG_PCIE2
4922dba0deaSKumar Gala 	ft_fsl_pci_setup(blob, "pci1", &pcie1_hose);
493addce57eSKumar Gala #endif
494addce57eSKumar Gala #ifdef CONFIG_PCIE1
4952dba0deaSKumar Gala 	ft_fsl_pci_setup(blob, "pci2", &pcie3_hose);
496837f1ba0SEd Swarthout #endif
497837f1ba0SEd Swarthout #ifdef CONFIG_PCIE3
4982dba0deaSKumar Gala 	ft_fsl_pci_setup(blob, "pci3", &pcie2_hose);
499837f1ba0SEd Swarthout #endif
500*feede8b0SAndy Fleming #ifdef CONFIG_FSL_SGMII_RISER
501*feede8b0SAndy Fleming 	fsl_sgmii_riser_fdt_fixup(blob);
502*feede8b0SAndy Fleming #endif
50325d83d7fSJon Loeliger }
50425d83d7fSJon Loeliger #endif
505