Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Kim Phillips | 5e918a9 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 2 | /* |
Kim Phillips | 9993e19 | 2009-07-18 18:42:13 -0500 | [diff] [blame] | 3 | * Copyright (C) 2006-2009 Freescale Semiconductor, Inc. |
Kim Phillips | 5e918a9 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <mpc83xx.h> |
| 8 | #include <pci.h> |
Anton Vorontsov | 7e91558 | 2009-02-19 18:20:52 +0300 | [diff] [blame] | 9 | #include <asm/io.h> |
Kim Phillips | 5e918a9 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 10 | |
Kim Phillips | 5e918a9 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 11 | static struct pci_region pci_regions[] = { |
| 12 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 13 | bus_start: CONFIG_SYS_PCI_MEM_BASE, |
| 14 | phys_start: CONFIG_SYS_PCI_MEM_PHYS, |
| 15 | size: CONFIG_SYS_PCI_MEM_SIZE, |
Kim Phillips | 5e918a9 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 16 | flags: PCI_REGION_MEM | PCI_REGION_PREFETCH |
| 17 | }, |
| 18 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 19 | bus_start: CONFIG_SYS_PCI_MMIO_BASE, |
| 20 | phys_start: CONFIG_SYS_PCI_MMIO_PHYS, |
| 21 | size: CONFIG_SYS_PCI_MMIO_SIZE, |
Kim Phillips | 5e918a9 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 22 | flags: PCI_REGION_MEM |
| 23 | }, |
| 24 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 25 | bus_start: CONFIG_SYS_PCI_IO_BASE, |
| 26 | phys_start: CONFIG_SYS_PCI_IO_PHYS, |
| 27 | size: CONFIG_SYS_PCI_IO_SIZE, |
Kim Phillips | 5e918a9 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 28 | flags: PCI_REGION_IO |
| 29 | } |
| 30 | }; |
| 31 | |
Anton Vorontsov | 7e91558 | 2009-02-19 18:20:52 +0300 | [diff] [blame] | 32 | static 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 | |
| 47 | static 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 Phillips | 5e918a9 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 62 | void pci_init_board(void) |
| 63 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 64 | volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR; |
Anton Vorontsov | 7e91558 | 2009-02-19 18:20:52 +0300 | [diff] [blame] | 65 | volatile sysconf83xx_t *sysconf = &immr->sysconf; |
Kim Phillips | 5e918a9 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 66 | volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk; |
| 67 | volatile law83xx_t *pci_law = immr->sysconf.pcilaw; |
Anton Vorontsov | 7e91558 | 2009-02-19 18:20:52 +0300 | [diff] [blame] | 68 | volatile law83xx_t *pcie_law = sysconf->pcielaw; |
Kim Phillips | 5e918a9 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 69 | struct pci_region *reg[] = { pci_regions }; |
Anton Vorontsov | 7e91558 | 2009-02-19 18:20:52 +0300 | [diff] [blame] | 70 | struct pci_region *pcie_reg[] = { pcie_regions_0, pcie_regions_1, }; |
| 71 | u32 spridr = in_be32(&immr->sysconf.spridr); |
Kim Phillips | 5e918a9 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 72 | |
| 73 | /* Enable all 5 PCI_CLK_OUTPUTS */ |
| 74 | clk->occr |= 0xf8000000; |
| 75 | udelay(2000); |
| 76 | |
| 77 | /* Configure PCI Local Access Windows */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 78 | pci_law[0].bar = CONFIG_SYS_PCI_MEM_PHYS & LAWBAR_BAR; |
Kim Phillips | 5e918a9 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 79 | pci_law[0].ar = LBLAWAR_EN | LBLAWAR_512MB; |
| 80 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 81 | pci_law[1].bar = CONFIG_SYS_PCI_IO_PHYS & LAWBAR_BAR; |
Kim Phillips | 5e918a9 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 82 | pci_law[1].ar = LBLAWAR_EN | LBLAWAR_1MB; |
| 83 | |
Peter Tyser | 6aa3d3b | 2010-09-14 19:13:50 -0500 | [diff] [blame] | 84 | mpc83xx_pci_init(1, reg); |
Anton Vorontsov | 7e91558 | 2009-02-19 18:20:52 +0300 | [diff] [blame] | 85 | |
| 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 Tyser | 6aa3d3b | 2010-09-14 19:13:50 -0500 | [diff] [blame] | 106 | mpc83xx_pcie_init(2, pcie_reg); |
Kim Phillips | 5e918a9 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 107 | } |