xref: /rk3399_rockchip-uboot/board/freescale/mpc8572ds/mpc8572ds.c (revision feede8b07013b33fca8dd2a916b3ac86bf4d4c0a)
1129ba616SKumar Gala /*
2129ba616SKumar Gala  * Copyright 2007-2008 Freescale Semiconductor, Inc.
3129ba616SKumar Gala  *
4129ba616SKumar Gala  * See file CREDITS for list of people who contributed to this
5129ba616SKumar Gala  * project.
6129ba616SKumar Gala  *
7129ba616SKumar Gala  * This program is free software; you can redistribute it and/or
8129ba616SKumar Gala  * modify it under the terms of the GNU General Public License as
9129ba616SKumar Gala  * published by the Free Software Foundation; either version 2 of
10129ba616SKumar Gala  * the License, or (at your option) any later version.
11129ba616SKumar Gala  *
12129ba616SKumar Gala  * This program is distributed in the hope that it will be useful,
13129ba616SKumar Gala  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14129ba616SKumar Gala  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
15129ba616SKumar Gala  * GNU General Public License for more details.
16129ba616SKumar Gala  *
17129ba616SKumar Gala  * You should have received a copy of the GNU General Public License
18129ba616SKumar Gala  * along with this program; if not, write to the Free Software
19129ba616SKumar Gala  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20129ba616SKumar Gala  * MA 02111-1307 USA
21129ba616SKumar Gala  */
22129ba616SKumar Gala 
23129ba616SKumar Gala #include <common.h>
24129ba616SKumar Gala #include <command.h>
25129ba616SKumar Gala #include <pci.h>
26129ba616SKumar Gala #include <asm/processor.h>
27129ba616SKumar Gala #include <asm/mmu.h>
287c0d4a75SKumar Gala #include <asm/cache.h>
29129ba616SKumar Gala #include <asm/immap_85xx.h>
30129ba616SKumar Gala #include <asm/immap_fsl_pci.h>
31129ba616SKumar Gala #include <asm/fsl_ddr_sdram.h>
32129ba616SKumar Gala #include <asm/io.h>
33129ba616SKumar Gala #include <miiphy.h>
34129ba616SKumar Gala #include <libfdt.h>
35129ba616SKumar Gala #include <fdt_support.h>
367e183cadSLiu Yu #include <tsec.h>
37129ba616SKumar Gala 
38129ba616SKumar Gala #include "../common/pixis.h"
397e183cadSLiu Yu #include "../common/sgmii_riser.h"
40129ba616SKumar Gala 
41129ba616SKumar Gala long int fixed_sdram(void);
42129ba616SKumar Gala 
43129ba616SKumar Gala int checkboard (void)
44129ba616SKumar Gala {
45129ba616SKumar Gala 	printf ("Board: MPC8572DS, System ID: 0x%02x, "
46129ba616SKumar Gala 		"System Version: 0x%02x, FPGA Version: 0x%02x\n",
47129ba616SKumar Gala 		in8(PIXIS_BASE + PIXIS_ID), in8(PIXIS_BASE + PIXIS_VER),
48129ba616SKumar Gala 		in8(PIXIS_BASE + PIXIS_PVER));
49129ba616SKumar Gala 	return 0;
50129ba616SKumar Gala }
51129ba616SKumar Gala 
52129ba616SKumar Gala phys_size_t initdram(int board_type)
53129ba616SKumar Gala {
54129ba616SKumar Gala 	phys_size_t dram_size = 0;
55129ba616SKumar Gala 
56129ba616SKumar Gala 	puts("Initializing....");
57129ba616SKumar Gala 
58129ba616SKumar Gala #ifdef CONFIG_SPD_EEPROM
59129ba616SKumar Gala 	dram_size = fsl_ddr_sdram();
60129ba616SKumar Gala #else
61129ba616SKumar Gala 	dram_size = fixed_sdram();
62129ba616SKumar Gala #endif
63e57f0fa1SDave Liu 	dram_size = setup_ddr_tlbs(dram_size / 0x100000);
64e57f0fa1SDave Liu 	dram_size *= 0x100000;
65129ba616SKumar Gala 
66129ba616SKumar Gala 	puts("    DDR: ");
67129ba616SKumar Gala 	return dram_size;
68129ba616SKumar Gala }
69129ba616SKumar Gala 
70129ba616SKumar Gala #if !defined(CONFIG_SPD_EEPROM)
71129ba616SKumar Gala /*
72129ba616SKumar Gala  * Fixed sdram init -- doesn't use serial presence detect.
73129ba616SKumar Gala  */
74129ba616SKumar Gala 
75129ba616SKumar Gala phys_size_t fixed_sdram (void)
76129ba616SKumar Gala {
776d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
78129ba616SKumar Gala 	volatile ccsr_ddr_t *ddr= &immap->im_ddr;
79129ba616SKumar Gala 	uint d_init;
80129ba616SKumar Gala 
816d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	ddr->cs0_bnds = CONFIG_SYS_DDR_CS0_BNDS;
826d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	ddr->cs0_config = CONFIG_SYS_DDR_CS0_CONFIG;
83129ba616SKumar Gala 
846d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	ddr->timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
856d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	ddr->timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
866d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	ddr->timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
876d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	ddr->timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
886d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	ddr->sdram_mode = CONFIG_SYS_DDR_MODE_1;
896d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	ddr->sdram_mode_2 = CONFIG_SYS_DDR_MODE_2;
906d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	ddr->sdram_interval = CONFIG_SYS_DDR_INTERVAL;
916d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	ddr->sdram_data_init = CONFIG_SYS_DDR_DATA_INIT;
926d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	ddr->sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CTRL;
936d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	ddr->sdram_cfg_2 = CONFIG_SYS_DDR_CONTROL2;
94129ba616SKumar Gala 
95129ba616SKumar Gala #if defined (CONFIG_DDR_ECC)
966d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	ddr->err_int_en = CONFIG_SYS_DDR_ERR_INT_EN;
976d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	ddr->err_disable = CONFIG_SYS_DDR_ERR_DIS;
986d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	ddr->err_sbe = CONFIG_SYS_DDR_SBE;
99129ba616SKumar Gala #endif
100129ba616SKumar Gala 	asm("sync;isync");
101129ba616SKumar Gala 
102129ba616SKumar Gala 	udelay(500);
103129ba616SKumar Gala 
1046d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	ddr->sdram_cfg = CONFIG_SYS_DDR_CONTROL;
105129ba616SKumar Gala 
106129ba616SKumar Gala #if defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
107129ba616SKumar Gala 	d_init = 1;
108129ba616SKumar Gala 	debug("DDR - 1st controller: memory initializing\n");
109129ba616SKumar Gala 	/*
110129ba616SKumar Gala 	 * Poll until memory is initialized.
111129ba616SKumar Gala 	 * 512 Meg at 400 might hit this 200 times or so.
112129ba616SKumar Gala 	 */
113129ba616SKumar Gala 	while ((ddr->sdram_cfg_2 & (d_init << 4)) != 0) {
114129ba616SKumar Gala 		udelay(1000);
115129ba616SKumar Gala 	}
116129ba616SKumar Gala 	debug("DDR: memory initialized\n\n");
117129ba616SKumar Gala 	asm("sync; isync");
118129ba616SKumar Gala 	udelay(500);
119129ba616SKumar Gala #endif
120129ba616SKumar Gala 
121129ba616SKumar Gala 	return 512 * 1024 * 1024;
122129ba616SKumar Gala }
123129ba616SKumar Gala 
124129ba616SKumar Gala #endif
125129ba616SKumar Gala 
126129ba616SKumar Gala #ifdef CONFIG_PCIE1
127129ba616SKumar Gala static struct pci_controller pcie1_hose;
128129ba616SKumar Gala #endif
129129ba616SKumar Gala 
130129ba616SKumar Gala #ifdef CONFIG_PCIE2
131129ba616SKumar Gala static struct pci_controller pcie2_hose;
132129ba616SKumar Gala #endif
133129ba616SKumar Gala 
134129ba616SKumar Gala #ifdef CONFIG_PCIE3
135129ba616SKumar Gala static struct pci_controller pcie3_hose;
136129ba616SKumar Gala #endif
137129ba616SKumar Gala 
1382dba0deaSKumar Gala extern int fsl_pci_setup_inbound_windows(struct pci_region *r);
1392dba0deaSKumar Gala extern void fsl_pci_init(struct pci_controller *hose);
1402dba0deaSKumar Gala 
141129ba616SKumar Gala int first_free_busno=0;
142129ba616SKumar Gala #ifdef CONFIG_PCI
143129ba616SKumar Gala void pci_init_board(void)
144129ba616SKumar Gala {
1456d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
146129ba616SKumar Gala 	uint devdisr = gur->devdisr;
147129ba616SKumar Gala 	uint io_sel = (gur->pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
148129ba616SKumar Gala 	uint host_agent = (gur->porbmsr & MPC85xx_PORBMSR_HA) >> 16;
149129ba616SKumar Gala 
150129ba616SKumar Gala 	debug ("   pci_init_board: devdisr=%x, io_sel=%x, host_agent=%x\n",
151129ba616SKumar Gala 			devdisr, io_sel, host_agent);
152129ba616SKumar Gala 
153129ba616SKumar Gala 	if (!(gur->pordevsr & MPC85xx_PORDEVSR_SGMII1_DIS))
154129ba616SKumar Gala 		printf ("    eTSEC1 is in sgmii mode.\n");
155129ba616SKumar Gala 	if (!(gur->pordevsr & MPC85xx_PORDEVSR_SGMII2_DIS))
156129ba616SKumar Gala 		printf ("    eTSEC2 is in sgmii mode.\n");
157129ba616SKumar Gala 	if (!(gur->pordevsr & MPC85xx_PORDEVSR_SGMII3_DIS))
158129ba616SKumar Gala 		printf ("    eTSEC3 is in sgmii mode.\n");
159129ba616SKumar Gala 	if (!(gur->pordevsr & MPC85xx_PORDEVSR_SGMII4_DIS))
160129ba616SKumar Gala 		printf ("    eTSEC4 is in sgmii mode.\n");
161129ba616SKumar Gala 
162129ba616SKumar Gala 
163129ba616SKumar Gala #ifdef CONFIG_PCIE3
164129ba616SKumar Gala 	{
1656d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 		volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE3_ADDR;
166129ba616SKumar Gala 		struct pci_controller *hose = &pcie3_hose;
167129ba616SKumar Gala 		int pcie_ep = (host_agent == 0) || (host_agent == 3) ||
168129ba616SKumar Gala 			(host_agent == 5) || (host_agent == 6);
1699afc2ef0SRoy Zang 		int pcie_configured  = (io_sel == 0x7);
1702dba0deaSKumar Gala 		struct pci_region *r = hose->regions;
171129ba616SKumar Gala 		u32 temp32;
172129ba616SKumar Gala 
173028e1168SRoy Zang 		if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE3)){
174129ba616SKumar Gala 			printf ("\n    PCIE3 connected to ULI as %s (base address %x)",
175129ba616SKumar Gala 					pcie_ep ? "End Point" : "Root Complex",
176129ba616SKumar Gala 					(uint)pci);
177129ba616SKumar Gala 			if (pci->pme_msg_det) {
178129ba616SKumar Gala 				pci->pme_msg_det = 0xffffffff;
179129ba616SKumar Gala 				debug (" with errors.  Clearing.  Now 0x%08x",pci->pme_msg_det);
180129ba616SKumar Gala 			}
181129ba616SKumar Gala 			printf ("\n");
182129ba616SKumar Gala 
183129ba616SKumar Gala 			/* inbound */
1842dba0deaSKumar Gala 			r += fsl_pci_setup_inbound_windows(r);
185129ba616SKumar Gala 
186129ba616SKumar Gala 			/* outbound memory */
1872dba0deaSKumar Gala 			pci_set_region(r++,
18810795f42SKumar Gala 					CONFIG_SYS_PCIE3_MEM_BUS,
1896d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 					CONFIG_SYS_PCIE3_MEM_PHYS,
1906d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 					CONFIG_SYS_PCIE3_MEM_SIZE,
191129ba616SKumar Gala 					PCI_REGION_MEM);
192129ba616SKumar Gala 
193129ba616SKumar Gala 			/* outbound io */
1942dba0deaSKumar Gala 			pci_set_region(r++,
1955f91ef6aSKumar Gala 					CONFIG_SYS_PCIE3_IO_BUS,
1966d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 					CONFIG_SYS_PCIE3_IO_PHYS,
1976d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 					CONFIG_SYS_PCIE3_IO_SIZE,
198129ba616SKumar Gala 					PCI_REGION_IO);
199129ba616SKumar Gala 
2002dba0deaSKumar Gala 			hose->region_count = r - hose->regions;
201129ba616SKumar Gala 			hose->first_busno=first_free_busno;
202129ba616SKumar Gala 			pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
203129ba616SKumar Gala 
204129ba616SKumar Gala 			fsl_pci_init(hose);
205129ba616SKumar Gala 
206129ba616SKumar Gala 			first_free_busno=hose->last_busno+1;
207129ba616SKumar Gala 			printf ("    PCIE3 on bus %02x - %02x\n",
208129ba616SKumar Gala 					hose->first_busno,hose->last_busno);
209129ba616SKumar Gala 
210129ba616SKumar Gala 			/*
211129ba616SKumar Gala 			 * Activate ULI1575 legacy chip by performing a fake
212129ba616SKumar Gala 			 * memory access.  Needed to make ULI RTC work.
213129ba616SKumar Gala 			 * Device 1d has the first on-board memory BAR.
214129ba616SKumar Gala 			 */
215129ba616SKumar Gala 
216129ba616SKumar Gala 			pci_hose_read_config_dword(hose, PCI_BDF(2, 0x1d, 0 ),
217129ba616SKumar Gala 					PCI_BASE_ADDRESS_1, &temp32);
2185af0fdd8SKumar Gala 			if (temp32 >= CONFIG_SYS_PCIE3_MEM_BUS) {
219ad97dce1SKumar Gala 				void *p = pci_mem_to_virt(PCI_BDF(2, 0x1d, 0),
220ad97dce1SKumar Gala 								temp32, 4, 0);
221ad97dce1SKumar Gala 				debug(" uli1572 read to %p\n", p);
222ad97dce1SKumar Gala 				in_be32(p);
223129ba616SKumar Gala 			}
224129ba616SKumar Gala 		} else {
225129ba616SKumar Gala 			printf ("    PCIE3: disabled\n");
226129ba616SKumar Gala 		}
227129ba616SKumar Gala 
228129ba616SKumar Gala 	}
229129ba616SKumar Gala #else
230129ba616SKumar Gala 	gur->devdisr |= MPC85xx_DEVDISR_PCIE3; /* disable */
231129ba616SKumar Gala #endif
232129ba616SKumar Gala 
233129ba616SKumar Gala #ifdef CONFIG_PCIE2
234129ba616SKumar Gala 	{
2356d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 		volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE2_ADDR;
236129ba616SKumar Gala 		struct pci_controller *hose = &pcie2_hose;
237129ba616SKumar Gala 		int pcie_ep = (host_agent == 2) || (host_agent == 4) ||
23886be510fSEd Swarthout 			(host_agent == 6) || (host_agent == 0);
2399afc2ef0SRoy Zang 		int pcie_configured  = (io_sel == 0x3) || (io_sel == 0x7);
2402dba0deaSKumar Gala 		struct pci_region *r = hose->regions;
241129ba616SKumar Gala 
242028e1168SRoy Zang 		if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE2)){
243129ba616SKumar Gala 			printf ("\n    PCIE2 connected to Slot 1 as %s (base address %x)",
244129ba616SKumar Gala 					pcie_ep ? "End Point" : "Root Complex",
245129ba616SKumar Gala 					(uint)pci);
246129ba616SKumar Gala 			if (pci->pme_msg_det) {
247129ba616SKumar Gala 				pci->pme_msg_det = 0xffffffff;
248129ba616SKumar Gala 				debug (" with errors.  Clearing.  Now 0x%08x",pci->pme_msg_det);
249129ba616SKumar Gala 			}
250129ba616SKumar Gala 			printf ("\n");
251129ba616SKumar Gala 
252129ba616SKumar Gala 			/* inbound */
2532dba0deaSKumar Gala 			r += fsl_pci_setup_inbound_windows(r);
254129ba616SKumar Gala 
255129ba616SKumar Gala 			/* outbound memory */
2562dba0deaSKumar Gala 			pci_set_region(r++,
25710795f42SKumar Gala 					CONFIG_SYS_PCIE2_MEM_BUS,
2586d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 					CONFIG_SYS_PCIE2_MEM_PHYS,
2596d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 					CONFIG_SYS_PCIE2_MEM_SIZE,
260129ba616SKumar Gala 					PCI_REGION_MEM);
261129ba616SKumar Gala 
262129ba616SKumar Gala 			/* outbound io */
2632dba0deaSKumar Gala 			pci_set_region(r++,
2645f91ef6aSKumar Gala 					CONFIG_SYS_PCIE2_IO_BUS,
2656d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 					CONFIG_SYS_PCIE2_IO_PHYS,
2666d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 					CONFIG_SYS_PCIE2_IO_SIZE,
267129ba616SKumar Gala 					PCI_REGION_IO);
268129ba616SKumar Gala 
2692dba0deaSKumar Gala 			hose->region_count = r - hose->regions;
270129ba616SKumar Gala 			hose->first_busno=first_free_busno;
271129ba616SKumar Gala 			pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
272129ba616SKumar Gala 
273129ba616SKumar Gala 			fsl_pci_init(hose);
274129ba616SKumar Gala 			first_free_busno=hose->last_busno+1;
275129ba616SKumar Gala 			printf ("    PCIE2 on bus %02x - %02x\n",
276129ba616SKumar Gala 					hose->first_busno,hose->last_busno);
277129ba616SKumar Gala 
278129ba616SKumar Gala 		} else {
279129ba616SKumar Gala 			printf ("    PCIE2: disabled\n");
280129ba616SKumar Gala 		}
281129ba616SKumar Gala 
282129ba616SKumar Gala 	}
283129ba616SKumar Gala #else
284129ba616SKumar Gala 	gur->devdisr |= MPC85xx_DEVDISR_PCIE2; /* disable */
285129ba616SKumar Gala #endif
286129ba616SKumar Gala #ifdef CONFIG_PCIE1
287129ba616SKumar Gala 	{
2886d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 		volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE1_ADDR;
289129ba616SKumar Gala 		struct pci_controller *hose = &pcie1_hose;
29086be510fSEd Swarthout 		int pcie_ep = (host_agent <= 1) || (host_agent == 4) ||
291129ba616SKumar Gala 			(host_agent == 5);
2929afc2ef0SRoy Zang 		int pcie_configured  = (io_sel == 0x2) || (io_sel == 0x3) ||
2939afc2ef0SRoy Zang 					(io_sel == 0x7) || (io_sel == 0xb) ||
2949afc2ef0SRoy Zang 					(io_sel == 0xc) || (io_sel == 0xf);
2952dba0deaSKumar Gala 		struct pci_region *r = hose->regions;
296129ba616SKumar Gala 
297129ba616SKumar Gala 		if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE)){
298129ba616SKumar Gala 			printf ("\n    PCIE1 connected to Slot 2 as %s (base address %x)",
299129ba616SKumar Gala 					pcie_ep ? "End Point" : "Root Complex",
300129ba616SKumar Gala 					(uint)pci);
301129ba616SKumar Gala 			if (pci->pme_msg_det) {
302129ba616SKumar Gala 				pci->pme_msg_det = 0xffffffff;
303129ba616SKumar Gala 				debug (" with errors.  Clearing.  Now 0x%08x",pci->pme_msg_det);
304129ba616SKumar Gala 			}
305129ba616SKumar Gala 			printf ("\n");
306129ba616SKumar Gala 
307129ba616SKumar Gala 			/* inbound */
3082dba0deaSKumar Gala 			r += fsl_pci_setup_inbound_windows(r);
309129ba616SKumar Gala 
310129ba616SKumar Gala 			/* outbound memory */
3112dba0deaSKumar Gala 			pci_set_region(r++,
31210795f42SKumar Gala 					CONFIG_SYS_PCIE1_MEM_BUS,
3136d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 					CONFIG_SYS_PCIE1_MEM_PHYS,
3146d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 					CONFIG_SYS_PCIE1_MEM_SIZE,
315129ba616SKumar Gala 					PCI_REGION_MEM);
316129ba616SKumar Gala 
317129ba616SKumar Gala 			/* outbound io */
3182dba0deaSKumar Gala 			pci_set_region(r++,
3195f91ef6aSKumar Gala 					CONFIG_SYS_PCIE1_IO_BUS,
3206d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 					CONFIG_SYS_PCIE1_IO_PHYS,
3216d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 					CONFIG_SYS_PCIE1_IO_SIZE,
322129ba616SKumar Gala 					PCI_REGION_IO);
323129ba616SKumar Gala 
3242dba0deaSKumar Gala 			hose->region_count = r - hose->regions;
325129ba616SKumar Gala 			hose->first_busno=first_free_busno;
326129ba616SKumar Gala 
327129ba616SKumar Gala 			pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
328129ba616SKumar Gala 
329129ba616SKumar Gala 			fsl_pci_init(hose);
330129ba616SKumar Gala 
331129ba616SKumar Gala 			first_free_busno=hose->last_busno+1;
332129ba616SKumar Gala 			printf("    PCIE1 on bus %02x - %02x\n",
333129ba616SKumar Gala 					hose->first_busno,hose->last_busno);
334129ba616SKumar Gala 
335129ba616SKumar Gala 		} else {
336129ba616SKumar Gala 			printf ("    PCIE1: disabled\n");
337129ba616SKumar Gala 		}
338129ba616SKumar Gala 
339129ba616SKumar Gala 	}
340129ba616SKumar Gala #else
341129ba616SKumar Gala 	gur->devdisr |= MPC85xx_DEVDISR_PCIE; /* disable */
342129ba616SKumar Gala #endif
343129ba616SKumar Gala }
344129ba616SKumar Gala #endif
345129ba616SKumar Gala 
346129ba616SKumar Gala int board_early_init_r(void)
347129ba616SKumar Gala {
3486d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
349129ba616SKumar Gala 	const u8 flash_esel = 2;
350129ba616SKumar Gala 
351129ba616SKumar Gala 	/*
352129ba616SKumar Gala 	 * Remap Boot flash + PROMJET region to caching-inhibited
353129ba616SKumar Gala 	 * so that flash can be erased properly.
354129ba616SKumar Gala 	 */
355129ba616SKumar Gala 
3567c0d4a75SKumar Gala 	/* Flush d-cache and invalidate i-cache of any FLASH data */
3577c0d4a75SKumar Gala 	flush_dcache();
3587c0d4a75SKumar Gala 	invalidate_icache();
359129ba616SKumar Gala 
360129ba616SKumar Gala 	/* invalidate existing TLB entry for flash + promjet */
361129ba616SKumar Gala 	disable_tlb(flash_esel);
362129ba616SKumar Gala 
363c953ddfdSKumar Gala 	set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,	/* tlb, epn, rpn */
364129ba616SKumar Gala 			MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,	/* perms, wimge */
365129ba616SKumar Gala 			0, flash_esel, BOOKE_PAGESZ_256M, 1);	/* ts, esel, tsize, iprot */
366129ba616SKumar Gala 
367129ba616SKumar Gala 	return 0;
368129ba616SKumar Gala }
369129ba616SKumar Gala 
370129ba616SKumar Gala #ifdef CONFIG_GET_CLK_FROM_ICS307
371129ba616SKumar Gala /* decode S[0-2] to Output Divider (OD) */
372129ba616SKumar Gala static unsigned char ics307_S_to_OD[] = {
373129ba616SKumar Gala 	10, 2, 8, 4, 5, 7, 3, 6
374129ba616SKumar Gala };
375129ba616SKumar Gala 
376129ba616SKumar Gala /* Calculate frequency being generated by ICS307-02 clock chip based upon
377129ba616SKumar Gala  * the control bytes being programmed into it. */
378129ba616SKumar Gala /* XXX: This function should probably go into a common library */
379129ba616SKumar Gala static unsigned long
380129ba616SKumar Gala ics307_clk_freq (unsigned char cw0, unsigned char cw1, unsigned char cw2)
381129ba616SKumar Gala {
382129ba616SKumar Gala 	const unsigned long InputFrequency = CONFIG_ICS307_REFCLK_HZ;
383129ba616SKumar Gala 	unsigned long VDW = ((cw1 << 1) & 0x1FE) + ((cw2 >> 7) & 1);
384129ba616SKumar Gala 	unsigned long RDW = cw2 & 0x7F;
385129ba616SKumar Gala 	unsigned long OD = ics307_S_to_OD[cw0 & 0x7];
386129ba616SKumar Gala 	unsigned long freq;
387129ba616SKumar Gala 
388129ba616SKumar Gala 	/* CLK1Frequency = InputFrequency * 2 * (VDW + 8) / ((RDW + 2) * OD) */
389129ba616SKumar Gala 
390129ba616SKumar Gala 	/* cw0:  C1 C0 TTL F1 F0 S2 S1 S0
391129ba616SKumar Gala 	 * cw1:  V8 V7 V6 V5 V4 V3 V2 V1
392129ba616SKumar Gala 	 * cw2:  V0 R6 R5 R4 R3 R2 R1 R0
393129ba616SKumar Gala 	 *
394129ba616SKumar Gala 	 * R6:R0 = Reference Divider Word (RDW)
395129ba616SKumar Gala 	 * V8:V0 = VCO Divider Word (VDW)
396129ba616SKumar Gala 	 * S2:S0 = Output Divider Select (OD)
397129ba616SKumar Gala 	 * F1:F0 = Function of CLK2 Output
398129ba616SKumar Gala 	 * TTL = duty cycle
399129ba616SKumar Gala 	 * C1:C0 = internal load capacitance for cyrstal
400129ba616SKumar Gala 	 */
401129ba616SKumar Gala 
402129ba616SKumar Gala 	/* Adding 1 to get a "nicely" rounded number, but this needs
403129ba616SKumar Gala 	 * more tweaking to get a "properly" rounded number. */
404129ba616SKumar Gala 
405129ba616SKumar Gala 	freq = 1 + (InputFrequency * 2 * (VDW + 8) / ((RDW + 2) * OD));
406129ba616SKumar Gala 
407129ba616SKumar Gala 	debug("ICS307: CW[0-2]: %02X %02X %02X => %u Hz\n", cw0, cw1, cw2,
408129ba616SKumar Gala 			freq);
409129ba616SKumar Gala 	return freq;
410129ba616SKumar Gala }
411129ba616SKumar Gala 
412129ba616SKumar Gala unsigned long get_board_sys_clk(ulong dummy)
413129ba616SKumar Gala {
414129ba616SKumar Gala 	return ics307_clk_freq (
415129ba616SKumar Gala 			in8(PIXIS_BASE + PIXIS_VSYSCLK0),
416129ba616SKumar Gala 			in8(PIXIS_BASE + PIXIS_VSYSCLK1),
417129ba616SKumar Gala 			in8(PIXIS_BASE + PIXIS_VSYSCLK2)
418129ba616SKumar Gala 			);
419129ba616SKumar Gala }
420129ba616SKumar Gala 
421129ba616SKumar Gala unsigned long get_board_ddr_clk(ulong dummy)
422129ba616SKumar Gala {
423129ba616SKumar Gala 	return ics307_clk_freq (
424129ba616SKumar Gala 			in8(PIXIS_BASE + PIXIS_VDDRCLK0),
425129ba616SKumar Gala 			in8(PIXIS_BASE + PIXIS_VDDRCLK1),
426129ba616SKumar Gala 			in8(PIXIS_BASE + PIXIS_VDDRCLK2)
427129ba616SKumar Gala 			);
428129ba616SKumar Gala }
429129ba616SKumar Gala #else
430129ba616SKumar Gala unsigned long get_board_sys_clk(ulong dummy)
431129ba616SKumar Gala {
432129ba616SKumar Gala 	u8 i;
433129ba616SKumar Gala 	ulong val = 0;
434129ba616SKumar Gala 
435129ba616SKumar Gala 	i = in8(PIXIS_BASE + PIXIS_SPD);
436129ba616SKumar Gala 	i &= 0x07;
437129ba616SKumar Gala 
438129ba616SKumar Gala 	switch (i) {
439129ba616SKumar Gala 		case 0:
440129ba616SKumar Gala 			val = 33333333;
441129ba616SKumar Gala 			break;
442129ba616SKumar Gala 		case 1:
443129ba616SKumar Gala 			val = 40000000;
444129ba616SKumar Gala 			break;
445129ba616SKumar Gala 		case 2:
446129ba616SKumar Gala 			val = 50000000;
447129ba616SKumar Gala 			break;
448129ba616SKumar Gala 		case 3:
449129ba616SKumar Gala 			val = 66666666;
450129ba616SKumar Gala 			break;
451129ba616SKumar Gala 		case 4:
452129ba616SKumar Gala 			val = 83333333;
453129ba616SKumar Gala 			break;
454129ba616SKumar Gala 		case 5:
455129ba616SKumar Gala 			val = 100000000;
456129ba616SKumar Gala 			break;
457129ba616SKumar Gala 		case 6:
458129ba616SKumar Gala 			val = 133333333;
459129ba616SKumar Gala 			break;
460129ba616SKumar Gala 		case 7:
461129ba616SKumar Gala 			val = 166666666;
462129ba616SKumar Gala 			break;
463129ba616SKumar Gala 	}
464129ba616SKumar Gala 
465129ba616SKumar Gala 	return val;
466129ba616SKumar Gala }
467129ba616SKumar Gala 
468129ba616SKumar Gala unsigned long get_board_ddr_clk(ulong dummy)
469129ba616SKumar Gala {
470129ba616SKumar Gala 	u8 i;
471129ba616SKumar Gala 	ulong val = 0;
472129ba616SKumar Gala 
473129ba616SKumar Gala 	i = in8(PIXIS_BASE + PIXIS_SPD);
474129ba616SKumar Gala 	i &= 0x38;
475129ba616SKumar Gala 	i >>= 3;
476129ba616SKumar Gala 
477129ba616SKumar Gala 	switch (i) {
478129ba616SKumar Gala 		case 0:
479129ba616SKumar Gala 			val = 33333333;
480129ba616SKumar Gala 			break;
481129ba616SKumar Gala 		case 1:
482129ba616SKumar Gala 			val = 40000000;
483129ba616SKumar Gala 			break;
484129ba616SKumar Gala 		case 2:
485129ba616SKumar Gala 			val = 50000000;
486129ba616SKumar Gala 			break;
487129ba616SKumar Gala 		case 3:
488129ba616SKumar Gala 			val = 66666666;
489129ba616SKumar Gala 			break;
490129ba616SKumar Gala 		case 4:
491129ba616SKumar Gala 			val = 83333333;
492129ba616SKumar Gala 			break;
493129ba616SKumar Gala 		case 5:
494129ba616SKumar Gala 			val = 100000000;
495129ba616SKumar Gala 			break;
496129ba616SKumar Gala 		case 6:
497129ba616SKumar Gala 			val = 133333333;
498129ba616SKumar Gala 			break;
499129ba616SKumar Gala 		case 7:
500129ba616SKumar Gala 			val = 166666666;
501129ba616SKumar Gala 			break;
502129ba616SKumar Gala 	}
503129ba616SKumar Gala 	return val;
504129ba616SKumar Gala }
505129ba616SKumar Gala #endif
506129ba616SKumar Gala 
5077e183cadSLiu Yu #ifdef CONFIG_TSEC_ENET
5087e183cadSLiu Yu int board_eth_init(bd_t *bis)
5097e183cadSLiu Yu {
5107e183cadSLiu Yu 	struct tsec_info_struct tsec_info[4];
5117e183cadSLiu Yu 	volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
5127e183cadSLiu Yu 	int num = 0;
5137e183cadSLiu Yu 
5147e183cadSLiu Yu #ifdef CONFIG_TSEC1
5157e183cadSLiu Yu 	SET_STD_TSEC_INFO(tsec_info[num], 1);
5167e183cadSLiu Yu 	if (!(gur->pordevsr & MPC85xx_PORDEVSR_SGMII1_DIS))
5177e183cadSLiu Yu 		tsec_info[num].flags |= TSEC_SGMII;
5187e183cadSLiu Yu 	num++;
5197e183cadSLiu Yu #endif
5207e183cadSLiu Yu #ifdef CONFIG_TSEC2
5217e183cadSLiu Yu 	SET_STD_TSEC_INFO(tsec_info[num], 2);
5227e183cadSLiu Yu 	if (!(gur->pordevsr & MPC85xx_PORDEVSR_SGMII2_DIS))
5237e183cadSLiu Yu 		tsec_info[num].flags |= TSEC_SGMII;
5247e183cadSLiu Yu 	num++;
5257e183cadSLiu Yu #endif
5267e183cadSLiu Yu #ifdef CONFIG_TSEC3
5277e183cadSLiu Yu 	SET_STD_TSEC_INFO(tsec_info[num], 3);
5287e183cadSLiu Yu 	if (!(gur->pordevsr & MPC85xx_PORDEVSR_SGMII3_DIS))
5297e183cadSLiu Yu 		tsec_info[num].flags |= TSEC_SGMII;
5307e183cadSLiu Yu 	num++;
5317e183cadSLiu Yu #endif
5327e183cadSLiu Yu #ifdef CONFIG_TSEC4
5337e183cadSLiu Yu 	SET_STD_TSEC_INFO(tsec_info[num], 4);
5347e183cadSLiu Yu 	if (!(gur->pordevsr & MPC85xx_PORDEVSR_SGMII4_DIS))
5357e183cadSLiu Yu 		tsec_info[num].flags |= TSEC_SGMII;
5367e183cadSLiu Yu 	num++;
5377e183cadSLiu Yu #endif
5387e183cadSLiu Yu 
5397e183cadSLiu Yu 	if (!num) {
5407e183cadSLiu Yu 		printf("No TSECs initialized\n");
5417e183cadSLiu Yu 
5427e183cadSLiu Yu 		return 0;
5437e183cadSLiu Yu 	}
5447e183cadSLiu Yu 
545*feede8b0SAndy Fleming #ifdef CONFIG_FSL_SGMII_RISER
5467e183cadSLiu Yu 	fsl_sgmii_riser_init(tsec_info, num);
547*feede8b0SAndy Fleming #endif
5487e183cadSLiu Yu 
5497e183cadSLiu Yu 	tsec_eth_init(bis, tsec_info, num);
5507e183cadSLiu Yu 
5517e183cadSLiu Yu 	return 0;
5527e183cadSLiu Yu }
5537e183cadSLiu Yu #endif
5547e183cadSLiu Yu 
555129ba616SKumar Gala #if defined(CONFIG_OF_BOARD_SETUP)
5562dba0deaSKumar Gala extern void ft_fsl_pci_setup(void *blob, const char *pci_alias,
5572dba0deaSKumar Gala 			struct pci_controller *hose);
5582dba0deaSKumar Gala 
559129ba616SKumar Gala void ft_board_setup(void *blob, bd_t *bd)
560129ba616SKumar Gala {
561b6730512SKumar Gala 	phys_addr_t base;
562b6730512SKumar Gala 	phys_size_t size;
563129ba616SKumar Gala 
564129ba616SKumar Gala 	ft_cpu_setup(blob, bd);
565129ba616SKumar Gala 
566129ba616SKumar Gala 	base = getenv_bootm_low();
567129ba616SKumar Gala 	size = getenv_bootm_size();
568129ba616SKumar Gala 
569129ba616SKumar Gala 	fdt_fixup_memory(blob, (u64)base, (u64)size);
570129ba616SKumar Gala 
571129ba616SKumar Gala #ifdef CONFIG_PCIE3
5722dba0deaSKumar Gala 	ft_fsl_pci_setup(blob, "pci0", &pcie3_hose);
573129ba616SKumar Gala #endif
574129ba616SKumar Gala #ifdef CONFIG_PCIE2
5752dba0deaSKumar Gala 	ft_fsl_pci_setup(blob, "pci1", &pcie2_hose);
576129ba616SKumar Gala #endif
577129ba616SKumar Gala #ifdef CONFIG_PCIE1
5782dba0deaSKumar Gala 	ft_fsl_pci_setup(blob, "pci2", &pcie1_hose);
579129ba616SKumar Gala #endif
580*feede8b0SAndy Fleming #ifdef CONFIG_FSL_SGMII_RISER
581*feede8b0SAndy Fleming 	fsl_sgmii_riser_fdt_fixup(blob);
582*feede8b0SAndy Fleming #endif
583129ba616SKumar Gala }
584129ba616SKumar Gala #endif
585129ba616SKumar Gala 
586129ba616SKumar Gala #ifdef CONFIG_MP
587129ba616SKumar Gala extern void cpu_mp_lmb_reserve(struct lmb *lmb);
588129ba616SKumar Gala 
589129ba616SKumar Gala void board_lmb_reserve(struct lmb *lmb)
590129ba616SKumar Gala {
591129ba616SKumar Gala 	cpu_mp_lmb_reserve(lmb);
592129ba616SKumar Gala }
593129ba616SKumar Gala #endif
594