blob: 8f50c9366e3ca25a984fc5650fab0dd3e944679f [file] [log] [blame]
Kim Phillips5e918a92008-01-16 00:38:05 -06001/*
Kim Phillips9993e192009-07-18 18:42:13 -05002 * Copyright (C) 2006-2009 Freescale Semiconductor, Inc.
Kim Phillips5e918a92008-01-16 00:38:05 -06003 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Kim Phillips5e918a92008-01-16 00:38:05 -06005 */
6
7#include <common.h>
8#include <mpc83xx.h>
9#include <pci.h>
Anton Vorontsov7e915582009-02-19 18:20:52 +030010#include <asm/io.h>
Kim Phillips5e918a92008-01-16 00:38:05 -060011
Kim Phillips5e918a92008-01-16 00:38:05 -060012static struct pci_region pci_regions[] = {
13 {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020014 bus_start: CONFIG_SYS_PCI_MEM_BASE,
15 phys_start: CONFIG_SYS_PCI_MEM_PHYS,
16 size: CONFIG_SYS_PCI_MEM_SIZE,
Kim Phillips5e918a92008-01-16 00:38:05 -060017 flags: PCI_REGION_MEM | PCI_REGION_PREFETCH
18 },
19 {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020020 bus_start: CONFIG_SYS_PCI_MMIO_BASE,
21 phys_start: CONFIG_SYS_PCI_MMIO_PHYS,
22 size: CONFIG_SYS_PCI_MMIO_SIZE,
Kim Phillips5e918a92008-01-16 00:38:05 -060023 flags: PCI_REGION_MEM
24 },
25 {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020026 bus_start: CONFIG_SYS_PCI_IO_BASE,
27 phys_start: CONFIG_SYS_PCI_IO_PHYS,
28 size: CONFIG_SYS_PCI_IO_SIZE,
Kim Phillips5e918a92008-01-16 00:38:05 -060029 flags: PCI_REGION_IO
30 }
31};
32
Anton Vorontsov7e915582009-02-19 18:20:52 +030033static struct pci_region pcie_regions_0[] = {
34 {
35 .bus_start = CONFIG_SYS_PCIE1_MEM_BASE,
36 .phys_start = CONFIG_SYS_PCIE1_MEM_PHYS,
37 .size = CONFIG_SYS_PCIE1_MEM_SIZE,
38 .flags = PCI_REGION_MEM,
39 },
40 {
41 .bus_start = CONFIG_SYS_PCIE1_IO_BASE,
42 .phys_start = CONFIG_SYS_PCIE1_IO_PHYS,
43 .size = CONFIG_SYS_PCIE1_IO_SIZE,
44 .flags = PCI_REGION_IO,
45 },
46};
47
48static struct pci_region pcie_regions_1[] = {
49 {
50 .bus_start = CONFIG_SYS_PCIE2_MEM_BASE,
51 .phys_start = CONFIG_SYS_PCIE2_MEM_PHYS,
52 .size = CONFIG_SYS_PCIE2_MEM_SIZE,
53 .flags = PCI_REGION_MEM,
54 },
55 {
56 .bus_start = CONFIG_SYS_PCIE2_IO_BASE,
57 .phys_start = CONFIG_SYS_PCIE2_IO_PHYS,
58 .size = CONFIG_SYS_PCIE2_IO_SIZE,
59 .flags = PCI_REGION_IO,
60 },
61};
62
Kim Phillips5e918a92008-01-16 00:38:05 -060063void pci_init_board(void)
64{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020065 volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR;
Anton Vorontsov7e915582009-02-19 18:20:52 +030066 volatile sysconf83xx_t *sysconf = &immr->sysconf;
Kim Phillips5e918a92008-01-16 00:38:05 -060067 volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk;
68 volatile law83xx_t *pci_law = immr->sysconf.pcilaw;
Anton Vorontsov7e915582009-02-19 18:20:52 +030069 volatile law83xx_t *pcie_law = sysconf->pcielaw;
Kim Phillips5e918a92008-01-16 00:38:05 -060070 struct pci_region *reg[] = { pci_regions };
Anton Vorontsov7e915582009-02-19 18:20:52 +030071 struct pci_region *pcie_reg[] = { pcie_regions_0, pcie_regions_1, };
72 u32 spridr = in_be32(&immr->sysconf.spridr);
Kim Phillips5e918a92008-01-16 00:38:05 -060073
74 /* Enable all 5 PCI_CLK_OUTPUTS */
75 clk->occr |= 0xf8000000;
76 udelay(2000);
77
78 /* Configure PCI Local Access Windows */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020079 pci_law[0].bar = CONFIG_SYS_PCI_MEM_PHYS & LAWBAR_BAR;
Kim Phillips5e918a92008-01-16 00:38:05 -060080 pci_law[0].ar = LBLAWAR_EN | LBLAWAR_512MB;
81
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020082 pci_law[1].bar = CONFIG_SYS_PCI_IO_PHYS & LAWBAR_BAR;
Kim Phillips5e918a92008-01-16 00:38:05 -060083 pci_law[1].ar = LBLAWAR_EN | LBLAWAR_1MB;
84
Peter Tyser6aa3d3b2010-09-14 19:13:50 -050085 mpc83xx_pci_init(1, reg);
Anton Vorontsov7e915582009-02-19 18:20:52 +030086
87 /* There is no PEX in MPC8379 parts. */
88 if (PARTID_NO_E(spridr) == SPR_8379)
89 return;
90
91 /* Configure the clock for PCIE controller */
92 clrsetbits_be32(&clk->sccr, SCCR_PCIEXP1CM | SCCR_PCIEXP2CM,
93 SCCR_PCIEXP1CM_1 | SCCR_PCIEXP2CM_1);
94
95 /* Deassert the resets in the control register */
96 out_be32(&sysconf->pecr1, 0xE0008000);
97 out_be32(&sysconf->pecr2, 0xE0008000);
98 udelay(2000);
99
100 /* Configure PCI Express Local Access Windows */
101 out_be32(&pcie_law[0].bar, CONFIG_SYS_PCIE1_BASE & LAWBAR_BAR);
102 out_be32(&pcie_law[0].ar, LBLAWAR_EN | LBLAWAR_512MB);
103
104 out_be32(&pcie_law[1].bar, CONFIG_SYS_PCIE2_BASE & LAWBAR_BAR);
105 out_be32(&pcie_law[1].ar, LBLAWAR_EN | LBLAWAR_512MB);
106
Peter Tyser6aa3d3b2010-09-14 19:13:50 -0500107 mpc83xx_pcie_init(2, pcie_reg);
Kim Phillips5e918a92008-01-16 00:38:05 -0600108}