Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2008 Extreme Engineering Solutions, Inc. |
| 3 | * Copyright 2007-2008 Freescale Semiconductor, Inc. |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
| 25 | #include <pci.h> |
Kumar Gala | 9bbd643 | 2009-04-02 13:22:48 -0500 | [diff] [blame] | 26 | #include <asm/fsl_pci.h> |
Peter Tyser | 2b1a48d | 2009-08-07 13:16:34 -0500 | [diff] [blame] | 27 | #include <asm/io.h> |
Peter Tyser | 5194477 | 2010-10-22 00:20:22 -0500 | [diff] [blame] | 28 | #include <linux/compiler.h> |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 29 | #include <libfdt.h> |
| 30 | #include <fdt_support.h> |
| 31 | |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 32 | |
Peter Tyser | 59b5fdf | 2008-12-01 13:47:13 -0600 | [diff] [blame] | 33 | #ifdef CONFIG_PCI1 |
| 34 | static struct pci_controller pci1_hose; |
| 35 | #endif |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 36 | #ifdef CONFIG_PCIE1 |
| 37 | static struct pci_controller pcie1_hose; |
| 38 | #endif |
| 39 | #ifdef CONFIG_PCIE2 |
| 40 | static struct pci_controller pcie2_hose; |
| 41 | #endif |
| 42 | #ifdef CONFIG_PCIE3 |
| 43 | static struct pci_controller pcie3_hose; |
| 44 | #endif |
| 45 | |
Peter Tyser | 7537982 | 2009-05-22 10:26:35 -0500 | [diff] [blame] | 46 | /* |
| 47 | * 85xx and 86xx share naming conventions, but different layout. |
| 48 | * Correlate names to CPU-specific values to share common |
| 49 | * PCI code. |
| 50 | */ |
| 51 | #if defined(CONFIG_MPC85xx) |
| 52 | #define MPC8xxx_DEVDISR_PCIE1 MPC85xx_DEVDISR_PCIE |
| 53 | #define MPC8xxx_DEVDISR_PCIE2 MPC85xx_DEVDISR_PCIE2 |
| 54 | #define MPC8xxx_DEVDISR_PCIE3 MPC85xx_DEVDISR_PCIE3 |
| 55 | #define MPC8xxx_PORDEVSR_IO_SEL MPC85xx_PORDEVSR_IO_SEL |
| 56 | #define MPC8xxx_PORDEVSR_IO_SEL_SHIFT MPC85xx_PORDEVSR_IO_SEL_SHIFT |
| 57 | #define MPC8xxx_PORBMSR_HA MPC85xx_PORBMSR_HA |
| 58 | #define MPC8xxx_PORBMSR_HA_SHIFT MPC85xx_PORBMSR_HA_SHIFT |
| 59 | #elif defined(CONFIG_MPC86xx) |
| 60 | #define MPC8xxx_DEVDISR_PCIE1 MPC86xx_DEVDISR_PCIEX1 |
| 61 | #define MPC8xxx_DEVDISR_PCIE2 MPC86xx_DEVDISR_PCIEX2 |
| 62 | #define MPC8xxx_DEVDISR_PCIE3 0 /* 8641 doesn't have PCIe3 */ |
| 63 | #define MPC8xxx_PORDEVSR_IO_SEL MPC8641_PORDEVSR_IO_SEL |
| 64 | #define MPC8xxx_PORDEVSR_IO_SEL_SHIFT MPC8641_PORDEVSR_IO_SEL_SHIFT |
| 65 | #define MPC8xxx_PORBMSR_HA MPC8641_PORBMSR_HA |
| 66 | #define MPC8xxx_PORBMSR_HA_SHIFT MPC8641_PORBMSR_HA_SHIFT |
| 67 | #endif |
| 68 | |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 69 | void pci_init_board(void) |
| 70 | { |
Peter Tyser | 5194477 | 2010-10-22 00:20:22 -0500 | [diff] [blame] | 71 | struct fsl_pci_info pci_info[3]; |
| 72 | int first_free_busno = 0; |
| 73 | int num = 0; |
| 74 | int pcie_ep; |
| 75 | __maybe_unused int pcie_configured; |
| 76 | |
Peter Tyser | 7537982 | 2009-05-22 10:26:35 -0500 | [diff] [blame] | 77 | #if defined(CONFIG_MPC85xx) |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 78 | volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); |
Peter Tyser | 7537982 | 2009-05-22 10:26:35 -0500 | [diff] [blame] | 79 | #elif defined(CONFIG_MPC86xx) |
| 80 | immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; |
| 81 | volatile ccsr_gur_t *gur = &immap->im_gur; |
| 82 | #endif |
Peter Tyser | 5194477 | 2010-10-22 00:20:22 -0500 | [diff] [blame] | 83 | u32 devdisr = in_be32(&gur->devdisr); |
| 84 | u32 pordevsr = in_be32(&gur->pordevsr); |
| 85 | __maybe_unused uint io_sel = (pordevsr & MPC8xxx_PORDEVSR_IO_SEL) >> |
Peter Tyser | 7537982 | 2009-05-22 10:26:35 -0500 | [diff] [blame] | 86 | MPC8xxx_PORDEVSR_IO_SEL_SHIFT; |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 87 | |
Peter Tyser | 59b5fdf | 2008-12-01 13:47:13 -0600 | [diff] [blame] | 88 | #ifdef CONFIG_PCI1 |
Peter Tyser | 2b1a48d | 2009-08-07 13:16:34 -0500 | [diff] [blame] | 89 | uint pci_spd_norm = in_be32(&gur->pordevsr) & MPC85xx_PORDEVSR_PCI1_SPD; |
| 90 | uint pci_32 = in_be32(&gur->pordevsr) & MPC85xx_PORDEVSR_PCI1_PCI32; |
| 91 | uint pci_arb = in_be32(&gur->pordevsr) & MPC85xx_PORDEVSR_PCI1_ARB; |
| 92 | uint pcix = in_be32(&gur->pordevsr) & MPC85xx_PORDEVSR_PCI1; |
Peter Tyser | 59b5fdf | 2008-12-01 13:47:13 -0600 | [diff] [blame] | 93 | uint freq = CONFIG_SYS_CLK_FREQ / 1000 / 1000; |
| 94 | |
Peter Tyser | 59b5fdf | 2008-12-01 13:47:13 -0600 | [diff] [blame] | 95 | if (!(devdisr & MPC85xx_DEVDISR_PCI1)) { |
Peter Tyser | 5194477 | 2010-10-22 00:20:22 -0500 | [diff] [blame] | 96 | SET_STD_PCI_INFO(pci_info[num], 1); |
| 97 | pcie_ep = fsl_setup_hose(&pci1_hose, pci_info[num].regs); |
Peter Tyser | 2b91f71 | 2010-10-29 17:59:24 -0500 | [diff] [blame^] | 98 | printf("PCI1: %d bit %s, %s %d MHz, %s, %s\n", |
Peter Tyser | 59b5fdf | 2008-12-01 13:47:13 -0600 | [diff] [blame] | 99 | pci_32 ? 32 : 64, |
| 100 | pcix ? "PCIX" : "PCI", |
Peter Tyser | 2b1a48d | 2009-08-07 13:16:34 -0500 | [diff] [blame] | 101 | pci_spd_norm ? ">=" : "<=", |
Peter Tyser | 59b5fdf | 2008-12-01 13:47:13 -0600 | [diff] [blame] | 102 | pcix ? freq * 2 : freq, |
Peter Tyser | 5194477 | 2010-10-22 00:20:22 -0500 | [diff] [blame] | 103 | pcie_ep ? "agent" : "host", |
Peter Tyser | 59b5fdf | 2008-12-01 13:47:13 -0600 | [diff] [blame] | 104 | pci_arb ? "arbiter" : "external-arbiter"); |
| 105 | |
Peter Tyser | 5194477 | 2010-10-22 00:20:22 -0500 | [diff] [blame] | 106 | first_free_busno = fsl_pci_init_port(&pci_info[num++], |
| 107 | &pci1_hose, first_free_busno); |
Peter Tyser | 59b5fdf | 2008-12-01 13:47:13 -0600 | [diff] [blame] | 108 | } else { |
Peter Tyser | 2b91f71 | 2010-10-29 17:59:24 -0500 | [diff] [blame^] | 109 | printf("PCI1: disabled\n"); |
Peter Tyser | 59b5fdf | 2008-12-01 13:47:13 -0600 | [diff] [blame] | 110 | } |
| 111 | #elif defined CONFIG_MPC8548 |
| 112 | /* PCI1 not present on MPC8572 */ |
Peter Tyser | 2b1a48d | 2009-08-07 13:16:34 -0500 | [diff] [blame] | 113 | setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCI1); |
Peter Tyser | 59b5fdf | 2008-12-01 13:47:13 -0600 | [diff] [blame] | 114 | #endif |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 115 | |
Peter Tyser | 5194477 | 2010-10-22 00:20:22 -0500 | [diff] [blame] | 116 | #ifdef CONFIG_PCIE1 |
| 117 | pcie_configured = is_fsl_pci_cfg(LAW_TRGT_IF_PCIE_1, io_sel); |
Peter Tyser | 2143be8 | 2008-10-29 12:39:27 -0500 | [diff] [blame] | 118 | |
Peter Tyser | 5194477 | 2010-10-22 00:20:22 -0500 | [diff] [blame] | 119 | if (pcie_configured && !(devdisr & MPC8xxx_DEVDISR_PCIE1)) { |
| 120 | SET_STD_PCIE_INFO(pci_info[num], 1); |
| 121 | pcie_ep = fsl_setup_hose(&pcie1_hose, pci_info[num].regs); |
Peter Tyser | 2b91f71 | 2010-10-29 17:59:24 -0500 | [diff] [blame^] | 122 | printf("PCIE1: connected as %s\n", |
Peter Tyser | 5194477 | 2010-10-22 00:20:22 -0500 | [diff] [blame] | 123 | pcie_ep ? "Endpoint" : "Root Complex"); |
| 124 | first_free_busno = fsl_pci_init_port(&pci_info[num++], |
| 125 | &pcie1_hose, first_free_busno); |
| 126 | } else { |
Peter Tyser | 2b91f71 | 2010-10-29 17:59:24 -0500 | [diff] [blame^] | 127 | printf("PCIE1: disabled\n"); |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 128 | } |
| 129 | #else |
Peter Tyser | 2b1a48d | 2009-08-07 13:16:34 -0500 | [diff] [blame] | 130 | setbits_be32(&gur->devdisr, MPC8xxx_DEVDISR_PCIE1); |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 131 | #endif /* CONFIG_PCIE1 */ |
| 132 | |
| 133 | #ifdef CONFIG_PCIE2 |
Peter Tyser | 5194477 | 2010-10-22 00:20:22 -0500 | [diff] [blame] | 134 | pcie_configured = is_fsl_pci_cfg(LAW_TRGT_IF_PCIE_2, io_sel); |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 135 | |
Peter Tyser | 5194477 | 2010-10-22 00:20:22 -0500 | [diff] [blame] | 136 | if (pcie_configured && !(devdisr & MPC8xxx_DEVDISR_PCIE2)) { |
| 137 | SET_STD_PCIE_INFO(pci_info[num], 2); |
| 138 | pcie_ep = fsl_setup_hose(&pcie2_hose, pci_info[num].regs); |
Peter Tyser | 2b91f71 | 2010-10-29 17:59:24 -0500 | [diff] [blame^] | 139 | printf("PCIE2: connected as %s\n", |
Peter Tyser | 5194477 | 2010-10-22 00:20:22 -0500 | [diff] [blame] | 140 | pcie_ep ? "Endpoint" : "Root Complex"); |
| 141 | first_free_busno = fsl_pci_init_port(&pci_info[num++], |
| 142 | &pcie2_hose, first_free_busno); |
| 143 | } else { |
Peter Tyser | 2b91f71 | 2010-10-29 17:59:24 -0500 | [diff] [blame^] | 144 | printf("PCIE2: disabled\n"); |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 145 | } |
| 146 | #else |
Peter Tyser | 2b1a48d | 2009-08-07 13:16:34 -0500 | [diff] [blame] | 147 | setbits_be32(&gur->devdisr, MPC8xxx_DEVDISR_PCIE2); |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 148 | #endif /* CONFIG_PCIE2 */ |
| 149 | |
| 150 | #ifdef CONFIG_PCIE3 |
Peter Tyser | 5194477 | 2010-10-22 00:20:22 -0500 | [diff] [blame] | 151 | pcie_configured = is_fsl_pci_cfg(LAW_TRGT_IF_PCIE_3, io_sel); |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 152 | |
Peter Tyser | 5194477 | 2010-10-22 00:20:22 -0500 | [diff] [blame] | 153 | if (pcie_configured && !(devdisr & MPC8xxx_DEVDISR_PCIE3)) { |
| 154 | SET_STD_PCIE_INFO(pci_info[num], 3); |
| 155 | pcie_ep = fsl_setup_hose(&pcie3_hose, pci_info[num].regs); |
Peter Tyser | 2b91f71 | 2010-10-29 17:59:24 -0500 | [diff] [blame^] | 156 | printf("PCIE3: connected as %s\n", |
Peter Tyser | 5194477 | 2010-10-22 00:20:22 -0500 | [diff] [blame] | 157 | pcie_ep ? "Endpoint" : "Root Complex"); |
| 158 | first_free_busno = fsl_pci_init_port(&pci_info[num++], |
| 159 | &pcie3_hose, first_free_busno); |
| 160 | } else { |
Peter Tyser | 2b91f71 | 2010-10-29 17:59:24 -0500 | [diff] [blame^] | 161 | printf("PCIE3: disabled\n"); |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 162 | } |
| 163 | #else |
Peter Tyser | 2b1a48d | 2009-08-07 13:16:34 -0500 | [diff] [blame] | 164 | setbits_be32(&gur->devdisr, MPC8xxx_DEVDISR_PCIE3); |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 165 | #endif /* CONFIG_PCIE3 */ |
| 166 | } |
| 167 | |
| 168 | #if defined(CONFIG_OF_BOARD_SETUP) |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 169 | void ft_board_pci_setup(void *blob, bd_t *bd) |
| 170 | { |
Kumar Gala | d0f27d3 | 2010-07-08 22:37:44 -0500 | [diff] [blame] | 171 | FT_FSL_PCI_SETUP; |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 172 | } |
| 173 | #endif /* CONFIG_OF_BOARD_SETUP */ |