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> |
Simon Glass | 2cf431c | 2019-11-14 12:57:47 -0700 | [diff] [blame] | 7 | #include <init.h> |
Kim Phillips | 5e918a9 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 8 | #include <mpc83xx.h> |
| 9 | #include <pci.h> |
Anton Vorontsov | 7e91558 | 2009-02-19 18:20:52 +0300 | [diff] [blame] | 10 | #include <asm/io.h> |
Simon Glass | c05ed00 | 2020-05-10 11:40:11 -0600 | [diff] [blame^] | 11 | #include <linux/delay.h> |
Kim Phillips | 5e918a9 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 12 | |
Kim Phillips | 5e918a9 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 13 | static struct pci_region pci_regions[] = { |
| 14 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 15 | bus_start: CONFIG_SYS_PCI_MEM_BASE, |
| 16 | phys_start: CONFIG_SYS_PCI_MEM_PHYS, |
| 17 | size: CONFIG_SYS_PCI_MEM_SIZE, |
Kim Phillips | 5e918a9 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 18 | flags: PCI_REGION_MEM | PCI_REGION_PREFETCH |
| 19 | }, |
| 20 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 21 | bus_start: CONFIG_SYS_PCI_MMIO_BASE, |
| 22 | phys_start: CONFIG_SYS_PCI_MMIO_PHYS, |
| 23 | size: CONFIG_SYS_PCI_MMIO_SIZE, |
Kim Phillips | 5e918a9 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 24 | flags: PCI_REGION_MEM |
| 25 | }, |
| 26 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 27 | bus_start: CONFIG_SYS_PCI_IO_BASE, |
| 28 | phys_start: CONFIG_SYS_PCI_IO_PHYS, |
| 29 | size: CONFIG_SYS_PCI_IO_SIZE, |
Kim Phillips | 5e918a9 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 30 | flags: PCI_REGION_IO |
| 31 | } |
| 32 | }; |
| 33 | |
Anton Vorontsov | 7e91558 | 2009-02-19 18:20:52 +0300 | [diff] [blame] | 34 | static 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 | |
| 49 | static 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 Phillips | 5e918a9 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 64 | void pci_init_board(void) |
| 65 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 66 | volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR; |
Anton Vorontsov | 7e91558 | 2009-02-19 18:20:52 +0300 | [diff] [blame] | 67 | volatile sysconf83xx_t *sysconf = &immr->sysconf; |
Kim Phillips | 5e918a9 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 68 | volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk; |
| 69 | volatile law83xx_t *pci_law = immr->sysconf.pcilaw; |
Anton Vorontsov | 7e91558 | 2009-02-19 18:20:52 +0300 | [diff] [blame] | 70 | volatile law83xx_t *pcie_law = sysconf->pcielaw; |
Kim Phillips | 5e918a9 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 71 | struct pci_region *reg[] = { pci_regions }; |
Anton Vorontsov | 7e91558 | 2009-02-19 18:20:52 +0300 | [diff] [blame] | 72 | struct pci_region *pcie_reg[] = { pcie_regions_0, pcie_regions_1, }; |
| 73 | u32 spridr = in_be32(&immr->sysconf.spridr); |
Kim Phillips | 5e918a9 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 74 | |
| 75 | /* Enable all 5 PCI_CLK_OUTPUTS */ |
| 76 | clk->occr |= 0xf8000000; |
| 77 | udelay(2000); |
| 78 | |
| 79 | /* Configure PCI Local Access Windows */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 80 | pci_law[0].bar = CONFIG_SYS_PCI_MEM_PHYS & LAWBAR_BAR; |
Kim Phillips | 5e918a9 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 81 | pci_law[0].ar = LBLAWAR_EN | LBLAWAR_512MB; |
| 82 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 83 | pci_law[1].bar = CONFIG_SYS_PCI_IO_PHYS & LAWBAR_BAR; |
Kim Phillips | 5e918a9 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 84 | pci_law[1].ar = LBLAWAR_EN | LBLAWAR_1MB; |
| 85 | |
Peter Tyser | 6aa3d3b | 2010-09-14 19:13:50 -0500 | [diff] [blame] | 86 | mpc83xx_pci_init(1, reg); |
Anton Vorontsov | 7e91558 | 2009-02-19 18:20:52 +0300 | [diff] [blame] | 87 | |
| 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 Tyser | 6aa3d3b | 2010-09-14 19:13:50 -0500 | [diff] [blame] | 108 | mpc83xx_pcie_init(2, pcie_reg); |
Kim Phillips | 5e918a9 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 109 | } |