18bd522ceSDave Liu /* 28bd522ceSDave Liu * Copyright (C) 2007 Freescale Semiconductor, Inc. 38bd522ceSDave Liu * 48bd522ceSDave Liu * Author: Scott Wood <scottwood@freescale.com> 58bd522ceSDave Liu * Dave Liu <daveliu@freescale.com> 68bd522ceSDave Liu * 78bd522ceSDave Liu * See file CREDITS for list of people who contributed to this 88bd522ceSDave Liu * project. 98bd522ceSDave Liu * 108bd522ceSDave Liu * This program is free software; you can redistribute it and/or 118bd522ceSDave Liu * modify it under the terms of the GNU General Public License as 128bd522ceSDave Liu * published by the Free Software Foundation; either version 2 of 138bd522ceSDave Liu * the License, or (at your option) any later version. 148bd522ceSDave Liu * 158bd522ceSDave Liu * This program is distributed in the hope that it will be useful, 168bd522ceSDave Liu * but WITHOUT ANY WARRANTY; without even the implied warranty of 178bd522ceSDave Liu * MERCHANTABILITY or FITNESS for A PARTICULAR PURPOSE. See the 188bd522ceSDave Liu * GNU General Public License for more details. 198bd522ceSDave Liu * 208bd522ceSDave Liu * You should have received a copy of the GNU General Public License 218bd522ceSDave Liu * along with this program; if not, write to the Free Software 228bd522ceSDave Liu * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 238bd522ceSDave Liu * MA 02111-1307 USA 248bd522ceSDave Liu */ 258bd522ceSDave Liu 268bd522ceSDave Liu #include <common.h> 27*b8b71ffbSAnton Vorontsov #include <hwconfig.h> 288bd522ceSDave Liu #include <i2c.h> 298bd522ceSDave Liu #include <libfdt.h> 3025f5f0d4SAnton Vorontsov #include <fdt_support.h> 318bd522ceSDave Liu #include <pci.h> 328bd522ceSDave Liu #include <mpc83xx.h> 3310efa024SBen Warren #include <netdev.h> 348f11e34bSAnton Vorontsov #include <asm/io.h> 358bd522ceSDave Liu 368bd522ceSDave Liu DECLARE_GLOBAL_DATA_PTR; 378bd522ceSDave Liu 388bd522ceSDave Liu int board_early_init_f(void) 398bd522ceSDave Liu { 406d0f6bcfSJean-Christophe PLAGNIOL-VILLARD volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR; 418bd522ceSDave Liu 428bd522ceSDave Liu if (im->pmc.pmccr1 & PMCCR1_POWER_OFF) 438bd522ceSDave Liu gd->flags |= GD_FLG_SILENT; 448bd522ceSDave Liu 458bd522ceSDave Liu return 0; 468bd522ceSDave Liu } 478bd522ceSDave Liu 488bd522ceSDave Liu static u8 read_board_info(void) 498bd522ceSDave Liu { 508bd522ceSDave Liu u8 val8; 518bd522ceSDave Liu i2c_set_bus_num(0); 528bd522ceSDave Liu 536d0f6bcfSJean-Christophe PLAGNIOL-VILLARD if (i2c_read(CONFIG_SYS_I2C_PCF8574A_ADDR, 0, 0, &val8, 1) == 0) 548bd522ceSDave Liu return val8; 558bd522ceSDave Liu else 568bd522ceSDave Liu return 0; 578bd522ceSDave Liu } 588bd522ceSDave Liu 598bd522ceSDave Liu int checkboard(void) 608bd522ceSDave Liu { 618bd522ceSDave Liu static const char * const rev_str[] = { 628bd522ceSDave Liu "0.0", 638bd522ceSDave Liu "0.1", 648bd522ceSDave Liu "1.0", 658bd522ceSDave Liu "1.1", 668bd522ceSDave Liu "<unknown>", 678bd522ceSDave Liu }; 688bd522ceSDave Liu u8 info; 698bd522ceSDave Liu int i; 708bd522ceSDave Liu 718bd522ceSDave Liu info = read_board_info(); 728bd522ceSDave Liu i = (!info) ? 4: info & 0x03; 738bd522ceSDave Liu 748bd522ceSDave Liu printf("Board: Freescale MPC8315ERDB Rev %s\n", rev_str[i]); 758bd522ceSDave Liu 768bd522ceSDave Liu return 0; 778bd522ceSDave Liu } 788bd522ceSDave Liu 798bd522ceSDave Liu static struct pci_region pci_regions[] = { 808bd522ceSDave Liu { 816d0f6bcfSJean-Christophe PLAGNIOL-VILLARD bus_start: CONFIG_SYS_PCI_MEM_BASE, 826d0f6bcfSJean-Christophe PLAGNIOL-VILLARD phys_start: CONFIG_SYS_PCI_MEM_PHYS, 836d0f6bcfSJean-Christophe PLAGNIOL-VILLARD size: CONFIG_SYS_PCI_MEM_SIZE, 848bd522ceSDave Liu flags: PCI_REGION_MEM | PCI_REGION_PREFETCH 858bd522ceSDave Liu }, 868bd522ceSDave Liu { 876d0f6bcfSJean-Christophe PLAGNIOL-VILLARD bus_start: CONFIG_SYS_PCI_MMIO_BASE, 886d0f6bcfSJean-Christophe PLAGNIOL-VILLARD phys_start: CONFIG_SYS_PCI_MMIO_PHYS, 896d0f6bcfSJean-Christophe PLAGNIOL-VILLARD size: CONFIG_SYS_PCI_MMIO_SIZE, 908bd522ceSDave Liu flags: PCI_REGION_MEM 918bd522ceSDave Liu }, 928bd522ceSDave Liu { 936d0f6bcfSJean-Christophe PLAGNIOL-VILLARD bus_start: CONFIG_SYS_PCI_IO_BASE, 946d0f6bcfSJean-Christophe PLAGNIOL-VILLARD phys_start: CONFIG_SYS_PCI_IO_PHYS, 956d0f6bcfSJean-Christophe PLAGNIOL-VILLARD size: CONFIG_SYS_PCI_IO_SIZE, 968bd522ceSDave Liu flags: PCI_REGION_IO 978bd522ceSDave Liu } 988bd522ceSDave Liu }; 998bd522ceSDave Liu 1008f11e34bSAnton Vorontsov static struct pci_region pcie_regions_0[] = { 1018f11e34bSAnton Vorontsov { 1028f11e34bSAnton Vorontsov .bus_start = CONFIG_SYS_PCIE1_MEM_BASE, 1038f11e34bSAnton Vorontsov .phys_start = CONFIG_SYS_PCIE1_MEM_PHYS, 1048f11e34bSAnton Vorontsov .size = CONFIG_SYS_PCIE1_MEM_SIZE, 1058f11e34bSAnton Vorontsov .flags = PCI_REGION_MEM, 1068f11e34bSAnton Vorontsov }, 1078f11e34bSAnton Vorontsov { 1088f11e34bSAnton Vorontsov .bus_start = CONFIG_SYS_PCIE1_IO_BASE, 1098f11e34bSAnton Vorontsov .phys_start = CONFIG_SYS_PCIE1_IO_PHYS, 1108f11e34bSAnton Vorontsov .size = CONFIG_SYS_PCIE1_IO_SIZE, 1118f11e34bSAnton Vorontsov .flags = PCI_REGION_IO, 1128f11e34bSAnton Vorontsov }, 1138f11e34bSAnton Vorontsov }; 1148f11e34bSAnton Vorontsov 1158f11e34bSAnton Vorontsov static struct pci_region pcie_regions_1[] = { 1168f11e34bSAnton Vorontsov { 1178f11e34bSAnton Vorontsov .bus_start = CONFIG_SYS_PCIE2_MEM_BASE, 1188f11e34bSAnton Vorontsov .phys_start = CONFIG_SYS_PCIE2_MEM_PHYS, 1198f11e34bSAnton Vorontsov .size = CONFIG_SYS_PCIE2_MEM_SIZE, 1208f11e34bSAnton Vorontsov .flags = PCI_REGION_MEM, 1218f11e34bSAnton Vorontsov }, 1228f11e34bSAnton Vorontsov { 1238f11e34bSAnton Vorontsov .bus_start = CONFIG_SYS_PCIE2_IO_BASE, 1248f11e34bSAnton Vorontsov .phys_start = CONFIG_SYS_PCIE2_IO_PHYS, 1258f11e34bSAnton Vorontsov .size = CONFIG_SYS_PCIE2_IO_SIZE, 1268f11e34bSAnton Vorontsov .flags = PCI_REGION_IO, 1278f11e34bSAnton Vorontsov }, 1288f11e34bSAnton Vorontsov }; 1298f11e34bSAnton Vorontsov 1308bd522ceSDave Liu void pci_init_board(void) 1318bd522ceSDave Liu { 1326d0f6bcfSJean-Christophe PLAGNIOL-VILLARD volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR; 1338f11e34bSAnton Vorontsov volatile sysconf83xx_t *sysconf = &immr->sysconf; 1348bd522ceSDave Liu volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk; 1358bd522ceSDave Liu volatile law83xx_t *pci_law = immr->sysconf.pcilaw; 1368f11e34bSAnton Vorontsov volatile law83xx_t *pcie_law = sysconf->pcielaw; 1378bd522ceSDave Liu struct pci_region *reg[] = { pci_regions }; 1388f11e34bSAnton Vorontsov struct pci_region *pcie_reg[] = { pcie_regions_0, pcie_regions_1, }; 1398bd522ceSDave Liu int warmboot; 1408bd522ceSDave Liu 1418bd522ceSDave Liu /* Enable all 3 PCI_CLK_OUTPUTs. */ 1428bd522ceSDave Liu clk->occr |= 0xe0000000; 1438bd522ceSDave Liu 1448bd522ceSDave Liu /* 1458bd522ceSDave Liu * Configure PCI Local Access Windows 1468bd522ceSDave Liu */ 1476d0f6bcfSJean-Christophe PLAGNIOL-VILLARD pci_law[0].bar = CONFIG_SYS_PCI_MEM_PHYS & LAWBAR_BAR; 1488bd522ceSDave Liu pci_law[0].ar = LBLAWAR_EN | LBLAWAR_512MB; 1498bd522ceSDave Liu 1506d0f6bcfSJean-Christophe PLAGNIOL-VILLARD pci_law[1].bar = CONFIG_SYS_PCI_IO_PHYS & LAWBAR_BAR; 1518bd522ceSDave Liu pci_law[1].ar = LBLAWAR_EN | LBLAWAR_1MB; 1528bd522ceSDave Liu 1538bd522ceSDave Liu warmboot = gd->bd->bi_bootflags & BOOTFLAG_WARM; 1548bd522ceSDave Liu warmboot |= immr->pmc.pmccr1 & PMCCR1_POWER_OFF; 1558bd522ceSDave Liu 1568bd522ceSDave Liu mpc83xx_pci_init(1, reg, warmboot); 1578f11e34bSAnton Vorontsov 1588f11e34bSAnton Vorontsov /* Configure the clock for PCIE controller */ 1598f11e34bSAnton Vorontsov clrsetbits_be32(&clk->sccr, SCCR_PCIEXP1CM | SCCR_PCIEXP2CM, 1608f11e34bSAnton Vorontsov SCCR_PCIEXP1CM_1 | SCCR_PCIEXP2CM_1); 1618f11e34bSAnton Vorontsov 1628f11e34bSAnton Vorontsov /* Deassert the resets in the control register */ 1638f11e34bSAnton Vorontsov out_be32(&sysconf->pecr1, 0xE0008000); 1648f11e34bSAnton Vorontsov out_be32(&sysconf->pecr2, 0xE0008000); 1658f11e34bSAnton Vorontsov udelay(2000); 1668f11e34bSAnton Vorontsov 1678f11e34bSAnton Vorontsov /* Configure PCI Express Local Access Windows */ 1688f11e34bSAnton Vorontsov out_be32(&pcie_law[0].bar, CONFIG_SYS_PCIE1_BASE & LAWBAR_BAR); 1698f11e34bSAnton Vorontsov out_be32(&pcie_law[0].ar, LBLAWAR_EN | LBLAWAR_512MB); 1708f11e34bSAnton Vorontsov 1718f11e34bSAnton Vorontsov out_be32(&pcie_law[1].bar, CONFIG_SYS_PCIE2_BASE & LAWBAR_BAR); 1728f11e34bSAnton Vorontsov out_be32(&pcie_law[1].ar, LBLAWAR_EN | LBLAWAR_512MB); 1738f11e34bSAnton Vorontsov 1748f11e34bSAnton Vorontsov mpc83xx_pcie_init(2, pcie_reg, warmboot); 1758bd522ceSDave Liu } 1768bd522ceSDave Liu 1778bd522ceSDave Liu #if defined(CONFIG_OF_BOARD_SETUP) 17825f5f0d4SAnton Vorontsov void fdt_tsec1_fixup(void *fdt, bd_t *bd) 17925f5f0d4SAnton Vorontsov { 18025f5f0d4SAnton Vorontsov const char disabled[] = "disabled"; 18125f5f0d4SAnton Vorontsov const char *path; 18225f5f0d4SAnton Vorontsov int ret; 18325f5f0d4SAnton Vorontsov 184*b8b71ffbSAnton Vorontsov if (hwconfig_arg_cmp("board_type", "tsec1")) { 185021f6df6SAnton Vorontsov return; 186*b8b71ffbSAnton Vorontsov } else if (!hwconfig_arg_cmp("board_type", "ulpi")) { 187*b8b71ffbSAnton Vorontsov printf("NOTICE: No or unknown board_type hwconfig specified.\n" 188*b8b71ffbSAnton Vorontsov " Assuming board with TSEC1.\n"); 18925f5f0d4SAnton Vorontsov return; 19025f5f0d4SAnton Vorontsov } 19125f5f0d4SAnton Vorontsov 19225f5f0d4SAnton Vorontsov ret = fdt_path_offset(fdt, "/aliases"); 19325f5f0d4SAnton Vorontsov if (ret < 0) { 19425f5f0d4SAnton Vorontsov printf("WARNING: can't find /aliases node\n"); 19525f5f0d4SAnton Vorontsov return; 19625f5f0d4SAnton Vorontsov } 19725f5f0d4SAnton Vorontsov 19825f5f0d4SAnton Vorontsov path = fdt_getprop(fdt, ret, "ethernet0", NULL); 19925f5f0d4SAnton Vorontsov if (!path) { 20025f5f0d4SAnton Vorontsov printf("WARNING: can't find ethernet0 alias\n"); 20125f5f0d4SAnton Vorontsov return; 20225f5f0d4SAnton Vorontsov } 20325f5f0d4SAnton Vorontsov 20425f5f0d4SAnton Vorontsov do_fixup_by_path(fdt, path, "status", disabled, sizeof(disabled), 1); 20525f5f0d4SAnton Vorontsov } 20625f5f0d4SAnton Vorontsov 2078bd522ceSDave Liu void ft_board_setup(void *blob, bd_t *bd) 2088bd522ceSDave Liu { 2098bd522ceSDave Liu ft_cpu_setup(blob, bd); 2108bd522ceSDave Liu #ifdef CONFIG_PCI 2118bd522ceSDave Liu ft_pci_setup(blob, bd); 2128bd522ceSDave Liu #endif 21325f5f0d4SAnton Vorontsov fdt_fixup_dr_usb(blob, bd); 21425f5f0d4SAnton Vorontsov fdt_tsec1_fixup(blob, bd); 2158bd522ceSDave Liu } 2168bd522ceSDave Liu #endif 21710efa024SBen Warren 21810efa024SBen Warren int board_eth_init(bd_t *bis) 21910efa024SBen Warren { 22010efa024SBen Warren cpu_eth_init(bis); /* Initialize TSECs first */ 22110efa024SBen Warren return pci_eth_init(bis); 22210efa024SBen Warren } 223