119580e66SDave Liu /* 219580e66SDave Liu * Copyright (C) 2007 Freescale Semiconductor, Inc. 319580e66SDave Liu * 419580e66SDave Liu * See file CREDITS for list of people who contributed to this 519580e66SDave Liu * project. 619580e66SDave Liu * 719580e66SDave Liu * This program is free software; you can redistribute it and/or 819580e66SDave Liu * modify it under the terms of the GNU General Public License as 919580e66SDave Liu * published by the Free Software Foundation; either version 2 of 1019580e66SDave Liu * the License, or (at your option) any later version. 1119580e66SDave Liu */ 1219580e66SDave Liu 1319580e66SDave Liu #include <asm/mmu.h> 1419580e66SDave Liu #include <asm/io.h> 1519580e66SDave Liu #include <common.h> 1619580e66SDave Liu #include <mpc83xx.h> 1719580e66SDave Liu #include <pci.h> 1819580e66SDave Liu #include <i2c.h> 198b34557cSAnton Vorontsov #include <fdt_support.h> 2019580e66SDave Liu #include <asm/fsl_i2c.h> 218b34557cSAnton Vorontsov #include <asm/fsl_serdes.h> 2219580e66SDave Liu 2319580e66SDave Liu #if defined(CONFIG_PCI) 2419580e66SDave Liu static struct pci_region pci_regions[] = { 2519580e66SDave Liu { 266d0f6bcfSJean-Christophe PLAGNIOL-VILLARD bus_start: CONFIG_SYS_PCI_MEM_BASE, 276d0f6bcfSJean-Christophe PLAGNIOL-VILLARD phys_start: CONFIG_SYS_PCI_MEM_PHYS, 286d0f6bcfSJean-Christophe PLAGNIOL-VILLARD size: CONFIG_SYS_PCI_MEM_SIZE, 2919580e66SDave Liu flags: PCI_REGION_MEM | PCI_REGION_PREFETCH 3019580e66SDave Liu }, 3119580e66SDave Liu { 326d0f6bcfSJean-Christophe PLAGNIOL-VILLARD bus_start: CONFIG_SYS_PCI_MMIO_BASE, 336d0f6bcfSJean-Christophe PLAGNIOL-VILLARD phys_start: CONFIG_SYS_PCI_MMIO_PHYS, 346d0f6bcfSJean-Christophe PLAGNIOL-VILLARD size: CONFIG_SYS_PCI_MMIO_SIZE, 3519580e66SDave Liu flags: PCI_REGION_MEM 3619580e66SDave Liu }, 3719580e66SDave Liu { 386d0f6bcfSJean-Christophe PLAGNIOL-VILLARD bus_start: CONFIG_SYS_PCI_IO_BASE, 396d0f6bcfSJean-Christophe PLAGNIOL-VILLARD phys_start: CONFIG_SYS_PCI_IO_PHYS, 406d0f6bcfSJean-Christophe PLAGNIOL-VILLARD size: CONFIG_SYS_PCI_IO_SIZE, 4119580e66SDave Liu flags: PCI_REGION_IO 4219580e66SDave Liu } 4319580e66SDave Liu }; 4419580e66SDave Liu 458b34557cSAnton Vorontsov static struct pci_region pcie_regions_0[] = { 468b34557cSAnton Vorontsov { 478b34557cSAnton Vorontsov .bus_start = CONFIG_SYS_PCIE1_MEM_BASE, 488b34557cSAnton Vorontsov .phys_start = CONFIG_SYS_PCIE1_MEM_PHYS, 498b34557cSAnton Vorontsov .size = CONFIG_SYS_PCIE1_MEM_SIZE, 508b34557cSAnton Vorontsov .flags = PCI_REGION_MEM, 518b34557cSAnton Vorontsov }, 528b34557cSAnton Vorontsov { 538b34557cSAnton Vorontsov .bus_start = CONFIG_SYS_PCIE1_IO_BASE, 548b34557cSAnton Vorontsov .phys_start = CONFIG_SYS_PCIE1_IO_PHYS, 558b34557cSAnton Vorontsov .size = CONFIG_SYS_PCIE1_IO_SIZE, 568b34557cSAnton Vorontsov .flags = PCI_REGION_IO, 578b34557cSAnton Vorontsov }, 588b34557cSAnton Vorontsov }; 598b34557cSAnton Vorontsov 608b34557cSAnton Vorontsov static struct pci_region pcie_regions_1[] = { 618b34557cSAnton Vorontsov { 628b34557cSAnton Vorontsov .bus_start = CONFIG_SYS_PCIE2_MEM_BASE, 638b34557cSAnton Vorontsov .phys_start = CONFIG_SYS_PCIE2_MEM_PHYS, 648b34557cSAnton Vorontsov .size = CONFIG_SYS_PCIE2_MEM_SIZE, 658b34557cSAnton Vorontsov .flags = PCI_REGION_MEM, 668b34557cSAnton Vorontsov }, 678b34557cSAnton Vorontsov { 688b34557cSAnton Vorontsov .bus_start = CONFIG_SYS_PCIE2_IO_BASE, 698b34557cSAnton Vorontsov .phys_start = CONFIG_SYS_PCIE2_IO_PHYS, 708b34557cSAnton Vorontsov .size = CONFIG_SYS_PCIE2_IO_SIZE, 718b34557cSAnton Vorontsov .flags = PCI_REGION_IO, 728b34557cSAnton Vorontsov }, 738b34557cSAnton Vorontsov }; 748b34557cSAnton Vorontsov 758b34557cSAnton Vorontsov static int is_pex_x2(void) 768b34557cSAnton Vorontsov { 778b34557cSAnton Vorontsov const char *pex_x2 = getenv("pex_x2"); 788b34557cSAnton Vorontsov 798b34557cSAnton Vorontsov if (pex_x2 && !strcmp(pex_x2, "yes")) 808b34557cSAnton Vorontsov return 1; 818b34557cSAnton Vorontsov return 0; 828b34557cSAnton Vorontsov } 838b34557cSAnton Vorontsov 8419580e66SDave Liu void pci_init_board(void) 8519580e66SDave Liu { 866d0f6bcfSJean-Christophe PLAGNIOL-VILLARD volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR; 878b34557cSAnton Vorontsov volatile sysconf83xx_t *sysconf = &immr->sysconf; 8819580e66SDave Liu volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk; 8919580e66SDave Liu volatile law83xx_t *pci_law = immr->sysconf.pcilaw; 908b34557cSAnton Vorontsov volatile law83xx_t *pcie_law = sysconf->pcielaw; 9119580e66SDave Liu struct pci_region *reg[] = { pci_regions }; 928b34557cSAnton Vorontsov struct pci_region *pcie_reg[] = { pcie_regions_0, pcie_regions_1, }; 938b34557cSAnton Vorontsov u32 spridr = in_be32(&immr->sysconf.spridr); 948b34557cSAnton Vorontsov int pex2 = is_pex_x2(); 9519580e66SDave Liu 9600f7bbaeSAnton Vorontsov if (board_pci_host_broken()) 978b34557cSAnton Vorontsov goto skip_pci; 9800f7bbaeSAnton Vorontsov 9919580e66SDave Liu /* Enable all 5 PCI_CLK_OUTPUTS */ 10019580e66SDave Liu clk->occr |= 0xf8000000; 10119580e66SDave Liu udelay(2000); 10219580e66SDave Liu 10319580e66SDave Liu /* Configure PCI Local Access Windows */ 1046d0f6bcfSJean-Christophe PLAGNIOL-VILLARD pci_law[0].bar = CONFIG_SYS_PCI_MEM_PHYS & LAWBAR_BAR; 10519580e66SDave Liu pci_law[0].ar = LBLAWAR_EN | LBLAWAR_512MB; 10619580e66SDave Liu 1076d0f6bcfSJean-Christophe PLAGNIOL-VILLARD pci_law[1].bar = CONFIG_SYS_PCI_IO_PHYS & LAWBAR_BAR; 10819580e66SDave Liu pci_law[1].ar = LBLAWAR_EN | LBLAWAR_1MB; 10919580e66SDave Liu 11019580e66SDave Liu udelay(2000); 11119580e66SDave Liu 11219580e66SDave Liu mpc83xx_pci_init(1, reg, 0); 1138b34557cSAnton Vorontsov skip_pci: 1148b34557cSAnton Vorontsov /* There is no PEX in MPC8379 parts. */ 1158b34557cSAnton Vorontsov if (PARTID_NO_E(spridr) == SPR_8379) 1168b34557cSAnton Vorontsov return; 1178b34557cSAnton Vorontsov 118*7e2ec1deSAnton Vorontsov if (pex2) 119*7e2ec1deSAnton Vorontsov fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_PEX_X2, 120*7e2ec1deSAnton Vorontsov FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V); 121*7e2ec1deSAnton Vorontsov else 122*7e2ec1deSAnton Vorontsov fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_PEX, 123*7e2ec1deSAnton Vorontsov FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V); 124*7e2ec1deSAnton Vorontsov 1258b34557cSAnton Vorontsov /* Configure the clock for PCIE controller */ 1268b34557cSAnton Vorontsov clrsetbits_be32(&clk->sccr, SCCR_PCIEXP1CM | SCCR_PCIEXP2CM, 1278b34557cSAnton Vorontsov SCCR_PCIEXP1CM_1 | SCCR_PCIEXP2CM_1); 1288b34557cSAnton Vorontsov 1298b34557cSAnton Vorontsov /* Deassert the resets in the control register */ 1308b34557cSAnton Vorontsov out_be32(&sysconf->pecr1, 0xE0008000); 1318b34557cSAnton Vorontsov if (!pex2) 1328b34557cSAnton Vorontsov out_be32(&sysconf->pecr2, 0xE0008000); 1338b34557cSAnton Vorontsov udelay(2000); 1348b34557cSAnton Vorontsov 1358b34557cSAnton Vorontsov /* Configure PCI Express Local Access Windows */ 1368b34557cSAnton Vorontsov out_be32(&pcie_law[0].bar, CONFIG_SYS_PCIE1_BASE & LAWBAR_BAR); 1378b34557cSAnton Vorontsov out_be32(&pcie_law[0].ar, LBLAWAR_EN | LBLAWAR_512MB); 1388b34557cSAnton Vorontsov 1398b34557cSAnton Vorontsov out_be32(&pcie_law[1].bar, CONFIG_SYS_PCIE2_BASE & LAWBAR_BAR); 1408b34557cSAnton Vorontsov out_be32(&pcie_law[1].ar, LBLAWAR_EN | LBLAWAR_512MB); 1418b34557cSAnton Vorontsov 1428b34557cSAnton Vorontsov mpc83xx_pcie_init(pex2 ? 1 : 2, pcie_reg, 0); 1438b34557cSAnton Vorontsov } 1448b34557cSAnton Vorontsov 1458b34557cSAnton Vorontsov void ft_pcie_fixup(void *blob, bd_t *bd) 1468b34557cSAnton Vorontsov { 1478b34557cSAnton Vorontsov const char *status = "disabled (PCIE1 is x2)"; 1488b34557cSAnton Vorontsov 1498b34557cSAnton Vorontsov if (!is_pex_x2()) 1508b34557cSAnton Vorontsov return; 1518b34557cSAnton Vorontsov 1528b34557cSAnton Vorontsov do_fixup_by_path(blob, "pci2", "status", status, 1538b34557cSAnton Vorontsov strlen(status) + 1, 1); 15419580e66SDave Liu } 15519580e66SDave Liu #endif /* CONFIG_PCI */ 156