19490a7f1SKumar Gala /* 2*54648985SKumar Gala * Copyright 2008-2010 Freescale Semiconductor, Inc. 39490a7f1SKumar Gala * 49490a7f1SKumar Gala * See file CREDITS for list of people who contributed to this 59490a7f1SKumar Gala * project. 69490a7f1SKumar Gala * 79490a7f1SKumar Gala * This program is free software; you can redistribute it and/or 89490a7f1SKumar Gala * modify it under the terms of the GNU General Public License as 99490a7f1SKumar Gala * published by the Free Software Foundation; either version 2 of 109490a7f1SKumar Gala * the License, or (at your option) any later version. 119490a7f1SKumar Gala * 129490a7f1SKumar Gala * This program is distributed in the hope that it will be useful, 139490a7f1SKumar Gala * but WITHOUT ANY WARRANTY; without even the implied warranty of 149490a7f1SKumar Gala * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 159490a7f1SKumar Gala * GNU General Public License for more details. 169490a7f1SKumar Gala * 179490a7f1SKumar Gala * You should have received a copy of the GNU General Public License 189490a7f1SKumar Gala * along with this program; if not, write to the Free Software 199490a7f1SKumar Gala * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 209490a7f1SKumar Gala * MA 02111-1307 USA 219490a7f1SKumar Gala */ 229490a7f1SKumar Gala 239490a7f1SKumar Gala #include <common.h> 249490a7f1SKumar Gala #include <command.h> 259490a7f1SKumar Gala #include <pci.h> 269490a7f1SKumar Gala #include <asm/processor.h> 279490a7f1SKumar Gala #include <asm/mmu.h> 287c0d4a75SKumar Gala #include <asm/cache.h> 299490a7f1SKumar Gala #include <asm/immap_85xx.h> 30c8514622SKumar Gala #include <asm/fsl_pci.h> 319490a7f1SKumar Gala #include <asm/fsl_ddr_sdram.h> 329490a7f1SKumar Gala #include <asm/io.h> 33*54648985SKumar Gala #include <asm/fsl_serdes.h> 349490a7f1SKumar Gala #include <spd.h> 359490a7f1SKumar Gala #include <miiphy.h> 369490a7f1SKumar Gala #include <libfdt.h> 379490a7f1SKumar Gala #include <spd_sdram.h> 389490a7f1SKumar Gala #include <fdt_support.h> 392e26d837SJason Jin #include <tsec.h> 402e26d837SJason Jin #include <netdev.h> 4154a7cc49SWolfgang Denk #include <sata.h> 429490a7f1SKumar Gala 432e26d837SJason Jin #include "../common/sgmii_riser.h" 449490a7f1SKumar Gala 459490a7f1SKumar Gala phys_size_t fixed_sdram(void); 469490a7f1SKumar Gala 4780522dc8SAndy Fleming int board_early_init_f (void) 4880522dc8SAndy Fleming { 4980522dc8SAndy Fleming #ifdef CONFIG_MMC 5080522dc8SAndy Fleming volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); 5180522dc8SAndy Fleming 5280522dc8SAndy Fleming setbits_be32(&gur->pmuxcr, 5380522dc8SAndy Fleming (MPC85xx_PMUXCR_SD_DATA | 5480522dc8SAndy Fleming MPC85xx_PMUXCR_SDHC_CD | 5580522dc8SAndy Fleming MPC85xx_PMUXCR_SDHC_WP)); 5680522dc8SAndy Fleming 5780522dc8SAndy Fleming #endif 5880522dc8SAndy Fleming return 0; 5980522dc8SAndy Fleming } 6080522dc8SAndy Fleming 619490a7f1SKumar Gala int checkboard (void) 629490a7f1SKumar Gala { 636bb5b412SKumar Gala u8 vboot; 646bb5b412SKumar Gala u8 *pixis_base = (u8 *)PIXIS_BASE; 656bb5b412SKumar Gala 666bb5b412SKumar Gala puts("Board: MPC8536DS "); 676bb5b412SKumar Gala #ifdef CONFIG_PHYS_64BIT 686bb5b412SKumar Gala puts("(36-bit addrmap) "); 696bb5b412SKumar Gala #endif 706bb5b412SKumar Gala 716bb5b412SKumar Gala printf ("Sys ID: 0x%02x, " 726bb5b412SKumar Gala "Sys Ver: 0x%02x, FPGA Ver: 0x%02x, ", 736bb5b412SKumar Gala in_8(pixis_base + PIXIS_ID), in_8(pixis_base + PIXIS_VER), 746bb5b412SKumar Gala in_8(pixis_base + PIXIS_PVER)); 756bb5b412SKumar Gala 766bb5b412SKumar Gala vboot = in_8(pixis_base + PIXIS_VBOOT); 776bb5b412SKumar Gala switch ((vboot & PIXIS_VBOOT_LBMAP) >> 5) { 786bb5b412SKumar Gala case PIXIS_VBOOT_LBMAP_NOR0: 796bb5b412SKumar Gala puts ("vBank: 0\n"); 806bb5b412SKumar Gala break; 816bb5b412SKumar Gala case PIXIS_VBOOT_LBMAP_NOR1: 826bb5b412SKumar Gala puts ("vBank: 1\n"); 836bb5b412SKumar Gala break; 846bb5b412SKumar Gala case PIXIS_VBOOT_LBMAP_NOR2: 856bb5b412SKumar Gala puts ("vBank: 2\n"); 866bb5b412SKumar Gala break; 876bb5b412SKumar Gala case PIXIS_VBOOT_LBMAP_NOR3: 886bb5b412SKumar Gala puts ("vBank: 3\n"); 896bb5b412SKumar Gala break; 906bb5b412SKumar Gala case PIXIS_VBOOT_LBMAP_PJET: 916bb5b412SKumar Gala puts ("Promjet\n"); 926bb5b412SKumar Gala break; 936bb5b412SKumar Gala case PIXIS_VBOOT_LBMAP_NAND: 946bb5b412SKumar Gala puts ("NAND\n"); 956bb5b412SKumar Gala break; 966bb5b412SKumar Gala } 976bb5b412SKumar Gala 989490a7f1SKumar Gala return 0; 999490a7f1SKumar Gala } 1009490a7f1SKumar Gala 1019490a7f1SKumar Gala phys_size_t 1029490a7f1SKumar Gala initdram(int board_type) 1039490a7f1SKumar Gala { 1049490a7f1SKumar Gala phys_size_t dram_size = 0; 1059490a7f1SKumar Gala 1069490a7f1SKumar Gala puts("Initializing...."); 1079490a7f1SKumar Gala 1089490a7f1SKumar Gala #ifdef CONFIG_SPD_EEPROM 1099490a7f1SKumar Gala dram_size = fsl_ddr_sdram(); 1109490a7f1SKumar Gala #else 1119490a7f1SKumar Gala dram_size = fixed_sdram(); 1129490a7f1SKumar Gala #endif 113e57f0fa1SDave Liu dram_size = setup_ddr_tlbs(dram_size / 0x100000); 114e57f0fa1SDave Liu dram_size *= 0x100000; 1159490a7f1SKumar Gala 1169490a7f1SKumar Gala puts(" DDR: "); 1179490a7f1SKumar Gala return dram_size; 1189490a7f1SKumar Gala } 1199490a7f1SKumar Gala 1209490a7f1SKumar Gala #if !defined(CONFIG_SPD_EEPROM) 1219490a7f1SKumar Gala /* 1229490a7f1SKumar Gala * Fixed sdram init -- doesn't use serial presence detect. 1239490a7f1SKumar Gala */ 1249490a7f1SKumar Gala 1259490a7f1SKumar Gala phys_size_t fixed_sdram (void) 1269490a7f1SKumar Gala { 1276d0f6bcfSJean-Christophe PLAGNIOL-VILLARD volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; 1289490a7f1SKumar Gala volatile ccsr_ddr_t *ddr= &immap->im_ddr; 1299490a7f1SKumar Gala uint d_init; 1309490a7f1SKumar Gala 1316d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->cs0_bnds = CONFIG_SYS_DDR_CS0_BNDS; 1326d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->cs0_config = CONFIG_SYS_DDR_CS0_CONFIG; 1339490a7f1SKumar Gala 1346d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3; 1356d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0; 1366d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1; 1376d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2; 1386d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->sdram_mode = CONFIG_SYS_DDR_MODE_1; 1396d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->sdram_mode_2 = CONFIG_SYS_DDR_MODE_2; 1406d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->sdram_interval = CONFIG_SYS_DDR_INTERVAL; 1416d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->sdram_data_init = CONFIG_SYS_DDR_DATA_INIT; 1426d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CTRL; 1436d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->sdram_cfg_2 = CONFIG_SYS_DDR_CONTROL2; 1449490a7f1SKumar Gala 1459490a7f1SKumar Gala #if defined (CONFIG_DDR_ECC) 1466d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->err_int_en = CONFIG_SYS_DDR_ERR_INT_EN; 1476d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->err_disable = CONFIG_SYS_DDR_ERR_DIS; 1486d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->err_sbe = CONFIG_SYS_DDR_SBE; 1499490a7f1SKumar Gala #endif 1509490a7f1SKumar Gala asm("sync;isync"); 1519490a7f1SKumar Gala 1529490a7f1SKumar Gala udelay(500); 1539490a7f1SKumar Gala 1546d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->sdram_cfg = CONFIG_SYS_DDR_CONTROL; 1559490a7f1SKumar Gala 1569490a7f1SKumar Gala #if defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER) 1579490a7f1SKumar Gala d_init = 1; 1589490a7f1SKumar Gala debug("DDR - 1st controller: memory initializing\n"); 1599490a7f1SKumar Gala /* 1609490a7f1SKumar Gala * Poll until memory is initialized. 1619490a7f1SKumar Gala * 512 Meg at 400 might hit this 200 times or so. 1629490a7f1SKumar Gala */ 1639490a7f1SKumar Gala while ((ddr->sdram_cfg_2 & (d_init << 4)) != 0) { 1649490a7f1SKumar Gala udelay(1000); 1659490a7f1SKumar Gala } 1669490a7f1SKumar Gala debug("DDR: memory initialized\n\n"); 1679490a7f1SKumar Gala asm("sync; isync"); 1689490a7f1SKumar Gala udelay(500); 1699490a7f1SKumar Gala #endif 1709490a7f1SKumar Gala 1719490a7f1SKumar Gala return 512 * 1024 * 1024; 1729490a7f1SKumar Gala } 1739490a7f1SKumar Gala 1749490a7f1SKumar Gala #endif 1759490a7f1SKumar Gala 1769490a7f1SKumar Gala #ifdef CONFIG_PCI1 1779490a7f1SKumar Gala static struct pci_controller pci1_hose; 1789490a7f1SKumar Gala #endif 1799490a7f1SKumar Gala 1809490a7f1SKumar Gala #ifdef CONFIG_PCIE1 1819490a7f1SKumar Gala static struct pci_controller pcie1_hose; 1829490a7f1SKumar Gala #endif 1839490a7f1SKumar Gala 1849490a7f1SKumar Gala #ifdef CONFIG_PCIE2 1859490a7f1SKumar Gala static struct pci_controller pcie2_hose; 1869490a7f1SKumar Gala #endif 1879490a7f1SKumar Gala 1889490a7f1SKumar Gala #ifdef CONFIG_PCIE3 1899490a7f1SKumar Gala static struct pci_controller pcie3_hose; 1909490a7f1SKumar Gala #endif 1919490a7f1SKumar Gala 1928a414c42SMingkai Hu #ifdef CONFIG_PCI 1938a414c42SMingkai Hu void pci_init_board(void) 1949490a7f1SKumar Gala { 1958a414c42SMingkai Hu ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); 1968a414c42SMingkai Hu struct fsl_pci_info pci_info[4]; 1978a414c42SMingkai Hu u32 devdisr, pordevsr, io_sel, sdrs2_io_sel; 1988a414c42SMingkai Hu u32 porpllsr, pci_agent, pci_speed, pci_32, pci_arb, pci_clk_sel; 1998a414c42SMingkai Hu int first_free_busno = 0; 2008a414c42SMingkai Hu int num = 0; 2019490a7f1SKumar Gala 2028a414c42SMingkai Hu int pcie_ep, pcie_configured; 2038a414c42SMingkai Hu 2048a414c42SMingkai Hu devdisr = in_be32(&gur->devdisr); 2058a414c42SMingkai Hu pordevsr = in_be32(&gur->pordevsr); 2068a414c42SMingkai Hu porpllsr = in_be32(&gur->porpllsr); 2078a414c42SMingkai Hu io_sel = (pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19; 2088a414c42SMingkai Hu sdrs2_io_sel = (pordevsr & MPC85xx_PORDEVSR_SRDS2_IO_SEL) >> 27; 2098a414c42SMingkai Hu 2108a414c42SMingkai Hu debug(" pci_init_board: devdisr=%x, sdrs2_io_sel=%x, io_sel=%x\n", 2118a414c42SMingkai Hu devdisr, sdrs2_io_sel, io_sel); 2129490a7f1SKumar Gala 2139490a7f1SKumar Gala if (sdrs2_io_sel == 7) 2149490a7f1SKumar Gala printf(" Serdes2 disalbed\n"); 2159490a7f1SKumar Gala else if (sdrs2_io_sel == 4) { 2169490a7f1SKumar Gala printf(" eTSEC1 is in sgmii mode.\n"); 2179490a7f1SKumar Gala printf(" eTSEC3 is in sgmii mode.\n"); 2189490a7f1SKumar Gala } else if (sdrs2_io_sel == 6) 2199490a7f1SKumar Gala printf(" eTSEC1 is in sgmii mode.\n"); 2209490a7f1SKumar Gala 2218a414c42SMingkai Hu puts("\n"); 2229490a7f1SKumar Gala #ifdef CONFIG_PCIE3 223*54648985SKumar Gala pcie_configured = is_serdes_configured(PCIE3); 2249490a7f1SKumar Gala 2258a414c42SMingkai Hu if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE3)){ 226*54648985SKumar Gala set_next_law(CONFIG_SYS_PCIE3_MEM_PHYS, LAW_SIZE_512M, 227*54648985SKumar Gala LAW_TRGT_IF_PCIE_3); 228*54648985SKumar Gala set_next_law(CONFIG_SYS_PCIE3_IO_PHYS, LAW_SIZE_64K, 229*54648985SKumar Gala LAW_TRGT_IF_PCIE_3); 2308a414c42SMingkai Hu SET_STD_PCIE_INFO(pci_info[num], 3); 2318a414c42SMingkai Hu pcie_ep = fsl_setup_hose(&pcie3_hose, pci_info[num].regs); 2328a414c42SMingkai Hu printf (" PCIE3 connected to Slot3 as %s (base address %lx)\n", 23364917ca3SPeter Tyser pcie_ep ? "Endpoint" : "Root Complex", 2348a414c42SMingkai Hu pci_info[num].regs); 2358a414c42SMingkai Hu first_free_busno = fsl_pci_init_port(&pci_info[num++], 2368a414c42SMingkai Hu &pcie3_hose, first_free_busno); 2379490a7f1SKumar Gala } else { 2389490a7f1SKumar Gala printf (" PCIE3: disabled\n"); 2399490a7f1SKumar Gala } 2408a414c42SMingkai Hu 2418a414c42SMingkai Hu puts("\n"); 2429490a7f1SKumar Gala #else 2438a414c42SMingkai Hu setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCIE3); /* disable */ 2449490a7f1SKumar Gala #endif 2459490a7f1SKumar Gala 2469490a7f1SKumar Gala #ifdef CONFIG_PCIE1 247*54648985SKumar Gala pcie_configured = is_serdes_configured(PCIE1); 2489490a7f1SKumar Gala 2499490a7f1SKumar Gala if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE)){ 250*54648985SKumar Gala set_next_law(CONFIG_SYS_PCIE1_MEM_PHYS, LAW_SIZE_128M, 251*54648985SKumar Gala LAW_TRGT_IF_PCIE_1); 252*54648985SKumar Gala set_next_law(CONFIG_SYS_PCIE1_IO_PHYS, LAW_SIZE_64K, 253*54648985SKumar Gala LAW_TRGT_IF_PCIE_1); 2548a414c42SMingkai Hu SET_STD_PCIE_INFO(pci_info[num], 1); 2558a414c42SMingkai Hu pcie_ep = fsl_setup_hose(&pcie1_hose, pci_info[num].regs); 2568a414c42SMingkai Hu printf (" PCIE1 connected to Slot1 as %s (base address %lx)\n", 25764917ca3SPeter Tyser pcie_ep ? "Endpoint" : "Root Complex", 2588a414c42SMingkai Hu pci_info[num].regs); 2598a414c42SMingkai Hu first_free_busno = fsl_pci_init_port(&pci_info[num++], 2608a414c42SMingkai Hu &pcie1_hose, first_free_busno); 2619490a7f1SKumar Gala } else { 2629490a7f1SKumar Gala printf (" PCIE1: disabled\n"); 2639490a7f1SKumar Gala } 2648a414c42SMingkai Hu 2658a414c42SMingkai Hu puts("\n"); 2669490a7f1SKumar Gala #else 2678a414c42SMingkai Hu setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCIE); /* disable */ 2689490a7f1SKumar Gala #endif 2699490a7f1SKumar Gala 2709490a7f1SKumar Gala #ifdef CONFIG_PCIE2 271*54648985SKumar Gala pcie_configured = is_serdes_configured(PCIE2); 2729490a7f1SKumar Gala 2738a414c42SMingkai Hu if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE2)){ 274*54648985SKumar Gala set_next_law(CONFIG_SYS_PCIE2_MEM_PHYS, LAW_SIZE_128M, 275*54648985SKumar Gala LAW_TRGT_IF_PCIE_2); 276*54648985SKumar Gala set_next_law(CONFIG_SYS_PCIE2_IO_PHYS, LAW_SIZE_64K, 277*54648985SKumar Gala LAW_TRGT_IF_PCIE_2); 2788a414c42SMingkai Hu SET_STD_PCIE_INFO(pci_info[num], 2); 2798a414c42SMingkai Hu pcie_ep = fsl_setup_hose(&pcie2_hose, pci_info[num].regs); 2808a414c42SMingkai Hu printf (" PCIE2 connected to Slot 2 as %s (base address %lx)\n", 28164917ca3SPeter Tyser pcie_ep ? "Endpoint" : "Root Complex", 2828a414c42SMingkai Hu pci_info[num].regs); 2838a414c42SMingkai Hu first_free_busno = fsl_pci_init_port(&pci_info[num++], 2848a414c42SMingkai Hu &pcie2_hose, first_free_busno); 2859490a7f1SKumar Gala } else { 2869490a7f1SKumar Gala printf (" PCIE2: disabled\n"); 2879490a7f1SKumar Gala } 2888a414c42SMingkai Hu 2898a414c42SMingkai Hu puts("\n"); 2909490a7f1SKumar Gala #else 2918a414c42SMingkai Hu setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCIE2); /* disable */ 2929490a7f1SKumar Gala #endif 2939490a7f1SKumar Gala 2949490a7f1SKumar Gala #ifdef CONFIG_PCI1 2958a414c42SMingkai Hu pci_speed = 66666000; 2968a414c42SMingkai Hu pci_32 = 1; 2978a414c42SMingkai Hu pci_arb = pordevsr & MPC85xx_PORDEVSR_PCI1_ARB; 2988a414c42SMingkai Hu pci_clk_sel = porpllsr & MPC85xx_PORDEVSR_PCI1_SPD; 2999490a7f1SKumar Gala 3009490a7f1SKumar Gala if (!(devdisr & MPC85xx_DEVDISR_PCI1)) { 301*54648985SKumar Gala set_next_law(CONFIG_SYS_PCI1_MEM_PHYS, LAW_SIZE_256M, 302*54648985SKumar Gala LAW_TRGT_IF_PCI); 303*54648985SKumar Gala set_next_law(CONFIG_SYS_PCI1_IO_PHYS, LAW_SIZE_64K, 304*54648985SKumar Gala LAW_TRGT_IF_PCI); 3058a414c42SMingkai Hu SET_STD_PCI_INFO(pci_info[num], 1); 3068a414c42SMingkai Hu pci_agent = fsl_setup_hose(&pci1_hose, pci_info[num].regs); 3078a414c42SMingkai Hu printf ("\n PCI: %d bit, %s MHz, %s, %s, %s (base address %lx)\n", 3089490a7f1SKumar Gala (pci_32) ? 32 : 64, 3099490a7f1SKumar Gala (pci_speed == 33333000) ? "33" : 3109490a7f1SKumar Gala (pci_speed == 66666000) ? "66" : "unknown", 3119490a7f1SKumar Gala pci_clk_sel ? "sync" : "async", 3129490a7f1SKumar Gala pci_agent ? "agent" : "host", 3139490a7f1SKumar Gala pci_arb ? "arbiter" : "external-arbiter", 3148a414c42SMingkai Hu pci_info[num].regs); 3159490a7f1SKumar Gala 3168a414c42SMingkai Hu first_free_busno = fsl_pci_init_port(&pci_info[num++], 3178a414c42SMingkai Hu &pci1_hose, first_free_busno); 3189490a7f1SKumar Gala } else { 3199490a7f1SKumar Gala printf (" PCI: disabled\n"); 3209490a7f1SKumar Gala } 3218a414c42SMingkai Hu 3228a414c42SMingkai Hu puts("\n"); 3239490a7f1SKumar Gala #else 3248a414c42SMingkai Hu setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCI1); /* disable */ 3259490a7f1SKumar Gala #endif 3269490a7f1SKumar Gala } 3278a414c42SMingkai Hu #endif 3289490a7f1SKumar Gala 3299490a7f1SKumar Gala int board_early_init_r(void) 3309490a7f1SKumar Gala { 3316d0f6bcfSJean-Christophe PLAGNIOL-VILLARD const unsigned int flashbase = CONFIG_SYS_FLASH_BASE; 3325fb6ea3aSKumar Gala const u8 flash_esel = find_tlb_idx((void *)flashbase, 1); 3339490a7f1SKumar Gala 3349490a7f1SKumar Gala /* 3359490a7f1SKumar Gala * Remap Boot flash + PROMJET region to caching-inhibited 3369490a7f1SKumar Gala * so that flash can be erased properly. 3379490a7f1SKumar Gala */ 3389490a7f1SKumar Gala 3397c0d4a75SKumar Gala /* Flush d-cache and invalidate i-cache of any FLASH data */ 3407c0d4a75SKumar Gala flush_dcache(); 3417c0d4a75SKumar Gala invalidate_icache(); 3429490a7f1SKumar Gala 3439490a7f1SKumar Gala /* invalidate existing TLB entry for flash + promjet */ 3449490a7f1SKumar Gala disable_tlb(flash_esel); 3459490a7f1SKumar Gala 346c953ddfdSKumar Gala set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS, /* tlb, epn, rpn */ 3479490a7f1SKumar Gala MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, /* perms, wimge */ 3489490a7f1SKumar Gala 0, flash_esel, BOOKE_PAGESZ_256M, 1); /* ts, esel, tsize, iprot */ 3499490a7f1SKumar Gala 3509490a7f1SKumar Gala return 0; 3519490a7f1SKumar Gala } 3529490a7f1SKumar Gala 3539490a7f1SKumar Gala #ifdef CONFIG_GET_CLK_FROM_ICS307 3549490a7f1SKumar Gala /* decode S[0-2] to Output Divider (OD) */ 3559490a7f1SKumar Gala static unsigned char 3569490a7f1SKumar Gala ics307_S_to_OD[] = { 3579490a7f1SKumar Gala 10, 2, 8, 4, 5, 7, 3, 6 3589490a7f1SKumar Gala }; 3599490a7f1SKumar Gala 3609490a7f1SKumar Gala /* Calculate frequency being generated by ICS307-02 clock chip based upon 3619490a7f1SKumar Gala * the control bytes being programmed into it. */ 3629490a7f1SKumar Gala /* XXX: This function should probably go into a common library */ 3639490a7f1SKumar Gala static unsigned long 3649490a7f1SKumar Gala ics307_clk_freq (unsigned char cw0, unsigned char cw1, unsigned char cw2) 3659490a7f1SKumar Gala { 3669490a7f1SKumar Gala const unsigned long long InputFrequency = CONFIG_ICS307_REFCLK_HZ; 3679490a7f1SKumar Gala unsigned long VDW = ((cw1 << 1) & 0x1FE) + ((cw2 >> 7) & 1); 3689490a7f1SKumar Gala unsigned long RDW = cw2 & 0x7F; 3699490a7f1SKumar Gala unsigned long OD = ics307_S_to_OD[cw0 & 0x7]; 3709490a7f1SKumar Gala unsigned long freq; 3719490a7f1SKumar Gala 3729490a7f1SKumar Gala /* CLK1Frequency = InputFrequency * 2 * (VDW + 8) / ((RDW + 2) * OD) */ 3739490a7f1SKumar Gala 3749490a7f1SKumar Gala /* cw0: C1 C0 TTL F1 F0 S2 S1 S0 3759490a7f1SKumar Gala * cw1: V8 V7 V6 V5 V4 V3 V2 V1 3769490a7f1SKumar Gala * cw2: V0 R6 R5 R4 R3 R2 R1 R0 3779490a7f1SKumar Gala * 3789490a7f1SKumar Gala * R6:R0 = Reference Divider Word (RDW) 3799490a7f1SKumar Gala * V8:V0 = VCO Divider Word (VDW) 3809490a7f1SKumar Gala * S2:S0 = Output Divider Select (OD) 3819490a7f1SKumar Gala * F1:F0 = Function of CLK2 Output 3829490a7f1SKumar Gala * TTL = duty cycle 3839490a7f1SKumar Gala * C1:C0 = internal load capacitance for cyrstal 3849490a7f1SKumar Gala */ 3859490a7f1SKumar Gala 3869490a7f1SKumar Gala /* Adding 1 to get a "nicely" rounded number, but this needs 3879490a7f1SKumar Gala * more tweaking to get a "properly" rounded number. */ 3889490a7f1SKumar Gala 3899490a7f1SKumar Gala freq = 1 + (InputFrequency * 2 * (VDW + 8) / ((RDW + 2) * OD)); 3909490a7f1SKumar Gala 3919490a7f1SKumar Gala debug("ICS307: CW[0-2]: %02X %02X %02X => %u Hz\n", cw0, cw1, cw2, 3929490a7f1SKumar Gala freq); 3939490a7f1SKumar Gala return freq; 3949490a7f1SKumar Gala } 3959490a7f1SKumar Gala 3969490a7f1SKumar Gala unsigned long 3979490a7f1SKumar Gala get_board_sys_clk(ulong dummy) 3989490a7f1SKumar Gala { 399048e7efeSKumar Gala u8 *pixis_base = (u8 *)PIXIS_BASE; 400048e7efeSKumar Gala 4019490a7f1SKumar Gala return ics307_clk_freq ( 402048e7efeSKumar Gala in_8(pixis_base + PIXIS_VSYSCLK0), 403048e7efeSKumar Gala in_8(pixis_base + PIXIS_VSYSCLK1), 404048e7efeSKumar Gala in_8(pixis_base + PIXIS_VSYSCLK2) 4059490a7f1SKumar Gala ); 4069490a7f1SKumar Gala } 4079490a7f1SKumar Gala 4089490a7f1SKumar Gala unsigned long 4099490a7f1SKumar Gala get_board_ddr_clk(ulong dummy) 4109490a7f1SKumar Gala { 411048e7efeSKumar Gala u8 *pixis_base = (u8 *)PIXIS_BASE; 412048e7efeSKumar Gala 4139490a7f1SKumar Gala return ics307_clk_freq ( 414048e7efeSKumar Gala in_8(pixis_base + PIXIS_VDDRCLK0), 415048e7efeSKumar Gala in_8(pixis_base + PIXIS_VDDRCLK1), 416048e7efeSKumar Gala in_8(pixis_base + PIXIS_VDDRCLK2) 4179490a7f1SKumar Gala ); 4189490a7f1SKumar Gala } 4199490a7f1SKumar Gala #else 4209490a7f1SKumar Gala unsigned long 4219490a7f1SKumar Gala get_board_sys_clk(ulong dummy) 4229490a7f1SKumar Gala { 4239490a7f1SKumar Gala u8 i; 4249490a7f1SKumar Gala ulong val = 0; 425048e7efeSKumar Gala u8 *pixis_base = (u8 *)PIXIS_BASE; 4269490a7f1SKumar Gala 427048e7efeSKumar Gala i = in_8(pixis_base + PIXIS_SPD); 4289490a7f1SKumar Gala i &= 0x07; 4299490a7f1SKumar Gala 4309490a7f1SKumar Gala switch (i) { 4319490a7f1SKumar Gala case 0: 4329490a7f1SKumar Gala val = 33333333; 4339490a7f1SKumar Gala break; 4349490a7f1SKumar Gala case 1: 4359490a7f1SKumar Gala val = 40000000; 4369490a7f1SKumar Gala break; 4379490a7f1SKumar Gala case 2: 4389490a7f1SKumar Gala val = 50000000; 4399490a7f1SKumar Gala break; 4409490a7f1SKumar Gala case 3: 4419490a7f1SKumar Gala val = 66666666; 4429490a7f1SKumar Gala break; 4439490a7f1SKumar Gala case 4: 4449490a7f1SKumar Gala val = 83333333; 4459490a7f1SKumar Gala break; 4469490a7f1SKumar Gala case 5: 4479490a7f1SKumar Gala val = 100000000; 4489490a7f1SKumar Gala break; 4499490a7f1SKumar Gala case 6: 4509490a7f1SKumar Gala val = 133333333; 4519490a7f1SKumar Gala break; 4529490a7f1SKumar Gala case 7: 4539490a7f1SKumar Gala val = 166666666; 4549490a7f1SKumar Gala break; 4559490a7f1SKumar Gala } 4569490a7f1SKumar Gala 4579490a7f1SKumar Gala return val; 4589490a7f1SKumar Gala } 4599490a7f1SKumar Gala 4609490a7f1SKumar Gala unsigned long 4619490a7f1SKumar Gala get_board_ddr_clk(ulong dummy) 4629490a7f1SKumar Gala { 4639490a7f1SKumar Gala u8 i; 4649490a7f1SKumar Gala ulong val = 0; 465048e7efeSKumar Gala u8 *pixis_base = (u8 *)PIXIS_BASE; 4669490a7f1SKumar Gala 467048e7efeSKumar Gala i = in_8(pixis_base + PIXIS_SPD); 4689490a7f1SKumar Gala i &= 0x38; 4699490a7f1SKumar Gala i >>= 3; 4709490a7f1SKumar Gala 4719490a7f1SKumar Gala switch (i) { 4729490a7f1SKumar Gala case 0: 4739490a7f1SKumar Gala val = 33333333; 4749490a7f1SKumar Gala break; 4759490a7f1SKumar Gala case 1: 4769490a7f1SKumar Gala val = 40000000; 4779490a7f1SKumar Gala break; 4789490a7f1SKumar Gala case 2: 4799490a7f1SKumar Gala val = 50000000; 4809490a7f1SKumar Gala break; 4819490a7f1SKumar Gala case 3: 4829490a7f1SKumar Gala val = 66666666; 4839490a7f1SKumar Gala break; 4849490a7f1SKumar Gala case 4: 4859490a7f1SKumar Gala val = 83333333; 4869490a7f1SKumar Gala break; 4879490a7f1SKumar Gala case 5: 4889490a7f1SKumar Gala val = 100000000; 4899490a7f1SKumar Gala break; 4909490a7f1SKumar Gala case 6: 4919490a7f1SKumar Gala val = 133333333; 4929490a7f1SKumar Gala break; 4939490a7f1SKumar Gala case 7: 4949490a7f1SKumar Gala val = 166666666; 4959490a7f1SKumar Gala break; 4969490a7f1SKumar Gala } 4979490a7f1SKumar Gala return val; 4989490a7f1SKumar Gala } 4999490a7f1SKumar Gala #endif 5009490a7f1SKumar Gala 501cf7e399fSMike Frysinger int sata_initialize(void) 5020f8cbc18SJason Jin { 5036d0f6bcfSJean-Christophe PLAGNIOL-VILLARD volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); 5040f8cbc18SJason Jin uint sdrs2_io_sel = 5050f8cbc18SJason Jin (gur->pordevsr & MPC85xx_PORDEVSR_SRDS2_IO_SEL) >> 27; 5060f8cbc18SJason Jin if (sdrs2_io_sel & 0x04) 5070f8cbc18SJason Jin return 1; 508cf7e399fSMike Frysinger 509cf7e399fSMike Frysinger return __sata_initialize(); 5100f8cbc18SJason Jin } 5110f8cbc18SJason Jin 5122e26d837SJason Jin int board_eth_init(bd_t *bis) 5132e26d837SJason Jin { 5142e26d837SJason Jin #ifdef CONFIG_TSEC_ENET 5152e26d837SJason Jin struct tsec_info_struct tsec_info[2]; 5162e26d837SJason Jin volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); 5172e26d837SJason Jin int num = 0; 5182e26d837SJason Jin uint sdrs2_io_sel = 5192e26d837SJason Jin (gur->pordevsr & MPC85xx_PORDEVSR_SRDS2_IO_SEL) >> 27; 5202e26d837SJason Jin 5212e26d837SJason Jin #ifdef CONFIG_TSEC1 5222e26d837SJason Jin SET_STD_TSEC_INFO(tsec_info[num], 1); 5232e26d837SJason Jin if ((sdrs2_io_sel == 4) || (sdrs2_io_sel == 6)) { 5242e26d837SJason Jin tsec_info[num].phyaddr = 0; 5252e26d837SJason Jin tsec_info[num].flags |= TSEC_SGMII; 5262e26d837SJason Jin } 5272e26d837SJason Jin num++; 5282e26d837SJason Jin #endif 5292e26d837SJason Jin #ifdef CONFIG_TSEC3 5302e26d837SJason Jin SET_STD_TSEC_INFO(tsec_info[num], 3); 5312e26d837SJason Jin if (sdrs2_io_sel == 4) { 5322e26d837SJason Jin tsec_info[num].phyaddr = 1; 5332e26d837SJason Jin tsec_info[num].flags |= TSEC_SGMII; 5342e26d837SJason Jin } 5352e26d837SJason Jin num++; 5362e26d837SJason Jin #endif 5372e26d837SJason Jin 5382e26d837SJason Jin if (!num) { 5392e26d837SJason Jin printf("No TSECs initialized\n"); 5402e26d837SJason Jin return 0; 5412e26d837SJason Jin } 5422e26d837SJason Jin 543feede8b0SAndy Fleming #ifdef CONFIG_FSL_SGMII_RISER 5442e26d837SJason Jin if ((sdrs2_io_sel == 4) || (sdrs2_io_sel == 6)) 5452e26d837SJason Jin fsl_sgmii_riser_init(tsec_info, num); 546feede8b0SAndy Fleming #endif 5472e26d837SJason Jin 5482e26d837SJason Jin tsec_eth_init(bis, tsec_info, num); 5492e26d837SJason Jin #endif 5502e26d837SJason Jin return pci_eth_init(bis); 5512e26d837SJason Jin } 5522e26d837SJason Jin 5539490a7f1SKumar Gala #if defined(CONFIG_OF_BOARD_SETUP) 5542dba0deaSKumar Gala void ft_board_setup(void *blob, bd_t *bd) 5552dba0deaSKumar Gala { 5569490a7f1SKumar Gala ft_cpu_setup(blob, bd); 5579490a7f1SKumar Gala 5589490a7f1SKumar Gala #ifdef CONFIG_PCI1 5592dba0deaSKumar Gala ft_fsl_pci_setup(blob, "pci0", &pci1_hose); 560*54648985SKumar Gala #else 561*54648985SKumar Gala ft_fsl_pci_setup(blob, "pci0", NULL); 5629490a7f1SKumar Gala #endif 5639490a7f1SKumar Gala #ifdef CONFIG_PCIE2 5642dba0deaSKumar Gala ft_fsl_pci_setup(blob, "pci1", &pcie2_hose); 565*54648985SKumar Gala #else 566*54648985SKumar Gala ft_fsl_pci_setup(blob, "pci1", NULL); 5672dba0deaSKumar Gala #endif 5682dba0deaSKumar Gala #ifdef CONFIG_PCIE2 5692dba0deaSKumar Gala ft_fsl_pci_setup(blob, "pci2", &pcie1_hose); 570*54648985SKumar Gala #else 571*54648985SKumar Gala ft_fsl_pci_setup(blob, "pci2", NULL); 5729490a7f1SKumar Gala #endif 5739490a7f1SKumar Gala #ifdef CONFIG_PCIE1 5742dba0deaSKumar Gala ft_fsl_pci_setup(blob, "pci3", &pcie3_hose); 575*54648985SKumar Gala #else 576*54648985SKumar Gala ft_fsl_pci_setup(blob, "pci3", NULL); 5779490a7f1SKumar Gala #endif 578feede8b0SAndy Fleming #ifdef CONFIG_FSL_SGMII_RISER 579feede8b0SAndy Fleming fsl_sgmii_riser_fdt_fixup(blob); 580feede8b0SAndy Fleming #endif 5819490a7f1SKumar Gala } 5829490a7f1SKumar Gala #endif 583