blob: 38954587aba892dcf80b5e5e2a5c5675d6061170 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Kim Phillips5e918a92008-01-16 00:38:05 -06002/*
Kim Phillips9993e192009-07-18 18:42:13 -05003 * Copyright (C) 2006-2009 Freescale Semiconductor, Inc.
Kim Phillips5e918a92008-01-16 00:38:05 -06004 */
5
6#include <common.h>
7#include <mpc83xx.h>
8#include <pci.h>
Anton Vorontsov7e915582009-02-19 18:20:52 +03009#include <asm/io.h>
Kim Phillips5e918a92008-01-16 00:38:05 -060010
Kim Phillips5e918a92008-01-16 00:38:05 -060011static struct pci_region pci_regions[] = {
12 {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020013 bus_start: CONFIG_SYS_PCI_MEM_BASE,
14 phys_start: CONFIG_SYS_PCI_MEM_PHYS,
15 size: CONFIG_SYS_PCI_MEM_SIZE,
Kim Phillips5e918a92008-01-16 00:38:05 -060016 flags: PCI_REGION_MEM | PCI_REGION_PREFETCH
17 },
18 {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020019 bus_start: CONFIG_SYS_PCI_MMIO_BASE,
20 phys_start: CONFIG_SYS_PCI_MMIO_PHYS,
21 size: CONFIG_SYS_PCI_MMIO_SIZE,
Kim Phillips5e918a92008-01-16 00:38:05 -060022 flags: PCI_REGION_MEM
23 },
24 {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020025 bus_start: CONFIG_SYS_PCI_IO_BASE,
26 phys_start: CONFIG_SYS_PCI_IO_PHYS,
27 size: CONFIG_SYS_PCI_IO_SIZE,
Kim Phillips5e918a92008-01-16 00:38:05 -060028 flags: PCI_REGION_IO
29 }
30};
31
Anton Vorontsov7e915582009-02-19 18:20:52 +030032static struct pci_region pcie_regions_0[] = {
33 {
34 .bus_start = CONFIG_SYS_PCIE1_MEM_BASE,
35 .phys_start = CONFIG_SYS_PCIE1_MEM_PHYS,
36 .size = CONFIG_SYS_PCIE1_MEM_SIZE,
37 .flags = PCI_REGION_MEM,
38 },
39 {
40 .bus_start = CONFIG_SYS_PCIE1_IO_BASE,
41 .phys_start = CONFIG_SYS_PCIE1_IO_PHYS,
42 .size = CONFIG_SYS_PCIE1_IO_SIZE,
43 .flags = PCI_REGION_IO,
44 },
45};
46
47static struct pci_region pcie_regions_1[] = {
48 {
49 .bus_start = CONFIG_SYS_PCIE2_MEM_BASE,
50 .phys_start = CONFIG_SYS_PCIE2_MEM_PHYS,
51 .size = CONFIG_SYS_PCIE2_MEM_SIZE,
52 .flags = PCI_REGION_MEM,
53 },
54 {
55 .bus_start = CONFIG_SYS_PCIE2_IO_BASE,
56 .phys_start = CONFIG_SYS_PCIE2_IO_PHYS,
57 .size = CONFIG_SYS_PCIE2_IO_SIZE,
58 .flags = PCI_REGION_IO,
59 },
60};
61
Kim Phillips5e918a92008-01-16 00:38:05 -060062void pci_init_board(void)
63{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020064 volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR;
Anton Vorontsov7e915582009-02-19 18:20:52 +030065 volatile sysconf83xx_t *sysconf = &immr->sysconf;
Kim Phillips5e918a92008-01-16 00:38:05 -060066 volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk;
67 volatile law83xx_t *pci_law = immr->sysconf.pcilaw;
Anton Vorontsov7e915582009-02-19 18:20:52 +030068 volatile law83xx_t *pcie_law = sysconf->pcielaw;
Kim Phillips5e918a92008-01-16 00:38:05 -060069 struct pci_region *reg[] = { pci_regions };
Anton Vorontsov7e915582009-02-19 18:20:52 +030070 struct pci_region *pcie_reg[] = { pcie_regions_0, pcie_regions_1, };
71 u32 spridr = in_be32(&immr->sysconf.spridr);
Kim Phillips5e918a92008-01-16 00:38:05 -060072
73 /* Enable all 5 PCI_CLK_OUTPUTS */
74 clk->occr |= 0xf8000000;
75 udelay(2000);
76
77 /* Configure PCI Local Access Windows */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020078 pci_law[0].bar = CONFIG_SYS_PCI_MEM_PHYS & LAWBAR_BAR;
Kim Phillips5e918a92008-01-16 00:38:05 -060079 pci_law[0].ar = LBLAWAR_EN | LBLAWAR_512MB;
80
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020081 pci_law[1].bar = CONFIG_SYS_PCI_IO_PHYS & LAWBAR_BAR;
Kim Phillips5e918a92008-01-16 00:38:05 -060082 pci_law[1].ar = LBLAWAR_EN | LBLAWAR_1MB;
83
Peter Tyser6aa3d3b2010-09-14 19:13:50 -050084 mpc83xx_pci_init(1, reg);
Anton Vorontsov7e915582009-02-19 18:20:52 +030085
86 /* There is no PEX in MPC8379 parts. */
87 if (PARTID_NO_E(spridr) == SPR_8379)
88 return;
89
90 /* Configure the clock for PCIE controller */
91 clrsetbits_be32(&clk->sccr, SCCR_PCIEXP1CM | SCCR_PCIEXP2CM,
92 SCCR_PCIEXP1CM_1 | SCCR_PCIEXP2CM_1);
93
94 /* Deassert the resets in the control register */
95 out_be32(&sysconf->pecr1, 0xE0008000);
96 out_be32(&sysconf->pecr2, 0xE0008000);
97 udelay(2000);
98
99 /* Configure PCI Express Local Access Windows */
100 out_be32(&pcie_law[0].bar, CONFIG_SYS_PCIE1_BASE & LAWBAR_BAR);
101 out_be32(&pcie_law[0].ar, LBLAWAR_EN | LBLAWAR_512MB);
102
103 out_be32(&pcie_law[1].bar, CONFIG_SYS_PCIE2_BASE & LAWBAR_BAR);
104 out_be32(&pcie_law[1].ar, LBLAWAR_EN | LBLAWAR_512MB);
105
Peter Tyser6aa3d3b2010-09-14 19:13:50 -0500106 mpc83xx_pcie_init(2, pcie_reg);
Kim Phillips5e918a92008-01-16 00:38:05 -0600107}