blob: 83e89cf2ecc996f154b6b2108428c10f74e5bde0 [file] [log] [blame]
Kim Phillips1cb07e62008-01-16 00:38:05 -06001/*
2 * Copyright (C) 2007 Freescale Semiconductor, Inc.
3 *
4 * See file CREDITS for list of people who contributed to this
5 * project.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 */
12
13#include <common.h>
14#include <mpc83xx.h>
15#include <pci.h>
Anton Vorontsov45a30ee2009-02-19 18:20:52 +030016#include <asm/io.h>
Kim Phillips1cb07e62008-01-16 00:38:05 -060017
18#if defined(CONFIG_PCI)
19static struct pci_region pci_regions[] = {
20 {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020021 bus_start: CONFIG_SYS_PCI_MEM_BASE,
22 phys_start: CONFIG_SYS_PCI_MEM_PHYS,
23 size: CONFIG_SYS_PCI_MEM_SIZE,
Kim Phillips1cb07e62008-01-16 00:38:05 -060024 flags: PCI_REGION_MEM | PCI_REGION_PREFETCH
25 },
26 {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020027 bus_start: CONFIG_SYS_PCI_MMIO_BASE,
28 phys_start: CONFIG_SYS_PCI_MMIO_PHYS,
29 size: CONFIG_SYS_PCI_MMIO_SIZE,
Kim Phillips1cb07e62008-01-16 00:38:05 -060030 flags: PCI_REGION_MEM
31 },
32 {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020033 bus_start: CONFIG_SYS_PCI_IO_BASE,
34 phys_start: CONFIG_SYS_PCI_IO_PHYS,
35 size: CONFIG_SYS_PCI_IO_SIZE,
Kim Phillips1cb07e62008-01-16 00:38:05 -060036 flags: PCI_REGION_IO
37 }
38};
39
Anton Vorontsov45a30ee2009-02-19 18:20:52 +030040static struct pci_region pcie_regions_0[] = {
41 {
42 .bus_start = CONFIG_SYS_PCIE1_MEM_BASE,
43 .phys_start = CONFIG_SYS_PCIE1_MEM_PHYS,
44 .size = CONFIG_SYS_PCIE1_MEM_SIZE,
45 .flags = PCI_REGION_MEM,
46 },
47 {
48 .bus_start = CONFIG_SYS_PCIE1_IO_BASE,
49 .phys_start = CONFIG_SYS_PCIE1_IO_PHYS,
50 .size = CONFIG_SYS_PCIE1_IO_SIZE,
51 .flags = PCI_REGION_IO,
52 },
53};
54
55static struct pci_region pcie_regions_1[] = {
56 {
57 .bus_start = CONFIG_SYS_PCIE2_MEM_BASE,
58 .phys_start = CONFIG_SYS_PCIE2_MEM_PHYS,
59 .size = CONFIG_SYS_PCIE2_MEM_SIZE,
60 .flags = PCI_REGION_MEM,
61 },
62 {
63 .bus_start = CONFIG_SYS_PCIE2_IO_BASE,
64 .phys_start = CONFIG_SYS_PCIE2_IO_PHYS,
65 .size = CONFIG_SYS_PCIE2_IO_SIZE,
66 .flags = PCI_REGION_IO,
67 },
68};
69
Kim Phillips1cb07e62008-01-16 00:38:05 -060070void pci_init_board(void)
71{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020072 volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR;
Anton Vorontsov45a30ee2009-02-19 18:20:52 +030073 volatile sysconf83xx_t *sysconf = &immr->sysconf;
Kim Phillips1cb07e62008-01-16 00:38:05 -060074 volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk;
75 volatile law83xx_t *pci_law = immr->sysconf.pcilaw;
Anton Vorontsov45a30ee2009-02-19 18:20:52 +030076 volatile law83xx_t *pcie_law = sysconf->pcielaw;
Kim Phillips1cb07e62008-01-16 00:38:05 -060077 struct pci_region *reg[] = { pci_regions };
Anton Vorontsov45a30ee2009-02-19 18:20:52 +030078 struct pci_region *pcie_reg[] = { pcie_regions_0, pcie_regions_1, };
79 u32 spridr = in_be32(&immr->sysconf.spridr);
Kim Phillips1cb07e62008-01-16 00:38:05 -060080
81 /* Enable all 5 PCI_CLK_OUTPUTS */
82 clk->occr |= 0xf8000000;
83 udelay(2000);
84
85 /* Configure PCI Local Access Windows */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020086 pci_law[0].bar = CONFIG_SYS_PCI_MEM_PHYS & LAWBAR_BAR;
Kim Phillips1cb07e62008-01-16 00:38:05 -060087 pci_law[0].ar = LBLAWAR_EN | LBLAWAR_512MB;
88
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020089 pci_law[1].bar = CONFIG_SYS_PCI_IO_PHYS & LAWBAR_BAR;
Kim Phillips1cb07e62008-01-16 00:38:05 -060090 pci_law[1].ar = LBLAWAR_EN | LBLAWAR_1MB;
91
92 mpc83xx_pci_init(1, reg, 0);
Anton Vorontsov45a30ee2009-02-19 18:20:52 +030093
94 /* There is no PEX in MPC8379 parts. */
95 if (PARTID_NO_E(spridr) == SPR_8379)
96 return;
97
98 /* Configure the clock for PCIE controller */
99 clrsetbits_be32(&clk->sccr, SCCR_PCIEXP1CM | SCCR_PCIEXP2CM,
100 SCCR_PCIEXP1CM_1 | SCCR_PCIEXP2CM_1);
101
102 /* Deassert the resets in the control register */
103 out_be32(&sysconf->pecr1, 0xE0008000);
104 out_be32(&sysconf->pecr2, 0xE0008000);
105 udelay(2000);
106
107 /* Configure PCI Express Local Access Windows */
108 out_be32(&pcie_law[0].bar, CONFIG_SYS_PCIE1_BASE & LAWBAR_BAR);
109 out_be32(&pcie_law[0].ar, LBLAWAR_EN | LBLAWAR_512MB);
110
111 out_be32(&pcie_law[1].bar, CONFIG_SYS_PCIE2_BASE & LAWBAR_BAR);
112 out_be32(&pcie_law[1].ar, LBLAWAR_EN | LBLAWAR_512MB);
113
114 mpc83xx_pcie_init(2, pcie_reg, 0);
Kim Phillips1cb07e62008-01-16 00:38:05 -0600115}
116#endif /* CONFIG_PCI */