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