Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 Hauke Mehrtens <hauke@hauke-m.de> |
Florian Fainelli | be908d2 | 2015-10-16 12:04:04 -0700 | [diff] [blame] | 3 | * Copyright (C) 2015 Broadcom Corporation |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License as |
| 7 | * published by the Free Software Foundation version 2. |
| 8 | * |
| 9 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any |
| 10 | * kind, whether express or implied; without even the implied warranty |
| 11 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | */ |
| 14 | |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/pci.h> |
| 17 | #include <linux/msi.h> |
| 18 | #include <linux/clk.h> |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/mbus.h> |
| 21 | #include <linux/slab.h> |
| 22 | #include <linux/delay.h> |
| 23 | #include <linux/interrupt.h> |
| 24 | #include <linux/platform_device.h> |
| 25 | #include <linux/of_address.h> |
| 26 | #include <linux/of_pci.h> |
| 27 | #include <linux/of_irq.h> |
| 28 | #include <linux/of_platform.h> |
| 29 | #include <linux/phy/phy.h> |
| 30 | |
| 31 | #include "pcie-iproc.h" |
| 32 | |
Ray Jui | 199ff14 | 2015-09-15 17:39:18 -0700 | [diff] [blame] | 33 | #define EP_PERST_SOURCE_SELECT_SHIFT 2 |
| 34 | #define EP_PERST_SOURCE_SELECT BIT(EP_PERST_SOURCE_SELECT_SHIFT) |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 35 | #define EP_MODE_SURVIVE_PERST_SHIFT 1 |
| 36 | #define EP_MODE_SURVIVE_PERST BIT(EP_MODE_SURVIVE_PERST_SHIFT) |
| 37 | #define RC_PCIE_RST_OUTPUT_SHIFT 0 |
| 38 | #define RC_PCIE_RST_OUTPUT BIT(RC_PCIE_RST_OUTPUT_SHIFT) |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 39 | #define PAXC_RESET_MASK 0x7f |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 40 | |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 41 | #define CFG_IND_ADDR_MASK 0x00001ffc |
| 42 | |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 43 | #define CFG_ADDR_BUS_NUM_SHIFT 20 |
| 44 | #define CFG_ADDR_BUS_NUM_MASK 0x0ff00000 |
| 45 | #define CFG_ADDR_DEV_NUM_SHIFT 15 |
| 46 | #define CFG_ADDR_DEV_NUM_MASK 0x000f8000 |
| 47 | #define CFG_ADDR_FUNC_NUM_SHIFT 12 |
| 48 | #define CFG_ADDR_FUNC_NUM_MASK 0x00007000 |
| 49 | #define CFG_ADDR_REG_NUM_SHIFT 2 |
| 50 | #define CFG_ADDR_REG_NUM_MASK 0x00000ffc |
| 51 | #define CFG_ADDR_CFG_TYPE_SHIFT 0 |
| 52 | #define CFG_ADDR_CFG_TYPE_MASK 0x00000003 |
| 53 | |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 54 | #define SYS_RC_INTX_MASK 0xf |
| 55 | |
Ray Jui | aaf22ab | 2015-09-15 17:39:19 -0700 | [diff] [blame] | 56 | #define PCIE_PHYLINKUP_SHIFT 3 |
| 57 | #define PCIE_PHYLINKUP BIT(PCIE_PHYLINKUP_SHIFT) |
| 58 | #define PCIE_DL_ACTIVE_SHIFT 2 |
| 59 | #define PCIE_DL_ACTIVE BIT(PCIE_DL_ACTIVE_SHIFT) |
| 60 | |
Ray Jui | 538928f | 2016-10-31 17:38:33 -0700 | [diff] [blame^] | 61 | #define APB_ERR_EN_SHIFT 0 |
| 62 | #define APB_ERR_EN BIT(APB_ERR_EN_SHIFT) |
| 63 | |
Ray Jui | e99a187 | 2015-10-16 08:18:24 -0500 | [diff] [blame] | 64 | #define OARR_VALID_SHIFT 0 |
| 65 | #define OARR_VALID BIT(OARR_VALID_SHIFT) |
| 66 | #define OARR_SIZE_CFG_SHIFT 1 |
| 67 | #define OARR_SIZE_CFG BIT(OARR_SIZE_CFG_SHIFT) |
| 68 | |
Bjorn Helgaas | e3a1698 | 2016-10-06 13:36:07 -0500 | [diff] [blame] | 69 | #define PCI_EXP_CAP 0xac |
| 70 | |
Ray Jui | e99a187 | 2015-10-16 08:18:24 -0500 | [diff] [blame] | 71 | #define MAX_NUM_OB_WINDOWS 2 |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 72 | |
| 73 | #define IPROC_PCIE_REG_INVALID 0xffff |
| 74 | |
Ray Jui | 06324ed | 2016-10-31 17:38:30 -0700 | [diff] [blame] | 75 | /* |
| 76 | * iProc PCIe host registers |
| 77 | */ |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 78 | enum iproc_pcie_reg { |
Ray Jui | 06324ed | 2016-10-31 17:38:30 -0700 | [diff] [blame] | 79 | /* clock/reset signal control */ |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 80 | IPROC_PCIE_CLK_CTRL = 0, |
Ray Jui | 06324ed | 2016-10-31 17:38:30 -0700 | [diff] [blame] | 81 | |
| 82 | /* allow access to root complex configuration space */ |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 83 | IPROC_PCIE_CFG_IND_ADDR, |
| 84 | IPROC_PCIE_CFG_IND_DATA, |
Ray Jui | 06324ed | 2016-10-31 17:38:30 -0700 | [diff] [blame] | 85 | |
| 86 | /* allow access to device configuration space */ |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 87 | IPROC_PCIE_CFG_ADDR, |
| 88 | IPROC_PCIE_CFG_DATA, |
Ray Jui | 06324ed | 2016-10-31 17:38:30 -0700 | [diff] [blame] | 89 | |
| 90 | /* enable INTx */ |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 91 | IPROC_PCIE_INTX_EN, |
Ray Jui | 06324ed | 2016-10-31 17:38:30 -0700 | [diff] [blame] | 92 | |
| 93 | /* outbound address mapping */ |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 94 | IPROC_PCIE_OARR_LO, |
| 95 | IPROC_PCIE_OARR_HI, |
| 96 | IPROC_PCIE_OMAP_LO, |
| 97 | IPROC_PCIE_OMAP_HI, |
Ray Jui | 06324ed | 2016-10-31 17:38:30 -0700 | [diff] [blame] | 98 | |
| 99 | /* link status */ |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 100 | IPROC_PCIE_LINK_STATUS, |
Ray Jui | 06324ed | 2016-10-31 17:38:30 -0700 | [diff] [blame] | 101 | |
Ray Jui | 538928f | 2016-10-31 17:38:33 -0700 | [diff] [blame^] | 102 | /* enable APB error for unsupported requests */ |
| 103 | IPROC_PCIE_APB_ERR_EN, |
| 104 | |
Ray Jui | 06324ed | 2016-10-31 17:38:30 -0700 | [diff] [blame] | 105 | /* total number of core registers */ |
| 106 | IPROC_PCIE_MAX_NUM_REG, |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 107 | }; |
| 108 | |
Ray Jui | 404349c | 2016-10-31 17:38:32 -0700 | [diff] [blame] | 109 | /* iProc PCIe PAXB BCMA registers */ |
| 110 | static const u16 iproc_pcie_reg_paxb_bcma[] = { |
| 111 | [IPROC_PCIE_CLK_CTRL] = 0x000, |
| 112 | [IPROC_PCIE_CFG_IND_ADDR] = 0x120, |
| 113 | [IPROC_PCIE_CFG_IND_DATA] = 0x124, |
| 114 | [IPROC_PCIE_CFG_ADDR] = 0x1f8, |
| 115 | [IPROC_PCIE_CFG_DATA] = 0x1fc, |
| 116 | [IPROC_PCIE_INTX_EN] = 0x330, |
| 117 | [IPROC_PCIE_LINK_STATUS] = 0xf0c, |
| 118 | }; |
| 119 | |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 120 | /* iProc PCIe PAXB registers */ |
| 121 | static const u16 iproc_pcie_reg_paxb[] = { |
| 122 | [IPROC_PCIE_CLK_CTRL] = 0x000, |
| 123 | [IPROC_PCIE_CFG_IND_ADDR] = 0x120, |
| 124 | [IPROC_PCIE_CFG_IND_DATA] = 0x124, |
| 125 | [IPROC_PCIE_CFG_ADDR] = 0x1f8, |
| 126 | [IPROC_PCIE_CFG_DATA] = 0x1fc, |
| 127 | [IPROC_PCIE_INTX_EN] = 0x330, |
| 128 | [IPROC_PCIE_OARR_LO] = 0xd20, |
| 129 | [IPROC_PCIE_OARR_HI] = 0xd24, |
| 130 | [IPROC_PCIE_OMAP_LO] = 0xd40, |
| 131 | [IPROC_PCIE_OMAP_HI] = 0xd44, |
| 132 | [IPROC_PCIE_LINK_STATUS] = 0xf0c, |
Ray Jui | 538928f | 2016-10-31 17:38:33 -0700 | [diff] [blame^] | 133 | [IPROC_PCIE_APB_ERR_EN] = 0xf40, |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 134 | }; |
| 135 | |
| 136 | /* iProc PCIe PAXC v1 registers */ |
| 137 | static const u16 iproc_pcie_reg_paxc[] = { |
| 138 | [IPROC_PCIE_CLK_CTRL] = 0x000, |
| 139 | [IPROC_PCIE_CFG_IND_ADDR] = 0x1f0, |
| 140 | [IPROC_PCIE_CFG_IND_DATA] = 0x1f4, |
| 141 | [IPROC_PCIE_CFG_ADDR] = 0x1f8, |
| 142 | [IPROC_PCIE_CFG_DATA] = 0x1fc, |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 143 | }; |
Ray Jui | e99a187 | 2015-10-16 08:18:24 -0500 | [diff] [blame] | 144 | |
Ray Jui | 8d9bfe3 | 2015-07-21 18:29:40 -0700 | [diff] [blame] | 145 | static inline struct iproc_pcie *iproc_data(struct pci_bus *bus) |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 146 | { |
Ray Jui | 8d9bfe3 | 2015-07-21 18:29:40 -0700 | [diff] [blame] | 147 | struct iproc_pcie *pcie; |
| 148 | #ifdef CONFIG_ARM |
| 149 | struct pci_sys_data *sys = bus->sysdata; |
| 150 | |
| 151 | pcie = sys->private_data; |
| 152 | #else |
| 153 | pcie = bus->sysdata; |
| 154 | #endif |
| 155 | return pcie; |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 158 | static inline bool iproc_pcie_reg_is_invalid(u16 reg_offset) |
| 159 | { |
| 160 | return !!(reg_offset == IPROC_PCIE_REG_INVALID); |
| 161 | } |
| 162 | |
| 163 | static inline u16 iproc_pcie_reg_offset(struct iproc_pcie *pcie, |
| 164 | enum iproc_pcie_reg reg) |
| 165 | { |
| 166 | return pcie->reg_offsets[reg]; |
| 167 | } |
| 168 | |
| 169 | static inline u32 iproc_pcie_read_reg(struct iproc_pcie *pcie, |
| 170 | enum iproc_pcie_reg reg) |
| 171 | { |
| 172 | u16 offset = iproc_pcie_reg_offset(pcie, reg); |
| 173 | |
| 174 | if (iproc_pcie_reg_is_invalid(offset)) |
| 175 | return 0; |
| 176 | |
| 177 | return readl(pcie->base + offset); |
| 178 | } |
| 179 | |
| 180 | static inline void iproc_pcie_write_reg(struct iproc_pcie *pcie, |
| 181 | enum iproc_pcie_reg reg, u32 val) |
| 182 | { |
| 183 | u16 offset = iproc_pcie_reg_offset(pcie, reg); |
| 184 | |
| 185 | if (iproc_pcie_reg_is_invalid(offset)) |
| 186 | return; |
| 187 | |
| 188 | writel(val, pcie->base + offset); |
| 189 | } |
| 190 | |
Ray Jui | 538928f | 2016-10-31 17:38:33 -0700 | [diff] [blame^] | 191 | /** |
| 192 | * APB error forwarding can be disabled during access of configuration |
| 193 | * registers of the endpoint device, to prevent unsupported requests |
| 194 | * (typically seen during enumeration with multi-function devices) from |
| 195 | * triggering a system exception. |
| 196 | */ |
| 197 | static inline void iproc_pcie_apb_err_disable(struct pci_bus *bus, |
| 198 | bool disable) |
| 199 | { |
| 200 | struct iproc_pcie *pcie = iproc_data(bus); |
| 201 | u32 val; |
| 202 | |
| 203 | if (bus->number && pcie->has_apb_err_disable) { |
| 204 | val = iproc_pcie_read_reg(pcie, IPROC_PCIE_APB_ERR_EN); |
| 205 | if (disable) |
| 206 | val &= ~APB_ERR_EN; |
| 207 | else |
| 208 | val |= APB_ERR_EN; |
| 209 | iproc_pcie_write_reg(pcie, IPROC_PCIE_APB_ERR_EN, val); |
| 210 | } |
| 211 | } |
| 212 | |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 213 | static inline void iproc_pcie_ob_write(struct iproc_pcie *pcie, |
| 214 | enum iproc_pcie_reg reg, |
| 215 | unsigned window, u32 val) |
| 216 | { |
| 217 | u16 offset = iproc_pcie_reg_offset(pcie, reg); |
| 218 | |
| 219 | if (iproc_pcie_reg_is_invalid(offset)) |
| 220 | return; |
| 221 | |
| 222 | writel(val, pcie->base + offset + (window * 8)); |
| 223 | } |
| 224 | |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 225 | /** |
| 226 | * Note access to the configuration registers are protected at the higher layer |
| 227 | * by 'pci_lock' in drivers/pci/access.c |
| 228 | */ |
| 229 | static void __iomem *iproc_pcie_map_cfg_bus(struct pci_bus *bus, |
| 230 | unsigned int devfn, |
| 231 | int where) |
| 232 | { |
Ray Jui | 8d9bfe3 | 2015-07-21 18:29:40 -0700 | [diff] [blame] | 233 | struct iproc_pcie *pcie = iproc_data(bus); |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 234 | unsigned slot = PCI_SLOT(devfn); |
| 235 | unsigned fn = PCI_FUNC(devfn); |
| 236 | unsigned busno = bus->number; |
| 237 | u32 val; |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 238 | u16 offset; |
| 239 | |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 240 | /* root complex access */ |
| 241 | if (busno == 0) { |
Ray Jui | 4656038 | 2016-01-27 16:52:24 -0600 | [diff] [blame] | 242 | if (slot > 0 || fn > 0) |
| 243 | return NULL; |
| 244 | |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 245 | iproc_pcie_write_reg(pcie, IPROC_PCIE_CFG_IND_ADDR, |
| 246 | where & CFG_IND_ADDR_MASK); |
| 247 | offset = iproc_pcie_reg_offset(pcie, IPROC_PCIE_CFG_IND_DATA); |
| 248 | if (iproc_pcie_reg_is_invalid(offset)) |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 249 | return NULL; |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 250 | else |
| 251 | return (pcie->base + offset); |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 252 | } |
| 253 | |
Ray Jui | 4656038 | 2016-01-27 16:52:24 -0600 | [diff] [blame] | 254 | /* |
| 255 | * PAXC is connected to an internally emulated EP within the SoC. It |
| 256 | * allows only one device. |
| 257 | */ |
Ray Jui | 06324ed | 2016-10-31 17:38:30 -0700 | [diff] [blame] | 258 | if (pcie->ep_is_internal) |
Ray Jui | 4656038 | 2016-01-27 16:52:24 -0600 | [diff] [blame] | 259 | if (slot > 0) |
| 260 | return NULL; |
| 261 | |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 262 | /* EP device access */ |
| 263 | val = (busno << CFG_ADDR_BUS_NUM_SHIFT) | |
| 264 | (slot << CFG_ADDR_DEV_NUM_SHIFT) | |
| 265 | (fn << CFG_ADDR_FUNC_NUM_SHIFT) | |
| 266 | (where & CFG_ADDR_REG_NUM_MASK) | |
| 267 | (1 & CFG_ADDR_CFG_TYPE_MASK); |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 268 | iproc_pcie_write_reg(pcie, IPROC_PCIE_CFG_ADDR, val); |
| 269 | offset = iproc_pcie_reg_offset(pcie, IPROC_PCIE_CFG_DATA); |
| 270 | if (iproc_pcie_reg_is_invalid(offset)) |
| 271 | return NULL; |
| 272 | else |
| 273 | return (pcie->base + offset); |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Ray Jui | 538928f | 2016-10-31 17:38:33 -0700 | [diff] [blame^] | 276 | static int iproc_pcie_config_read32(struct pci_bus *bus, unsigned int devfn, |
| 277 | int where, int size, u32 *val) |
| 278 | { |
| 279 | int ret; |
| 280 | |
| 281 | iproc_pcie_apb_err_disable(bus, true); |
| 282 | ret = pci_generic_config_read32(bus, devfn, where, size, val); |
| 283 | iproc_pcie_apb_err_disable(bus, false); |
| 284 | |
| 285 | return ret; |
| 286 | } |
| 287 | |
| 288 | static int iproc_pcie_config_write32(struct pci_bus *bus, unsigned int devfn, |
| 289 | int where, int size, u32 val) |
| 290 | { |
| 291 | int ret; |
| 292 | |
| 293 | iproc_pcie_apb_err_disable(bus, true); |
| 294 | ret = pci_generic_config_write32(bus, devfn, where, size, val); |
| 295 | iproc_pcie_apb_err_disable(bus, false); |
| 296 | |
| 297 | return ret; |
| 298 | } |
| 299 | |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 300 | static struct pci_ops iproc_pcie_ops = { |
| 301 | .map_bus = iproc_pcie_map_cfg_bus, |
Ray Jui | 538928f | 2016-10-31 17:38:33 -0700 | [diff] [blame^] | 302 | .read = iproc_pcie_config_read32, |
| 303 | .write = iproc_pcie_config_write32, |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 304 | }; |
| 305 | |
| 306 | static void iproc_pcie_reset(struct iproc_pcie *pcie) |
| 307 | { |
| 308 | u32 val; |
| 309 | |
Ray Jui | 7cbd50d | 2016-10-31 17:38:31 -0700 | [diff] [blame] | 310 | /* |
| 311 | * PAXC and the internal emulated endpoint device downstream should not |
| 312 | * be reset. If firmware has been loaded on the endpoint device at an |
| 313 | * earlier boot stage, reset here causes issues. |
| 314 | */ |
| 315 | if (pcie->ep_is_internal) |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 316 | return; |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 317 | |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 318 | /* |
Ray Jui | 199ff14 | 2015-09-15 17:39:18 -0700 | [diff] [blame] | 319 | * Select perst_b signal as reset source. Put the device into reset, |
| 320 | * and then bring it out of reset |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 321 | */ |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 322 | val = iproc_pcie_read_reg(pcie, IPROC_PCIE_CLK_CTRL); |
Ray Jui | 199ff14 | 2015-09-15 17:39:18 -0700 | [diff] [blame] | 323 | val &= ~EP_PERST_SOURCE_SELECT & ~EP_MODE_SURVIVE_PERST & |
| 324 | ~RC_PCIE_RST_OUTPUT; |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 325 | iproc_pcie_write_reg(pcie, IPROC_PCIE_CLK_CTRL, val); |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 326 | udelay(250); |
Ray Jui | 199ff14 | 2015-09-15 17:39:18 -0700 | [diff] [blame] | 327 | |
| 328 | val |= RC_PCIE_RST_OUTPUT; |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 329 | iproc_pcie_write_reg(pcie, IPROC_PCIE_CLK_CTRL, val); |
Ray Jui | 199ff14 | 2015-09-15 17:39:18 -0700 | [diff] [blame] | 330 | msleep(100); |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | static int iproc_pcie_check_link(struct iproc_pcie *pcie, struct pci_bus *bus) |
| 334 | { |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 335 | struct device *dev = pcie->dev; |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 336 | u8 hdr_type; |
Ray Jui | aaf22ab | 2015-09-15 17:39:19 -0700 | [diff] [blame] | 337 | u32 link_ctrl, class, val; |
Bjorn Helgaas | e3a1698 | 2016-10-06 13:36:07 -0500 | [diff] [blame] | 338 | u16 pos = PCI_EXP_CAP, link_status; |
Ray Jui | aaf22ab | 2015-09-15 17:39:19 -0700 | [diff] [blame] | 339 | bool link_is_active = false; |
| 340 | |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 341 | /* |
| 342 | * PAXC connects to emulated endpoint devices directly and does not |
| 343 | * have a Serdes. Therefore skip the link detection logic here. |
| 344 | */ |
Ray Jui | 06324ed | 2016-10-31 17:38:30 -0700 | [diff] [blame] | 345 | if (pcie->ep_is_internal) |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 346 | return 0; |
| 347 | |
| 348 | val = iproc_pcie_read_reg(pcie, IPROC_PCIE_LINK_STATUS); |
Ray Jui | aaf22ab | 2015-09-15 17:39:19 -0700 | [diff] [blame] | 349 | if (!(val & PCIE_PHYLINKUP) || !(val & PCIE_DL_ACTIVE)) { |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 350 | dev_err(dev, "PHY or data link is INACTIVE!\n"); |
Ray Jui | aaf22ab | 2015-09-15 17:39:19 -0700 | [diff] [blame] | 351 | return -ENODEV; |
| 352 | } |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 353 | |
| 354 | /* make sure we are not in EP mode */ |
| 355 | pci_bus_read_config_byte(bus, 0, PCI_HEADER_TYPE, &hdr_type); |
| 356 | if ((hdr_type & 0x7f) != PCI_HEADER_TYPE_BRIDGE) { |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 357 | dev_err(dev, "in EP mode, hdr=%#02x\n", hdr_type); |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 358 | return -EFAULT; |
| 359 | } |
| 360 | |
| 361 | /* force class to PCI_CLASS_BRIDGE_PCI (0x0604) */ |
Ray Jui | aaf22ab | 2015-09-15 17:39:19 -0700 | [diff] [blame] | 362 | #define PCI_BRIDGE_CTRL_REG_OFFSET 0x43c |
| 363 | #define PCI_CLASS_BRIDGE_MASK 0xffff00 |
| 364 | #define PCI_CLASS_BRIDGE_SHIFT 8 |
| 365 | pci_bus_read_config_dword(bus, 0, PCI_BRIDGE_CTRL_REG_OFFSET, &class); |
| 366 | class &= ~PCI_CLASS_BRIDGE_MASK; |
| 367 | class |= (PCI_CLASS_BRIDGE_PCI << PCI_CLASS_BRIDGE_SHIFT); |
| 368 | pci_bus_write_config_dword(bus, 0, PCI_BRIDGE_CTRL_REG_OFFSET, class); |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 369 | |
| 370 | /* check link status to see if link is active */ |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 371 | pci_bus_read_config_word(bus, 0, pos + PCI_EXP_LNKSTA, &link_status); |
| 372 | if (link_status & PCI_EXP_LNKSTA_NLW) |
Ray Jui | aaf22ab | 2015-09-15 17:39:19 -0700 | [diff] [blame] | 373 | link_is_active = true; |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 374 | |
| 375 | if (!link_is_active) { |
| 376 | /* try GEN 1 link speed */ |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 377 | #define PCI_TARGET_LINK_SPEED_MASK 0xf |
| 378 | #define PCI_TARGET_LINK_SPEED_GEN2 0x2 |
| 379 | #define PCI_TARGET_LINK_SPEED_GEN1 0x1 |
| 380 | pci_bus_read_config_dword(bus, 0, |
Bjorn Helgaas | e3a1698 | 2016-10-06 13:36:07 -0500 | [diff] [blame] | 381 | pos + PCI_EXP_LNKCTL2, |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 382 | &link_ctrl); |
| 383 | if ((link_ctrl & PCI_TARGET_LINK_SPEED_MASK) == |
| 384 | PCI_TARGET_LINK_SPEED_GEN2) { |
| 385 | link_ctrl &= ~PCI_TARGET_LINK_SPEED_MASK; |
| 386 | link_ctrl |= PCI_TARGET_LINK_SPEED_GEN1; |
| 387 | pci_bus_write_config_dword(bus, 0, |
Bjorn Helgaas | e3a1698 | 2016-10-06 13:36:07 -0500 | [diff] [blame] | 388 | pos + PCI_EXP_LNKCTL2, |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 389 | link_ctrl); |
| 390 | msleep(100); |
| 391 | |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 392 | pci_bus_read_config_word(bus, 0, pos + PCI_EXP_LNKSTA, |
| 393 | &link_status); |
| 394 | if (link_status & PCI_EXP_LNKSTA_NLW) |
Ray Jui | aaf22ab | 2015-09-15 17:39:19 -0700 | [diff] [blame] | 395 | link_is_active = true; |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 396 | } |
| 397 | } |
| 398 | |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 399 | dev_info(dev, "link: %s\n", link_is_active ? "UP" : "DOWN"); |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 400 | |
| 401 | return link_is_active ? 0 : -ENODEV; |
| 402 | } |
| 403 | |
| 404 | static void iproc_pcie_enable(struct iproc_pcie *pcie) |
| 405 | { |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 406 | iproc_pcie_write_reg(pcie, IPROC_PCIE_INTX_EN, SYS_RC_INTX_MASK); |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 407 | } |
| 408 | |
Ray Jui | e99a187 | 2015-10-16 08:18:24 -0500 | [diff] [blame] | 409 | /** |
| 410 | * Some iProc SoCs require the SW to configure the outbound address mapping |
| 411 | * |
| 412 | * Outbound address translation: |
| 413 | * |
| 414 | * iproc_pcie_address = axi_address - axi_offset |
| 415 | * OARR = iproc_pcie_address |
| 416 | * OMAP = pci_addr |
| 417 | * |
| 418 | * axi_addr -> iproc_pcie_address -> OARR -> OMAP -> pci_address |
| 419 | */ |
| 420 | static int iproc_pcie_setup_ob(struct iproc_pcie *pcie, u64 axi_addr, |
| 421 | u64 pci_addr, resource_size_t size) |
| 422 | { |
| 423 | struct iproc_pcie_ob *ob = &pcie->ob; |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 424 | struct device *dev = pcie->dev; |
Ray Jui | e99a187 | 2015-10-16 08:18:24 -0500 | [diff] [blame] | 425 | unsigned i; |
| 426 | u64 max_size = (u64)ob->window_size * MAX_NUM_OB_WINDOWS; |
| 427 | u64 remainder; |
| 428 | |
| 429 | if (size > max_size) { |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 430 | dev_err(dev, |
Dmitry V. Krivenok | 57303e9 | 2015-11-30 23:45:49 +0300 | [diff] [blame] | 431 | "res size %pap exceeds max supported size 0x%llx\n", |
Ray Jui | e99a187 | 2015-10-16 08:18:24 -0500 | [diff] [blame] | 432 | &size, max_size); |
| 433 | return -EINVAL; |
| 434 | } |
| 435 | |
| 436 | div64_u64_rem(size, ob->window_size, &remainder); |
| 437 | if (remainder) { |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 438 | dev_err(dev, |
Ray Jui | e99a187 | 2015-10-16 08:18:24 -0500 | [diff] [blame] | 439 | "res size %pap needs to be multiple of window size %pap\n", |
| 440 | &size, &ob->window_size); |
| 441 | return -EINVAL; |
| 442 | } |
| 443 | |
| 444 | if (axi_addr < ob->axi_offset) { |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 445 | dev_err(dev, "axi address %pap less than offset %pap\n", |
Ray Jui | e99a187 | 2015-10-16 08:18:24 -0500 | [diff] [blame] | 446 | &axi_addr, &ob->axi_offset); |
| 447 | return -EINVAL; |
| 448 | } |
| 449 | |
| 450 | /* |
| 451 | * Translate the AXI address to the internal address used by the iProc |
| 452 | * PCIe core before programming the OARR |
| 453 | */ |
| 454 | axi_addr -= ob->axi_offset; |
| 455 | |
| 456 | for (i = 0; i < MAX_NUM_OB_WINDOWS; i++) { |
Ray Jui | 943ebae | 2015-12-04 09:34:59 -0800 | [diff] [blame] | 457 | iproc_pcie_ob_write(pcie, IPROC_PCIE_OARR_LO, i, |
| 458 | lower_32_bits(axi_addr) | OARR_VALID | |
| 459 | (ob->set_oarr_size ? 1 : 0)); |
| 460 | iproc_pcie_ob_write(pcie, IPROC_PCIE_OARR_HI, i, |
| 461 | upper_32_bits(axi_addr)); |
| 462 | iproc_pcie_ob_write(pcie, IPROC_PCIE_OMAP_LO, i, |
| 463 | lower_32_bits(pci_addr)); |
| 464 | iproc_pcie_ob_write(pcie, IPROC_PCIE_OMAP_HI, i, |
| 465 | upper_32_bits(pci_addr)); |
Ray Jui | e99a187 | 2015-10-16 08:18:24 -0500 | [diff] [blame] | 466 | |
| 467 | size -= ob->window_size; |
| 468 | if (size == 0) |
| 469 | break; |
| 470 | |
| 471 | axi_addr += ob->window_size; |
| 472 | pci_addr += ob->window_size; |
| 473 | } |
| 474 | |
| 475 | return 0; |
| 476 | } |
| 477 | |
| 478 | static int iproc_pcie_map_ranges(struct iproc_pcie *pcie, |
| 479 | struct list_head *resources) |
| 480 | { |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 481 | struct device *dev = pcie->dev; |
Ray Jui | e99a187 | 2015-10-16 08:18:24 -0500 | [diff] [blame] | 482 | struct resource_entry *window; |
| 483 | int ret; |
| 484 | |
| 485 | resource_list_for_each_entry(window, resources) { |
| 486 | struct resource *res = window->res; |
| 487 | u64 res_type = resource_type(res); |
| 488 | |
| 489 | switch (res_type) { |
| 490 | case IORESOURCE_IO: |
| 491 | case IORESOURCE_BUS: |
| 492 | break; |
| 493 | case IORESOURCE_MEM: |
| 494 | ret = iproc_pcie_setup_ob(pcie, res->start, |
| 495 | res->start - window->offset, |
| 496 | resource_size(res)); |
| 497 | if (ret) |
| 498 | return ret; |
| 499 | break; |
| 500 | default: |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 501 | dev_err(dev, "invalid resource %pR\n", res); |
Ray Jui | e99a187 | 2015-10-16 08:18:24 -0500 | [diff] [blame] | 502 | return -EINVAL; |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | return 0; |
| 507 | } |
| 508 | |
Ray Jui | 3bc2b23 | 2016-01-06 18:04:35 -0600 | [diff] [blame] | 509 | static int iproc_pcie_msi_enable(struct iproc_pcie *pcie) |
| 510 | { |
| 511 | struct device_node *msi_node; |
| 512 | |
| 513 | msi_node = of_parse_phandle(pcie->dev->of_node, "msi-parent", 0); |
| 514 | if (!msi_node) |
| 515 | return -ENODEV; |
| 516 | |
| 517 | /* |
| 518 | * If another MSI controller is being used, the call below should fail |
| 519 | * but that is okay |
| 520 | */ |
| 521 | return iproc_msi_init(pcie, msi_node); |
| 522 | } |
| 523 | |
| 524 | static void iproc_pcie_msi_disable(struct iproc_pcie *pcie) |
| 525 | { |
| 526 | iproc_msi_exit(pcie); |
| 527 | } |
| 528 | |
Ray Jui | 06324ed | 2016-10-31 17:38:30 -0700 | [diff] [blame] | 529 | static int iproc_pcie_rev_init(struct iproc_pcie *pcie) |
| 530 | { |
| 531 | struct device *dev = pcie->dev; |
| 532 | unsigned int reg_idx; |
| 533 | const u16 *regs; |
| 534 | |
| 535 | switch (pcie->type) { |
Ray Jui | 404349c | 2016-10-31 17:38:32 -0700 | [diff] [blame] | 536 | case IPROC_PCIE_PAXB_BCMA: |
| 537 | regs = iproc_pcie_reg_paxb_bcma; |
| 538 | break; |
Ray Jui | 06324ed | 2016-10-31 17:38:30 -0700 | [diff] [blame] | 539 | case IPROC_PCIE_PAXB: |
| 540 | regs = iproc_pcie_reg_paxb; |
Ray Jui | 538928f | 2016-10-31 17:38:33 -0700 | [diff] [blame^] | 541 | pcie->has_apb_err_disable = true; |
Ray Jui | 06324ed | 2016-10-31 17:38:30 -0700 | [diff] [blame] | 542 | break; |
| 543 | case IPROC_PCIE_PAXC: |
| 544 | regs = iproc_pcie_reg_paxc; |
| 545 | pcie->ep_is_internal = true; |
| 546 | break; |
| 547 | default: |
| 548 | dev_err(dev, "incompatible iProc PCIe interface\n"); |
| 549 | return -EINVAL; |
| 550 | } |
| 551 | |
| 552 | pcie->reg_offsets = devm_kcalloc(dev, IPROC_PCIE_MAX_NUM_REG, |
| 553 | sizeof(*pcie->reg_offsets), |
| 554 | GFP_KERNEL); |
| 555 | if (!pcie->reg_offsets) |
| 556 | return -ENOMEM; |
| 557 | |
| 558 | /* go through the register table and populate all valid registers */ |
| 559 | pcie->reg_offsets[0] = regs[0]; |
| 560 | for (reg_idx = 1; reg_idx < IPROC_PCIE_MAX_NUM_REG; reg_idx++) |
| 561 | pcie->reg_offsets[reg_idx] = regs[reg_idx] ? |
| 562 | regs[reg_idx] : IPROC_PCIE_REG_INVALID; |
| 563 | |
| 564 | return 0; |
| 565 | } |
| 566 | |
Hauke Mehrtens | 18c4342 | 2015-05-24 22:37:02 +0200 | [diff] [blame] | 567 | int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res) |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 568 | { |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 569 | struct device *dev; |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 570 | int ret; |
Ray Jui | 8d9bfe3 | 2015-07-21 18:29:40 -0700 | [diff] [blame] | 571 | void *sysdata; |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 572 | struct pci_bus *bus; |
| 573 | |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 574 | dev = pcie->dev; |
Ray Jui | 06324ed | 2016-10-31 17:38:30 -0700 | [diff] [blame] | 575 | |
| 576 | ret = iproc_pcie_rev_init(pcie); |
| 577 | if (ret) { |
| 578 | dev_err(dev, "unable to initialize controller parameters\n"); |
| 579 | return ret; |
| 580 | } |
| 581 | |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 582 | ret = devm_request_pci_bus_resources(dev, res); |
Bjorn Helgaas | c3245a5 | 2016-05-28 18:22:24 -0500 | [diff] [blame] | 583 | if (ret) |
| 584 | return ret; |
| 585 | |
Markus Elfring | 93972d1 | 2015-06-28 16:42:04 +0200 | [diff] [blame] | 586 | ret = phy_init(pcie->phy); |
| 587 | if (ret) { |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 588 | dev_err(dev, "unable to initialize PCIe PHY\n"); |
Markus Elfring | 93972d1 | 2015-06-28 16:42:04 +0200 | [diff] [blame] | 589 | return ret; |
| 590 | } |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 591 | |
Markus Elfring | 93972d1 | 2015-06-28 16:42:04 +0200 | [diff] [blame] | 592 | ret = phy_power_on(pcie->phy); |
| 593 | if (ret) { |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 594 | dev_err(dev, "unable to power on PCIe PHY\n"); |
Markus Elfring | 93972d1 | 2015-06-28 16:42:04 +0200 | [diff] [blame] | 595 | goto err_exit_phy; |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | iproc_pcie_reset(pcie); |
| 599 | |
Ray Jui | e99a187 | 2015-10-16 08:18:24 -0500 | [diff] [blame] | 600 | if (pcie->need_ob_cfg) { |
| 601 | ret = iproc_pcie_map_ranges(pcie, res); |
| 602 | if (ret) { |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 603 | dev_err(dev, "map failed\n"); |
Ray Jui | e99a187 | 2015-10-16 08:18:24 -0500 | [diff] [blame] | 604 | goto err_power_off_phy; |
| 605 | } |
| 606 | } |
| 607 | |
Ray Jui | 8d9bfe3 | 2015-07-21 18:29:40 -0700 | [diff] [blame] | 608 | #ifdef CONFIG_ARM |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 609 | pcie->sysdata.private_data = pcie; |
Ray Jui | 8d9bfe3 | 2015-07-21 18:29:40 -0700 | [diff] [blame] | 610 | sysdata = &pcie->sysdata; |
| 611 | #else |
| 612 | sysdata = pcie; |
| 613 | #endif |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 614 | |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 615 | bus = pci_create_root_bus(dev, 0, &iproc_pcie_ops, sysdata, res); |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 616 | if (!bus) { |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 617 | dev_err(dev, "unable to create PCI root bus\n"); |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 618 | ret = -ENOMEM; |
| 619 | goto err_power_off_phy; |
| 620 | } |
| 621 | pcie->root_bus = bus; |
| 622 | |
| 623 | ret = iproc_pcie_check_link(pcie, bus); |
| 624 | if (ret) { |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 625 | dev_err(dev, "no PCIe EP device detected\n"); |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 626 | goto err_rm_root_bus; |
| 627 | } |
| 628 | |
| 629 | iproc_pcie_enable(pcie); |
| 630 | |
Ray Jui | 3bc2b23 | 2016-01-06 18:04:35 -0600 | [diff] [blame] | 631 | if (IS_ENABLED(CONFIG_PCI_MSI)) |
| 632 | if (iproc_pcie_msi_enable(pcie)) |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 633 | dev_info(dev, "not using iProc MSI\n"); |
Ray Jui | 3bc2b23 | 2016-01-06 18:04:35 -0600 | [diff] [blame] | 634 | |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 635 | pci_scan_child_bus(bus); |
| 636 | pci_assign_unassigned_bus_resources(bus); |
Hauke Mehrtens | c1e02ce | 2015-05-12 23:23:00 +0200 | [diff] [blame] | 637 | pci_fixup_irqs(pci_common_swizzle, pcie->map_irq); |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 638 | pci_bus_add_devices(bus); |
| 639 | |
| 640 | return 0; |
| 641 | |
| 642 | err_rm_root_bus: |
| 643 | pci_stop_root_bus(bus); |
| 644 | pci_remove_root_bus(bus); |
| 645 | |
| 646 | err_power_off_phy: |
Markus Elfring | 93972d1 | 2015-06-28 16:42:04 +0200 | [diff] [blame] | 647 | phy_power_off(pcie->phy); |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 648 | err_exit_phy: |
Markus Elfring | 93972d1 | 2015-06-28 16:42:04 +0200 | [diff] [blame] | 649 | phy_exit(pcie->phy); |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 650 | return ret; |
| 651 | } |
| 652 | EXPORT_SYMBOL(iproc_pcie_setup); |
| 653 | |
| 654 | int iproc_pcie_remove(struct iproc_pcie *pcie) |
| 655 | { |
| 656 | pci_stop_root_bus(pcie->root_bus); |
| 657 | pci_remove_root_bus(pcie->root_bus); |
| 658 | |
Ray Jui | 3bc2b23 | 2016-01-06 18:04:35 -0600 | [diff] [blame] | 659 | iproc_pcie_msi_disable(pcie); |
| 660 | |
Markus Elfring | 93972d1 | 2015-06-28 16:42:04 +0200 | [diff] [blame] | 661 | phy_power_off(pcie->phy); |
| 662 | phy_exit(pcie->phy); |
Ray Jui | 1fb37a8 | 2015-04-08 11:21:35 -0700 | [diff] [blame] | 663 | |
| 664 | return 0; |
| 665 | } |
| 666 | EXPORT_SYMBOL(iproc_pcie_remove); |
| 667 | |
| 668 | MODULE_AUTHOR("Ray Jui <rjui@broadcom.com>"); |
| 669 | MODULE_DESCRIPTION("Broadcom iPROC PCIe common driver"); |
| 670 | MODULE_LICENSE("GPL v2"); |