Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 2 | /* |
Kim Phillips | 57a2af3 | 2009-07-18 18:42:13 -0500 | [diff] [blame] | 3 | * Copyright (C) 2006-2009 Freescale Semiconductor, Inc. |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <asm/mmu.h> |
| 7 | #include <asm/io.h> |
| 8 | #include <common.h> |
| 9 | #include <mpc83xx.h> |
| 10 | #include <pci.h> |
| 11 | #include <i2c.h> |
Anton Vorontsov | 62842ec | 2009-01-08 04:26:19 +0300 | [diff] [blame] | 12 | #include <fdt_support.h> |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 13 | #include <asm/fsl_i2c.h> |
Kumar Gala | b7c3ccf | 2010-04-20 10:02:24 -0500 | [diff] [blame] | 14 | #include <asm/fsl_mpc83xx_serdes.h> |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 15 | |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 16 | static struct pci_region pci_regions[] = { |
| 17 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 18 | bus_start: CONFIG_SYS_PCI_MEM_BASE, |
| 19 | phys_start: CONFIG_SYS_PCI_MEM_PHYS, |
| 20 | size: CONFIG_SYS_PCI_MEM_SIZE, |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 21 | flags: PCI_REGION_MEM | PCI_REGION_PREFETCH |
| 22 | }, |
| 23 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 24 | bus_start: CONFIG_SYS_PCI_MMIO_BASE, |
| 25 | phys_start: CONFIG_SYS_PCI_MMIO_PHYS, |
| 26 | size: CONFIG_SYS_PCI_MMIO_SIZE, |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 27 | flags: PCI_REGION_MEM |
| 28 | }, |
| 29 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 30 | bus_start: CONFIG_SYS_PCI_IO_BASE, |
| 31 | phys_start: CONFIG_SYS_PCI_IO_PHYS, |
| 32 | size: CONFIG_SYS_PCI_IO_SIZE, |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 33 | flags: PCI_REGION_IO |
| 34 | } |
| 35 | }; |
| 36 | |
Anton Vorontsov | 62842ec | 2009-01-08 04:26:19 +0300 | [diff] [blame] | 37 | static struct pci_region pcie_regions_0[] = { |
| 38 | { |
| 39 | .bus_start = CONFIG_SYS_PCIE1_MEM_BASE, |
| 40 | .phys_start = CONFIG_SYS_PCIE1_MEM_PHYS, |
| 41 | .size = CONFIG_SYS_PCIE1_MEM_SIZE, |
| 42 | .flags = PCI_REGION_MEM, |
| 43 | }, |
| 44 | { |
| 45 | .bus_start = CONFIG_SYS_PCIE1_IO_BASE, |
| 46 | .phys_start = CONFIG_SYS_PCIE1_IO_PHYS, |
| 47 | .size = CONFIG_SYS_PCIE1_IO_SIZE, |
| 48 | .flags = PCI_REGION_IO, |
| 49 | }, |
| 50 | }; |
| 51 | |
| 52 | static struct pci_region pcie_regions_1[] = { |
| 53 | { |
| 54 | .bus_start = CONFIG_SYS_PCIE2_MEM_BASE, |
| 55 | .phys_start = CONFIG_SYS_PCIE2_MEM_PHYS, |
| 56 | .size = CONFIG_SYS_PCIE2_MEM_SIZE, |
| 57 | .flags = PCI_REGION_MEM, |
| 58 | }, |
| 59 | { |
| 60 | .bus_start = CONFIG_SYS_PCIE2_IO_BASE, |
| 61 | .phys_start = CONFIG_SYS_PCIE2_IO_PHYS, |
| 62 | .size = CONFIG_SYS_PCIE2_IO_SIZE, |
| 63 | .flags = PCI_REGION_IO, |
| 64 | }, |
| 65 | }; |
| 66 | |
| 67 | static int is_pex_x2(void) |
| 68 | { |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 69 | const char *pex_x2 = env_get("pex_x2"); |
Anton Vorontsov | 62842ec | 2009-01-08 04:26:19 +0300 | [diff] [blame] | 70 | |
| 71 | if (pex_x2 && !strcmp(pex_x2, "yes")) |
| 72 | return 1; |
| 73 | return 0; |
| 74 | } |
| 75 | |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 76 | void pci_init_board(void) |
| 77 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 78 | volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR; |
Anton Vorontsov | 62842ec | 2009-01-08 04:26:19 +0300 | [diff] [blame] | 79 | volatile sysconf83xx_t *sysconf = &immr->sysconf; |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 80 | volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk; |
| 81 | volatile law83xx_t *pci_law = immr->sysconf.pcilaw; |
Anton Vorontsov | 62842ec | 2009-01-08 04:26:19 +0300 | [diff] [blame] | 82 | volatile law83xx_t *pcie_law = sysconf->pcielaw; |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 83 | struct pci_region *reg[] = { pci_regions }; |
Anton Vorontsov | 62842ec | 2009-01-08 04:26:19 +0300 | [diff] [blame] | 84 | struct pci_region *pcie_reg[] = { pcie_regions_0, pcie_regions_1, }; |
| 85 | u32 spridr = in_be32(&immr->sysconf.spridr); |
| 86 | int pex2 = is_pex_x2(); |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 87 | |
Anton Vorontsov | 30c6992 | 2008-10-02 19:17:33 +0400 | [diff] [blame] | 88 | if (board_pci_host_broken()) |
Anton Vorontsov | 62842ec | 2009-01-08 04:26:19 +0300 | [diff] [blame] | 89 | goto skip_pci; |
Anton Vorontsov | 30c6992 | 2008-10-02 19:17:33 +0400 | [diff] [blame] | 90 | |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 91 | /* Enable all 5 PCI_CLK_OUTPUTS */ |
| 92 | clk->occr |= 0xf8000000; |
| 93 | udelay(2000); |
| 94 | |
| 95 | /* Configure PCI Local Access Windows */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 96 | pci_law[0].bar = CONFIG_SYS_PCI_MEM_PHYS & LAWBAR_BAR; |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 97 | pci_law[0].ar = LBLAWAR_EN | LBLAWAR_512MB; |
| 98 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 99 | pci_law[1].bar = CONFIG_SYS_PCI_IO_PHYS & LAWBAR_BAR; |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 100 | pci_law[1].ar = LBLAWAR_EN | LBLAWAR_1MB; |
| 101 | |
| 102 | udelay(2000); |
| 103 | |
Peter Tyser | e228332 | 2010-09-14 19:13:50 -0500 | [diff] [blame] | 104 | mpc83xx_pci_init(1, reg); |
Anton Vorontsov | 62842ec | 2009-01-08 04:26:19 +0300 | [diff] [blame] | 105 | skip_pci: |
| 106 | /* There is no PEX in MPC8379 parts. */ |
| 107 | if (PARTID_NO_E(spridr) == SPR_8379) |
| 108 | return; |
| 109 | |
Anton Vorontsov | 58fc0c3 | 2009-02-19 18:20:39 +0300 | [diff] [blame] | 110 | if (pex2) |
| 111 | fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_PEX_X2, |
| 112 | FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V); |
| 113 | else |
| 114 | fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_PEX, |
| 115 | FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V); |
| 116 | |
Anton Vorontsov | 62842ec | 2009-01-08 04:26:19 +0300 | [diff] [blame] | 117 | /* Configure the clock for PCIE controller */ |
| 118 | clrsetbits_be32(&clk->sccr, SCCR_PCIEXP1CM | SCCR_PCIEXP2CM, |
| 119 | SCCR_PCIEXP1CM_1 | SCCR_PCIEXP2CM_1); |
| 120 | |
| 121 | /* Deassert the resets in the control register */ |
| 122 | out_be32(&sysconf->pecr1, 0xE0008000); |
| 123 | if (!pex2) |
| 124 | out_be32(&sysconf->pecr2, 0xE0008000); |
| 125 | udelay(2000); |
| 126 | |
| 127 | /* Configure PCI Express Local Access Windows */ |
| 128 | out_be32(&pcie_law[0].bar, CONFIG_SYS_PCIE1_BASE & LAWBAR_BAR); |
| 129 | out_be32(&pcie_law[0].ar, LBLAWAR_EN | LBLAWAR_512MB); |
| 130 | |
| 131 | out_be32(&pcie_law[1].bar, CONFIG_SYS_PCIE2_BASE & LAWBAR_BAR); |
| 132 | out_be32(&pcie_law[1].ar, LBLAWAR_EN | LBLAWAR_512MB); |
| 133 | |
Kim Phillips | da7fb74 | 2010-09-30 13:40:34 -0500 | [diff] [blame] | 134 | mpc83xx_pcie_init(pex2 ? 1 : 2, pcie_reg); |
Anton Vorontsov | 62842ec | 2009-01-08 04:26:19 +0300 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | void ft_pcie_fixup(void *blob, bd_t *bd) |
| 138 | { |
| 139 | const char *status = "disabled (PCIE1 is x2)"; |
| 140 | |
| 141 | if (!is_pex_x2()) |
| 142 | return; |
| 143 | |
| 144 | do_fixup_by_path(blob, "pci2", "status", status, |
| 145 | strlen(status) + 1, 1); |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 146 | } |