119580e66SDave Liu /*
29993e196SKim Phillips * Copyright (C) 2006-2009 Freescale Semiconductor, Inc.
319580e66SDave Liu *
41a459660SWolfgang Denk * SPDX-License-Identifier: GPL-2.0+
519580e66SDave Liu */
619580e66SDave Liu
719580e66SDave Liu #include <asm/mmu.h>
819580e66SDave Liu #include <asm/io.h>
919580e66SDave Liu #include <common.h>
1019580e66SDave Liu #include <mpc83xx.h>
1119580e66SDave Liu #include <pci.h>
1219580e66SDave Liu #include <i2c.h>
138b34557cSAnton Vorontsov #include <fdt_support.h>
1419580e66SDave Liu #include <asm/fsl_i2c.h>
157e1afb62SKumar Gala #include <asm/fsl_mpc83xx_serdes.h>
1619580e66SDave Liu
1719580e66SDave Liu static struct pci_region pci_regions[] = {
1819580e66SDave Liu {
196d0f6bcfSJean-Christophe PLAGNIOL-VILLARD bus_start: CONFIG_SYS_PCI_MEM_BASE,
206d0f6bcfSJean-Christophe PLAGNIOL-VILLARD phys_start: CONFIG_SYS_PCI_MEM_PHYS,
216d0f6bcfSJean-Christophe PLAGNIOL-VILLARD size: CONFIG_SYS_PCI_MEM_SIZE,
2219580e66SDave Liu flags: PCI_REGION_MEM | PCI_REGION_PREFETCH
2319580e66SDave Liu },
2419580e66SDave Liu {
256d0f6bcfSJean-Christophe PLAGNIOL-VILLARD bus_start: CONFIG_SYS_PCI_MMIO_BASE,
266d0f6bcfSJean-Christophe PLAGNIOL-VILLARD phys_start: CONFIG_SYS_PCI_MMIO_PHYS,
276d0f6bcfSJean-Christophe PLAGNIOL-VILLARD size: CONFIG_SYS_PCI_MMIO_SIZE,
2819580e66SDave Liu flags: PCI_REGION_MEM
2919580e66SDave Liu },
3019580e66SDave Liu {
316d0f6bcfSJean-Christophe PLAGNIOL-VILLARD bus_start: CONFIG_SYS_PCI_IO_BASE,
326d0f6bcfSJean-Christophe PLAGNIOL-VILLARD phys_start: CONFIG_SYS_PCI_IO_PHYS,
336d0f6bcfSJean-Christophe PLAGNIOL-VILLARD size: CONFIG_SYS_PCI_IO_SIZE,
3419580e66SDave Liu flags: PCI_REGION_IO
3519580e66SDave Liu }
3619580e66SDave Liu };
3719580e66SDave Liu
388b34557cSAnton Vorontsov static struct pci_region pcie_regions_0[] = {
398b34557cSAnton Vorontsov {
408b34557cSAnton Vorontsov .bus_start = CONFIG_SYS_PCIE1_MEM_BASE,
418b34557cSAnton Vorontsov .phys_start = CONFIG_SYS_PCIE1_MEM_PHYS,
428b34557cSAnton Vorontsov .size = CONFIG_SYS_PCIE1_MEM_SIZE,
438b34557cSAnton Vorontsov .flags = PCI_REGION_MEM,
448b34557cSAnton Vorontsov },
458b34557cSAnton Vorontsov {
468b34557cSAnton Vorontsov .bus_start = CONFIG_SYS_PCIE1_IO_BASE,
478b34557cSAnton Vorontsov .phys_start = CONFIG_SYS_PCIE1_IO_PHYS,
488b34557cSAnton Vorontsov .size = CONFIG_SYS_PCIE1_IO_SIZE,
498b34557cSAnton Vorontsov .flags = PCI_REGION_IO,
508b34557cSAnton Vorontsov },
518b34557cSAnton Vorontsov };
528b34557cSAnton Vorontsov
538b34557cSAnton Vorontsov static struct pci_region pcie_regions_1[] = {
548b34557cSAnton Vorontsov {
558b34557cSAnton Vorontsov .bus_start = CONFIG_SYS_PCIE2_MEM_BASE,
568b34557cSAnton Vorontsov .phys_start = CONFIG_SYS_PCIE2_MEM_PHYS,
578b34557cSAnton Vorontsov .size = CONFIG_SYS_PCIE2_MEM_SIZE,
588b34557cSAnton Vorontsov .flags = PCI_REGION_MEM,
598b34557cSAnton Vorontsov },
608b34557cSAnton Vorontsov {
618b34557cSAnton Vorontsov .bus_start = CONFIG_SYS_PCIE2_IO_BASE,
628b34557cSAnton Vorontsov .phys_start = CONFIG_SYS_PCIE2_IO_PHYS,
638b34557cSAnton Vorontsov .size = CONFIG_SYS_PCIE2_IO_SIZE,
648b34557cSAnton Vorontsov .flags = PCI_REGION_IO,
658b34557cSAnton Vorontsov },
668b34557cSAnton Vorontsov };
678b34557cSAnton Vorontsov
is_pex_x2(void)688b34557cSAnton Vorontsov static int is_pex_x2(void)
698b34557cSAnton Vorontsov {
70*00caae6dSSimon Glass const char *pex_x2 = env_get("pex_x2");
718b34557cSAnton Vorontsov
728b34557cSAnton Vorontsov if (pex_x2 && !strcmp(pex_x2, "yes"))
738b34557cSAnton Vorontsov return 1;
748b34557cSAnton Vorontsov return 0;
758b34557cSAnton Vorontsov }
768b34557cSAnton Vorontsov
pci_init_board(void)7719580e66SDave Liu void pci_init_board(void)
7819580e66SDave Liu {
796d0f6bcfSJean-Christophe PLAGNIOL-VILLARD volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR;
808b34557cSAnton Vorontsov volatile sysconf83xx_t *sysconf = &immr->sysconf;
8119580e66SDave Liu volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk;
8219580e66SDave Liu volatile law83xx_t *pci_law = immr->sysconf.pcilaw;
838b34557cSAnton Vorontsov volatile law83xx_t *pcie_law = sysconf->pcielaw;
8419580e66SDave Liu struct pci_region *reg[] = { pci_regions };
858b34557cSAnton Vorontsov struct pci_region *pcie_reg[] = { pcie_regions_0, pcie_regions_1, };
868b34557cSAnton Vorontsov u32 spridr = in_be32(&immr->sysconf.spridr);
878b34557cSAnton Vorontsov int pex2 = is_pex_x2();
8819580e66SDave Liu
8900f7bbaeSAnton Vorontsov if (board_pci_host_broken())
908b34557cSAnton Vorontsov goto skip_pci;
9100f7bbaeSAnton Vorontsov
9219580e66SDave Liu /* Enable all 5 PCI_CLK_OUTPUTS */
9319580e66SDave Liu clk->occr |= 0xf8000000;
9419580e66SDave Liu udelay(2000);
9519580e66SDave Liu
9619580e66SDave Liu /* Configure PCI Local Access Windows */
976d0f6bcfSJean-Christophe PLAGNIOL-VILLARD pci_law[0].bar = CONFIG_SYS_PCI_MEM_PHYS & LAWBAR_BAR;
9819580e66SDave Liu pci_law[0].ar = LBLAWAR_EN | LBLAWAR_512MB;
9919580e66SDave Liu
1006d0f6bcfSJean-Christophe PLAGNIOL-VILLARD pci_law[1].bar = CONFIG_SYS_PCI_IO_PHYS & LAWBAR_BAR;
10119580e66SDave Liu pci_law[1].ar = LBLAWAR_EN | LBLAWAR_1MB;
10219580e66SDave Liu
10319580e66SDave Liu udelay(2000);
10419580e66SDave Liu
1056aa3d3bfSPeter Tyser mpc83xx_pci_init(1, reg);
1068b34557cSAnton Vorontsov skip_pci:
1078b34557cSAnton Vorontsov /* There is no PEX in MPC8379 parts. */
1088b34557cSAnton Vorontsov if (PARTID_NO_E(spridr) == SPR_8379)
1098b34557cSAnton Vorontsov return;
1108b34557cSAnton Vorontsov
1117e2ec1deSAnton Vorontsov if (pex2)
1127e2ec1deSAnton Vorontsov fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_PEX_X2,
1137e2ec1deSAnton Vorontsov FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
1147e2ec1deSAnton Vorontsov else
1157e2ec1deSAnton Vorontsov fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_PEX,
1167e2ec1deSAnton Vorontsov FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
1177e2ec1deSAnton Vorontsov
1188b34557cSAnton Vorontsov /* Configure the clock for PCIE controller */
1198b34557cSAnton Vorontsov clrsetbits_be32(&clk->sccr, SCCR_PCIEXP1CM | SCCR_PCIEXP2CM,
1208b34557cSAnton Vorontsov SCCR_PCIEXP1CM_1 | SCCR_PCIEXP2CM_1);
1218b34557cSAnton Vorontsov
1228b34557cSAnton Vorontsov /* Deassert the resets in the control register */
1238b34557cSAnton Vorontsov out_be32(&sysconf->pecr1, 0xE0008000);
1248b34557cSAnton Vorontsov if (!pex2)
1258b34557cSAnton Vorontsov out_be32(&sysconf->pecr2, 0xE0008000);
1268b34557cSAnton Vorontsov udelay(2000);
1278b34557cSAnton Vorontsov
1288b34557cSAnton Vorontsov /* Configure PCI Express Local Access Windows */
1298b34557cSAnton Vorontsov out_be32(&pcie_law[0].bar, CONFIG_SYS_PCIE1_BASE & LAWBAR_BAR);
1308b34557cSAnton Vorontsov out_be32(&pcie_law[0].ar, LBLAWAR_EN | LBLAWAR_512MB);
1318b34557cSAnton Vorontsov
1328b34557cSAnton Vorontsov out_be32(&pcie_law[1].bar, CONFIG_SYS_PCIE2_BASE & LAWBAR_BAR);
1338b34557cSAnton Vorontsov out_be32(&pcie_law[1].ar, LBLAWAR_EN | LBLAWAR_512MB);
1348b34557cSAnton Vorontsov
135e2229352SKim Phillips mpc83xx_pcie_init(pex2 ? 1 : 2, pcie_reg);
1368b34557cSAnton Vorontsov }
1378b34557cSAnton Vorontsov
ft_pcie_fixup(void * blob,bd_t * bd)1388b34557cSAnton Vorontsov void ft_pcie_fixup(void *blob, bd_t *bd)
1398b34557cSAnton Vorontsov {
1408b34557cSAnton Vorontsov const char *status = "disabled (PCIE1 is x2)";
1418b34557cSAnton Vorontsov
1428b34557cSAnton Vorontsov if (!is_pex_x2())
1438b34557cSAnton Vorontsov return;
1448b34557cSAnton Vorontsov
1458b34557cSAnton Vorontsov do_fixup_by_path(blob, "pci2", "status", status,
1468b34557cSAnton Vorontsov strlen(status) + 1, 1);
14719580e66SDave Liu }
148