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