blob: dccf8c5551b0c3c70422ba4c4ca20186025deea1 [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>
Simon Glass2cf431c2019-11-14 12:57:47 -07007#include <init.h>
Kim Phillips5e918a92008-01-16 00:38:05 -06008#include <mpc83xx.h>
9#include <pci.h>
Anton Vorontsov7e915582009-02-19 18:20:52 +030010#include <asm/io.h>
Simon Glassc05ed002020-05-10 11:40:11 -060011#include <linux/delay.h>
Kim Phillips5e918a92008-01-16 00:38:05 -060012
Kim Phillips5e918a92008-01-16 00:38:05 -060013static struct pci_region pci_regions[] = {
14 {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020015 bus_start: CONFIG_SYS_PCI_MEM_BASE,
16 phys_start: CONFIG_SYS_PCI_MEM_PHYS,
17 size: CONFIG_SYS_PCI_MEM_SIZE,
Kim Phillips5e918a92008-01-16 00:38:05 -060018 flags: PCI_REGION_MEM | PCI_REGION_PREFETCH
19 },
20 {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020021 bus_start: CONFIG_SYS_PCI_MMIO_BASE,
22 phys_start: CONFIG_SYS_PCI_MMIO_PHYS,
23 size: CONFIG_SYS_PCI_MMIO_SIZE,
Kim Phillips5e918a92008-01-16 00:38:05 -060024 flags: PCI_REGION_MEM
25 },
26 {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020027 bus_start: CONFIG_SYS_PCI_IO_BASE,
28 phys_start: CONFIG_SYS_PCI_IO_PHYS,
29 size: CONFIG_SYS_PCI_IO_SIZE,
Kim Phillips5e918a92008-01-16 00:38:05 -060030 flags: PCI_REGION_IO
31 }
32};
33
Anton Vorontsov7e915582009-02-19 18:20:52 +030034static struct pci_region pcie_regions_0[] = {
35 {
36 .bus_start = CONFIG_SYS_PCIE1_MEM_BASE,
37 .phys_start = CONFIG_SYS_PCIE1_MEM_PHYS,
38 .size = CONFIG_SYS_PCIE1_MEM_SIZE,
39 .flags = PCI_REGION_MEM,
40 },
41 {
42 .bus_start = CONFIG_SYS_PCIE1_IO_BASE,
43 .phys_start = CONFIG_SYS_PCIE1_IO_PHYS,
44 .size = CONFIG_SYS_PCIE1_IO_SIZE,
45 .flags = PCI_REGION_IO,
46 },
47};
48
49static struct pci_region pcie_regions_1[] = {
50 {
51 .bus_start = CONFIG_SYS_PCIE2_MEM_BASE,
52 .phys_start = CONFIG_SYS_PCIE2_MEM_PHYS,
53 .size = CONFIG_SYS_PCIE2_MEM_SIZE,
54 .flags = PCI_REGION_MEM,
55 },
56 {
57 .bus_start = CONFIG_SYS_PCIE2_IO_BASE,
58 .phys_start = CONFIG_SYS_PCIE2_IO_PHYS,
59 .size = CONFIG_SYS_PCIE2_IO_SIZE,
60 .flags = PCI_REGION_IO,
61 },
62};
63
Kim Phillips5e918a92008-01-16 00:38:05 -060064void pci_init_board(void)
65{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020066 volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR;
Anton Vorontsov7e915582009-02-19 18:20:52 +030067 volatile sysconf83xx_t *sysconf = &immr->sysconf;
Kim Phillips5e918a92008-01-16 00:38:05 -060068 volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk;
69 volatile law83xx_t *pci_law = immr->sysconf.pcilaw;
Anton Vorontsov7e915582009-02-19 18:20:52 +030070 volatile law83xx_t *pcie_law = sysconf->pcielaw;
Kim Phillips5e918a92008-01-16 00:38:05 -060071 struct pci_region *reg[] = { pci_regions };
Anton Vorontsov7e915582009-02-19 18:20:52 +030072 struct pci_region *pcie_reg[] = { pcie_regions_0, pcie_regions_1, };
73 u32 spridr = in_be32(&immr->sysconf.spridr);
Kim Phillips5e918a92008-01-16 00:38:05 -060074
75 /* Enable all 5 PCI_CLK_OUTPUTS */
76 clk->occr |= 0xf8000000;
77 udelay(2000);
78
79 /* Configure PCI Local Access Windows */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020080 pci_law[0].bar = CONFIG_SYS_PCI_MEM_PHYS & LAWBAR_BAR;
Kim Phillips5e918a92008-01-16 00:38:05 -060081 pci_law[0].ar = LBLAWAR_EN | LBLAWAR_512MB;
82
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020083 pci_law[1].bar = CONFIG_SYS_PCI_IO_PHYS & LAWBAR_BAR;
Kim Phillips5e918a92008-01-16 00:38:05 -060084 pci_law[1].ar = LBLAWAR_EN | LBLAWAR_1MB;
85
Peter Tyser6aa3d3b2010-09-14 19:13:50 -050086 mpc83xx_pci_init(1, reg);
Anton Vorontsov7e915582009-02-19 18:20:52 +030087
88 /* There is no PEX in MPC8379 parts. */
89 if (PARTID_NO_E(spridr) == SPR_8379)
90 return;
91
92 /* Configure the clock for PCIE controller */
93 clrsetbits_be32(&clk->sccr, SCCR_PCIEXP1CM | SCCR_PCIEXP2CM,
94 SCCR_PCIEXP1CM_1 | SCCR_PCIEXP2CM_1);
95
96 /* Deassert the resets in the control register */
97 out_be32(&sysconf->pecr1, 0xE0008000);
98 out_be32(&sysconf->pecr2, 0xE0008000);
99 udelay(2000);
100
101 /* Configure PCI Express Local Access Windows */
102 out_be32(&pcie_law[0].bar, CONFIG_SYS_PCIE1_BASE & LAWBAR_BAR);
103 out_be32(&pcie_law[0].ar, LBLAWAR_EN | LBLAWAR_512MB);
104
105 out_be32(&pcie_law[1].bar, CONFIG_SYS_PCIE2_BASE & LAWBAR_BAR);
106 out_be32(&pcie_law[1].ar, LBLAWAR_EN | LBLAWAR_512MB);
107
Peter Tyser6aa3d3b2010-09-14 19:13:50 -0500108 mpc83xx_pcie_init(2, pcie_reg);
Kim Phillips5e918a92008-01-16 00:38:05 -0600109}