1129ba616SKumar Gala /*
2561e710aSKumar Gala * Copyright 2007-2011 Freescale Semiconductor, Inc.
3129ba616SKumar Gala *
41a459660SWolfgang Denk * SPDX-License-Identifier: GPL-2.0+
5129ba616SKumar Gala */
6129ba616SKumar Gala
7129ba616SKumar Gala #include <common.h>
8129ba616SKumar Gala #include <command.h>
9129ba616SKumar Gala #include <pci.h>
10129ba616SKumar Gala #include <asm/processor.h>
11129ba616SKumar Gala #include <asm/mmu.h>
127c0d4a75SKumar Gala #include <asm/cache.h>
13129ba616SKumar Gala #include <asm/immap_85xx.h>
14c8514622SKumar Gala #include <asm/fsl_pci.h>
155614e71bSYork Sun #include <fsl_ddr_sdram.h>
16129ba616SKumar Gala #include <asm/io.h>
175d27e02cSKumar Gala #include <asm/fsl_serdes.h>
18129ba616SKumar Gala #include <miiphy.h>
19*0e00a84cSMasahiro Yamada #include <linux/libfdt.h>
20129ba616SKumar Gala #include <fdt_support.h>
217e183cadSLiu Yu #include <tsec.h>
22063c1263SAndy Fleming #include <fsl_mdio.h>
23b560ab85SKumar Gala #include <netdev.h>
24129ba616SKumar Gala
257e183cadSLiu Yu #include "../common/sgmii_riser.h"
26129ba616SKumar Gala
checkboard(void)27129ba616SKumar Gala int checkboard (void)
28129ba616SKumar Gala {
296bb5b412SKumar Gala u8 vboot;
306bb5b412SKumar Gala u8 *pixis_base = (u8 *)PIXIS_BASE;
316bb5b412SKumar Gala
325d065c3eSTimur Tabi printf("Board: MPC8572DS Sys ID: 0x%02x, "
336bb5b412SKumar Gala "Sys Ver: 0x%02x, FPGA Ver: 0x%02x, ",
346bb5b412SKumar Gala in_8(pixis_base + PIXIS_ID), in_8(pixis_base + PIXIS_VER),
356bb5b412SKumar Gala in_8(pixis_base + PIXIS_PVER));
366bb5b412SKumar Gala
376bb5b412SKumar Gala vboot = in_8(pixis_base + PIXIS_VBOOT);
386bb5b412SKumar Gala switch ((vboot & PIXIS_VBOOT_LBMAP) >> 6) {
396bb5b412SKumar Gala case PIXIS_VBOOT_LBMAP_NOR0:
406bb5b412SKumar Gala puts ("vBank: 0\n");
416bb5b412SKumar Gala break;
426bb5b412SKumar Gala case PIXIS_VBOOT_LBMAP_PJET:
436bb5b412SKumar Gala puts ("Promjet\n");
446bb5b412SKumar Gala break;
456bb5b412SKumar Gala case PIXIS_VBOOT_LBMAP_NAND:
466bb5b412SKumar Gala puts ("NAND\n");
476bb5b412SKumar Gala break;
486bb5b412SKumar Gala case PIXIS_VBOOT_LBMAP_NOR1:
496bb5b412SKumar Gala puts ("vBank: 1\n");
506bb5b412SKumar Gala break;
516bb5b412SKumar Gala }
526bb5b412SKumar Gala
53129ba616SKumar Gala return 0;
54129ba616SKumar Gala }
55129ba616SKumar Gala
56129ba616SKumar Gala
57129ba616SKumar Gala #if !defined(CONFIG_SPD_EEPROM)
58129ba616SKumar Gala /*
59129ba616SKumar Gala * Fixed sdram init -- doesn't use serial presence detect.
60129ba616SKumar Gala */
61129ba616SKumar Gala
fixed_sdram(void)62129ba616SKumar Gala phys_size_t fixed_sdram (void)
63129ba616SKumar Gala {
646d0f6bcfSJean-Christophe PLAGNIOL-VILLARD volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
659a17eb5bSYork Sun struct ccsr_ddr __iomem *ddr = &immap->im_ddr;
66129ba616SKumar Gala uint d_init;
67129ba616SKumar Gala
686d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->cs0_bnds = CONFIG_SYS_DDR_CS0_BNDS;
696d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->cs0_config = CONFIG_SYS_DDR_CS0_CONFIG;
70129ba616SKumar Gala
716d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
726d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
736d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
746d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
756d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->sdram_mode = CONFIG_SYS_DDR_MODE_1;
766d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->sdram_mode_2 = CONFIG_SYS_DDR_MODE_2;
776d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->sdram_interval = CONFIG_SYS_DDR_INTERVAL;
786d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->sdram_data_init = CONFIG_SYS_DDR_DATA_INIT;
796d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CTRL;
806d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->sdram_cfg_2 = CONFIG_SYS_DDR_CONTROL2;
81129ba616SKumar Gala
82129ba616SKumar Gala #if defined (CONFIG_DDR_ECC)
836d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->err_int_en = CONFIG_SYS_DDR_ERR_INT_EN;
846d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->err_disable = CONFIG_SYS_DDR_ERR_DIS;
856d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->err_sbe = CONFIG_SYS_DDR_SBE;
86129ba616SKumar Gala #endif
87129ba616SKumar Gala asm("sync;isync");
88129ba616SKumar Gala
89129ba616SKumar Gala udelay(500);
90129ba616SKumar Gala
916d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->sdram_cfg = CONFIG_SYS_DDR_CONTROL;
92129ba616SKumar Gala
93129ba616SKumar Gala #if defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
94129ba616SKumar Gala d_init = 1;
95129ba616SKumar Gala debug("DDR - 1st controller: memory initializing\n");
96129ba616SKumar Gala /*
97129ba616SKumar Gala * Poll until memory is initialized.
98129ba616SKumar Gala * 512 Meg at 400 might hit this 200 times or so.
99129ba616SKumar Gala */
100129ba616SKumar Gala while ((ddr->sdram_cfg_2 & (d_init << 4)) != 0) {
101129ba616SKumar Gala udelay(1000);
102129ba616SKumar Gala }
103129ba616SKumar Gala debug("DDR: memory initialized\n\n");
104129ba616SKumar Gala asm("sync; isync");
105129ba616SKumar Gala udelay(500);
106129ba616SKumar Gala #endif
107129ba616SKumar Gala
108129ba616SKumar Gala return 512 * 1024 * 1024;
109129ba616SKumar Gala }
110129ba616SKumar Gala
111129ba616SKumar Gala #endif
112129ba616SKumar Gala
113129ba616SKumar Gala #ifdef CONFIG_PCI
pci_init_board(void)114129ba616SKumar Gala void pci_init_board(void)
115129ba616SKumar Gala {
11618ea5551SKumar Gala struct pci_controller *hose;
117f61dae7cSKumar Gala
11818ea5551SKumar Gala fsl_pcie_init_board(0);
119f61dae7cSKumar Gala
12018ea5551SKumar Gala hose = find_hose_by_cfg_addr((void *)(CONFIG_SYS_PCIE3_ADDR));
121129ba616SKumar Gala
12218ea5551SKumar Gala if (hose) {
12318ea5551SKumar Gala u32 temp32;
12418ea5551SKumar Gala u8 uli_busno = hose->first_busno + 2;
125129ba616SKumar Gala
126129ba616SKumar Gala /*
127129ba616SKumar Gala * Activate ULI1575 legacy chip by performing a fake
128129ba616SKumar Gala * memory access. Needed to make ULI RTC work.
129129ba616SKumar Gala * Device 1d has the first on-board memory BAR.
130129ba616SKumar Gala */
13118ea5551SKumar Gala pci_hose_read_config_dword(hose, PCI_BDF(uli_busno, 0x1d, 0),
132129ba616SKumar Gala PCI_BASE_ADDRESS_1, &temp32);
13318ea5551SKumar Gala
1345af0fdd8SKumar Gala if (temp32 >= CONFIG_SYS_PCIE3_MEM_BUS) {
13518ea5551SKumar Gala void *p = pci_mem_to_virt(PCI_BDF(uli_busno, 0x1d, 0),
136ad97dce1SKumar Gala temp32, 4, 0);
137ad97dce1SKumar Gala debug(" uli1572 read to %p\n", p);
138ad97dce1SKumar Gala in_be32(p);
139129ba616SKumar Gala }
140129ba616SKumar Gala }
141129ba616SKumar Gala }
142129ba616SKumar Gala #endif
143129ba616SKumar Gala
board_early_init_r(void)144129ba616SKumar Gala int board_early_init_r(void)
145129ba616SKumar Gala {
1466d0f6bcfSJean-Christophe PLAGNIOL-VILLARD const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
1479d045682SYork Sun int flash_esel = find_tlb_idx((void *)flashbase, 1);
148129ba616SKumar Gala
149129ba616SKumar Gala /*
150129ba616SKumar Gala * Remap Boot flash + PROMJET region to caching-inhibited
151129ba616SKumar Gala * so that flash can be erased properly.
152129ba616SKumar Gala */
153129ba616SKumar Gala
1547c0d4a75SKumar Gala /* Flush d-cache and invalidate i-cache of any FLASH data */
1557c0d4a75SKumar Gala flush_dcache();
1567c0d4a75SKumar Gala invalidate_icache();
157129ba616SKumar Gala
1589d045682SYork Sun if (flash_esel == -1) {
1599d045682SYork Sun /* very unlikely unless something is messed up */
1609d045682SYork Sun puts("Error: Could not find TLB for FLASH BASE\n");
1619d045682SYork Sun flash_esel = 2; /* give our best effort to continue */
1629d045682SYork Sun } else {
163129ba616SKumar Gala /* invalidate existing TLB entry for flash + promjet */
164129ba616SKumar Gala disable_tlb(flash_esel);
1659d045682SYork Sun }
166129ba616SKumar Gala
167c953ddfdSKumar Gala set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS, /* tlb, epn, rpn */
168129ba616SKumar Gala MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, /* perms, wimge */
169129ba616SKumar Gala 0, flash_esel, BOOKE_PAGESZ_256M, 1); /* ts, esel, tsize, iprot */
170129ba616SKumar Gala
171129ba616SKumar Gala return 0;
172129ba616SKumar Gala }
173129ba616SKumar Gala
board_eth_init(bd_t * bis)1747e183cadSLiu Yu int board_eth_init(bd_t *bis)
1757e183cadSLiu Yu {
1764521ae9dSBin Meng #ifdef CONFIG_TSEC_ENET
177063c1263SAndy Fleming struct fsl_pq_mdio_info mdio_info;
1787e183cadSLiu Yu struct tsec_info_struct tsec_info[4];
1797e183cadSLiu Yu int num = 0;
1807e183cadSLiu Yu
1817e183cadSLiu Yu #ifdef CONFIG_TSEC1
1827e183cadSLiu Yu SET_STD_TSEC_INFO(tsec_info[num], 1);
183058d7dc7SKumar Gala if (is_serdes_configured(SGMII_TSEC1)) {
184058d7dc7SKumar Gala puts("eTSEC1 is in sgmii mode.\n");
1857e183cadSLiu Yu tsec_info[num].flags |= TSEC_SGMII;
186058d7dc7SKumar Gala }
1877e183cadSLiu Yu num++;
1887e183cadSLiu Yu #endif
1897e183cadSLiu Yu #ifdef CONFIG_TSEC2
1907e183cadSLiu Yu SET_STD_TSEC_INFO(tsec_info[num], 2);
191058d7dc7SKumar Gala if (is_serdes_configured(SGMII_TSEC2)) {
192058d7dc7SKumar Gala puts("eTSEC2 is in sgmii mode.\n");
1937e183cadSLiu Yu tsec_info[num].flags |= TSEC_SGMII;
194058d7dc7SKumar Gala }
1957e183cadSLiu Yu num++;
1967e183cadSLiu Yu #endif
1977e183cadSLiu Yu #ifdef CONFIG_TSEC3
1987e183cadSLiu Yu SET_STD_TSEC_INFO(tsec_info[num], 3);
199058d7dc7SKumar Gala if (is_serdes_configured(SGMII_TSEC3)) {
200058d7dc7SKumar Gala puts("eTSEC3 is in sgmii mode.\n");
2017e183cadSLiu Yu tsec_info[num].flags |= TSEC_SGMII;
202058d7dc7SKumar Gala }
2037e183cadSLiu Yu num++;
2047e183cadSLiu Yu #endif
2057e183cadSLiu Yu #ifdef CONFIG_TSEC4
2067e183cadSLiu Yu SET_STD_TSEC_INFO(tsec_info[num], 4);
207058d7dc7SKumar Gala if (is_serdes_configured(SGMII_TSEC4)) {
208058d7dc7SKumar Gala puts("eTSEC4 is in sgmii mode.\n");
2097e183cadSLiu Yu tsec_info[num].flags |= TSEC_SGMII;
210058d7dc7SKumar Gala }
2117e183cadSLiu Yu num++;
2127e183cadSLiu Yu #endif
2137e183cadSLiu Yu
2147e183cadSLiu Yu if (!num) {
2157e183cadSLiu Yu printf("No TSECs initialized\n");
2167e183cadSLiu Yu
2177e183cadSLiu Yu return 0;
2187e183cadSLiu Yu }
2197e183cadSLiu Yu
220feede8b0SAndy Fleming #ifdef CONFIG_FSL_SGMII_RISER
2217e183cadSLiu Yu fsl_sgmii_riser_init(tsec_info, num);
222feede8b0SAndy Fleming #endif
2237e183cadSLiu Yu
224063c1263SAndy Fleming mdio_info.regs = (struct tsec_mii_mng *)CONFIG_SYS_MDIO_BASE_ADDR;
225063c1263SAndy Fleming mdio_info.name = DEFAULT_MII_NAME;
226063c1263SAndy Fleming fsl_pq_mdio_init(bis, &mdio_info);
227063c1263SAndy Fleming
2287e183cadSLiu Yu tsec_eth_init(bis, tsec_info, num);
2294521ae9dSBin Meng #endif
2307e183cadSLiu Yu
231b560ab85SKumar Gala return pci_eth_init(bis);
2327e183cadSLiu Yu }
2337e183cadSLiu Yu
234129ba616SKumar Gala #if defined(CONFIG_OF_BOARD_SETUP)
ft_board_setup(void * blob,bd_t * bd)235e895a4b0SSimon Glass int ft_board_setup(void *blob, bd_t *bd)
236129ba616SKumar Gala {
237b6730512SKumar Gala phys_addr_t base;
238b6730512SKumar Gala phys_size_t size;
239129ba616SKumar Gala
240129ba616SKumar Gala ft_cpu_setup(blob, bd);
241129ba616SKumar Gala
242723806ccSSimon Glass base = env_get_bootm_low();
243723806ccSSimon Glass size = env_get_bootm_size();
244129ba616SKumar Gala
245129ba616SKumar Gala fdt_fixup_memory(blob, (u64)base, (u64)size);
246129ba616SKumar Gala
2476525d51fSKumar Gala FT_FSL_PCI_SETUP;
2486525d51fSKumar Gala
249feede8b0SAndy Fleming #ifdef CONFIG_FSL_SGMII_RISER
250feede8b0SAndy Fleming fsl_sgmii_riser_fdt_fixup(blob);
251feede8b0SAndy Fleming #endif
252e895a4b0SSimon Glass
253e895a4b0SSimon Glass return 0;
254129ba616SKumar Gala }
255129ba616SKumar Gala #endif
256