Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 1 | /* |
| 2 | * PCIe host controller driver for Axis ARTPEC-6 SoC |
| 3 | * |
Paul Gortmaker | 58bdaa1 | 2016-07-02 19:13:22 -0400 | [diff] [blame] | 4 | * Author: Niklas Cassel <niklas.cassel@axis.com> |
| 5 | * |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 6 | * Based on work done by Phil Edworthy <phil@edworthys.org> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/delay.h> |
| 14 | #include <linux/kernel.h> |
Paul Gortmaker | 58bdaa1 | 2016-07-02 19:13:22 -0400 | [diff] [blame] | 15 | #include <linux/init.h> |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 16 | #include <linux/pci.h> |
| 17 | #include <linux/platform_device.h> |
| 18 | #include <linux/resource.h> |
| 19 | #include <linux/signal.h> |
| 20 | #include <linux/types.h> |
| 21 | #include <linux/interrupt.h> |
| 22 | #include <linux/mfd/syscon.h> |
| 23 | #include <linux/regmap.h> |
| 24 | |
| 25 | #include "pcie-designware.h" |
| 26 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 27 | #define to_artpec6_pcie(x) dev_get_drvdata((x)->dev) |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 28 | |
| 29 | struct artpec6_pcie { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 30 | struct dw_pcie *pci; |
Bjorn Helgaas | 7c62efc | 2016-10-06 13:30:56 -0500 | [diff] [blame] | 31 | struct regmap *regmap; /* DT axis,syscon-pcie */ |
| 32 | void __iomem *phy_base; /* DT phy */ |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 33 | }; |
| 34 | |
| 35 | /* PCIe Port Logic registers (memory-mapped) */ |
| 36 | #define PL_OFFSET 0x700 |
| 37 | #define PCIE_PHY_DEBUG_R0 (PL_OFFSET + 0x28) |
| 38 | #define PCIE_PHY_DEBUG_R1 (PL_OFFSET + 0x2c) |
| 39 | |
| 40 | #define MISC_CONTROL_1_OFF (PL_OFFSET + 0x1bc) |
| 41 | #define DBI_RO_WR_EN 1 |
| 42 | |
| 43 | /* ARTPEC-6 specific registers */ |
| 44 | #define PCIECFG 0x18 |
| 45 | #define PCIECFG_DBG_OEN (1 << 24) |
| 46 | #define PCIECFG_CORE_RESET_REQ (1 << 21) |
| 47 | #define PCIECFG_LTSSM_ENABLE (1 << 20) |
| 48 | #define PCIECFG_CLKREQ_B (1 << 11) |
| 49 | #define PCIECFG_REFCLK_ENABLE (1 << 10) |
| 50 | #define PCIECFG_PLL_ENABLE (1 << 9) |
| 51 | #define PCIECFG_PCLK_ENABLE (1 << 8) |
| 52 | #define PCIECFG_RISRCREN (1 << 4) |
| 53 | #define PCIECFG_MODE_TX_DRV_EN (1 << 3) |
| 54 | #define PCIECFG_CISRREN (1 << 2) |
| 55 | #define PCIECFG_MACRO_ENABLE (1 << 0) |
| 56 | |
| 57 | #define NOCCFG 0x40 |
| 58 | #define NOCCFG_ENABLE_CLK_PCIE (1 << 4) |
| 59 | #define NOCCFG_POWER_PCIE_IDLEACK (1 << 3) |
| 60 | #define NOCCFG_POWER_PCIE_IDLE (1 << 2) |
| 61 | #define NOCCFG_POWER_PCIE_IDLEREQ (1 << 1) |
| 62 | |
| 63 | #define PHY_STATUS 0x118 |
| 64 | #define PHY_COSPLLLOCK (1 << 0) |
| 65 | |
| 66 | #define ARTPEC6_CPU_TO_BUS_ADDR 0x0fffffff |
| 67 | |
Bjorn Helgaas | 26fbcc5 | 2016-10-06 13:30:56 -0500 | [diff] [blame] | 68 | static u32 artpec6_pcie_readl(struct artpec6_pcie *artpec6_pcie, u32 offset) |
| 69 | { |
| 70 | u32 val; |
| 71 | |
| 72 | regmap_read(artpec6_pcie->regmap, offset, &val); |
| 73 | return val; |
| 74 | } |
| 75 | |
| 76 | static void artpec6_pcie_writel(struct artpec6_pcie *artpec6_pcie, u32 offset, u32 val) |
| 77 | { |
| 78 | regmap_write(artpec6_pcie->regmap, offset, val); |
| 79 | } |
| 80 | |
Kishon Vijay Abraham I | 62c5549f | 2017-03-13 19:13:24 +0530 | [diff] [blame] | 81 | static u64 artpec6_pcie_cpu_addr_fixup(u64 pci_addr) |
| 82 | { |
| 83 | return pci_addr & ARTPEC6_CPU_TO_BUS_ADDR; |
| 84 | } |
| 85 | |
Bjorn Helgaas | b6f5f43 | 2016-10-06 13:30:56 -0500 | [diff] [blame] | 86 | static int artpec6_pcie_establish_link(struct artpec6_pcie *artpec6_pcie) |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 87 | { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 88 | struct dw_pcie *pci = artpec6_pcie->pci; |
| 89 | struct pcie_port *pp = &pci->pp; |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 90 | u32 val; |
| 91 | unsigned int retries; |
| 92 | |
| 93 | /* Hold DW core in reset */ |
Bjorn Helgaas | 26fbcc5 | 2016-10-06 13:30:56 -0500 | [diff] [blame] | 94 | val = artpec6_pcie_readl(artpec6_pcie, PCIECFG); |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 95 | val |= PCIECFG_CORE_RESET_REQ; |
Bjorn Helgaas | 26fbcc5 | 2016-10-06 13:30:56 -0500 | [diff] [blame] | 96 | artpec6_pcie_writel(artpec6_pcie, PCIECFG, val); |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 97 | |
Bjorn Helgaas | 26fbcc5 | 2016-10-06 13:30:56 -0500 | [diff] [blame] | 98 | val = artpec6_pcie_readl(artpec6_pcie, PCIECFG); |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 99 | val |= PCIECFG_RISRCREN | /* Receiver term. 50 Ohm */ |
| 100 | PCIECFG_MODE_TX_DRV_EN | |
| 101 | PCIECFG_CISRREN | /* Reference clock term. 100 Ohm */ |
| 102 | PCIECFG_MACRO_ENABLE; |
| 103 | val |= PCIECFG_REFCLK_ENABLE; |
| 104 | val &= ~PCIECFG_DBG_OEN; |
| 105 | val &= ~PCIECFG_CLKREQ_B; |
Bjorn Helgaas | 26fbcc5 | 2016-10-06 13:30:56 -0500 | [diff] [blame] | 106 | artpec6_pcie_writel(artpec6_pcie, PCIECFG, val); |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 107 | usleep_range(5000, 6000); |
| 108 | |
Bjorn Helgaas | 26fbcc5 | 2016-10-06 13:30:56 -0500 | [diff] [blame] | 109 | val = artpec6_pcie_readl(artpec6_pcie, NOCCFG); |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 110 | val |= NOCCFG_ENABLE_CLK_PCIE; |
Bjorn Helgaas | 26fbcc5 | 2016-10-06 13:30:56 -0500 | [diff] [blame] | 111 | artpec6_pcie_writel(artpec6_pcie, NOCCFG, val); |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 112 | usleep_range(20, 30); |
| 113 | |
Bjorn Helgaas | 26fbcc5 | 2016-10-06 13:30:56 -0500 | [diff] [blame] | 114 | val = artpec6_pcie_readl(artpec6_pcie, PCIECFG); |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 115 | val |= PCIECFG_PCLK_ENABLE | PCIECFG_PLL_ENABLE; |
Bjorn Helgaas | 26fbcc5 | 2016-10-06 13:30:56 -0500 | [diff] [blame] | 116 | artpec6_pcie_writel(artpec6_pcie, PCIECFG, val); |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 117 | usleep_range(6000, 7000); |
| 118 | |
Bjorn Helgaas | 26fbcc5 | 2016-10-06 13:30:56 -0500 | [diff] [blame] | 119 | val = artpec6_pcie_readl(artpec6_pcie, NOCCFG); |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 120 | val &= ~NOCCFG_POWER_PCIE_IDLEREQ; |
Bjorn Helgaas | 26fbcc5 | 2016-10-06 13:30:56 -0500 | [diff] [blame] | 121 | artpec6_pcie_writel(artpec6_pcie, NOCCFG, val); |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 122 | |
| 123 | retries = 50; |
| 124 | do { |
| 125 | usleep_range(1000, 2000); |
Bjorn Helgaas | 26fbcc5 | 2016-10-06 13:30:56 -0500 | [diff] [blame] | 126 | val = artpec6_pcie_readl(artpec6_pcie, NOCCFG); |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 127 | retries--; |
| 128 | } while (retries && |
| 129 | (val & (NOCCFG_POWER_PCIE_IDLEACK | NOCCFG_POWER_PCIE_IDLE))); |
| 130 | |
| 131 | retries = 50; |
| 132 | do { |
| 133 | usleep_range(1000, 2000); |
| 134 | val = readl(artpec6_pcie->phy_base + PHY_STATUS); |
| 135 | retries--; |
| 136 | } while (retries && !(val & PHY_COSPLLLOCK)); |
| 137 | |
| 138 | /* Take DW core out of reset */ |
Bjorn Helgaas | 26fbcc5 | 2016-10-06 13:30:56 -0500 | [diff] [blame] | 139 | val = artpec6_pcie_readl(artpec6_pcie, PCIECFG); |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 140 | val &= ~PCIECFG_CORE_RESET_REQ; |
Bjorn Helgaas | 26fbcc5 | 2016-10-06 13:30:56 -0500 | [diff] [blame] | 141 | artpec6_pcie_writel(artpec6_pcie, PCIECFG, val); |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 142 | usleep_range(100, 200); |
| 143 | |
| 144 | /* |
| 145 | * Enable writing to config regs. This is required as the Synopsys |
| 146 | * driver changes the class code. That register needs DBI write enable. |
| 147 | */ |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 148 | dw_pcie_writel_dbi(pci, MISC_CONTROL_1_OFF, DBI_RO_WR_EN); |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 149 | |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 150 | /* setup root complex */ |
| 151 | dw_pcie_setup_rc(pp); |
| 152 | |
| 153 | /* assert LTSSM enable */ |
Bjorn Helgaas | 26fbcc5 | 2016-10-06 13:30:56 -0500 | [diff] [blame] | 154 | val = artpec6_pcie_readl(artpec6_pcie, PCIECFG); |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 155 | val |= PCIECFG_LTSSM_ENABLE; |
Bjorn Helgaas | 26fbcc5 | 2016-10-06 13:30:56 -0500 | [diff] [blame] | 156 | artpec6_pcie_writel(artpec6_pcie, PCIECFG, val); |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 157 | |
| 158 | /* check if the link is up or not */ |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 159 | if (!dw_pcie_wait_for_link(pci)) |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 160 | return 0; |
| 161 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 162 | dev_dbg(pci->dev, "DEBUG_R0: 0x%08x, DEBUG_R1: 0x%08x\n", |
| 163 | dw_pcie_readl_dbi(pci, PCIE_PHY_DEBUG_R0), |
| 164 | dw_pcie_readl_dbi(pci, PCIE_PHY_DEBUG_R1)); |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 165 | |
| 166 | return -ETIMEDOUT; |
| 167 | } |
| 168 | |
Bjorn Helgaas | b6f5f43 | 2016-10-06 13:30:56 -0500 | [diff] [blame] | 169 | static void artpec6_pcie_enable_interrupts(struct artpec6_pcie *artpec6_pcie) |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 170 | { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 171 | struct dw_pcie *pci = artpec6_pcie->pci; |
| 172 | struct pcie_port *pp = &pci->pp; |
Bjorn Helgaas | b6f5f43 | 2016-10-06 13:30:56 -0500 | [diff] [blame] | 173 | |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 174 | if (IS_ENABLED(CONFIG_PCI_MSI)) |
| 175 | dw_pcie_msi_init(pp); |
| 176 | } |
| 177 | |
Bjorn Andersson | 4a30176 | 2017-07-15 23:39:45 -0700 | [diff] [blame^] | 178 | static int artpec6_pcie_host_init(struct pcie_port *pp) |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 179 | { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 180 | struct dw_pcie *pci = to_dw_pcie_from_pp(pp); |
| 181 | struct artpec6_pcie *artpec6_pcie = to_artpec6_pcie(pci); |
Bjorn Helgaas | b6f5f43 | 2016-10-06 13:30:56 -0500 | [diff] [blame] | 182 | |
| 183 | artpec6_pcie_establish_link(artpec6_pcie); |
| 184 | artpec6_pcie_enable_interrupts(artpec6_pcie); |
Bjorn Andersson | 4a30176 | 2017-07-15 23:39:45 -0700 | [diff] [blame^] | 185 | |
| 186 | return 0; |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 187 | } |
| 188 | |
Jisheng Zhang | 4ab2e7c | 2017-06-05 16:53:46 +0800 | [diff] [blame] | 189 | static const struct dw_pcie_host_ops artpec6_pcie_host_ops = { |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 190 | .host_init = artpec6_pcie_host_init, |
| 191 | }; |
| 192 | |
| 193 | static irqreturn_t artpec6_pcie_msi_handler(int irq, void *arg) |
| 194 | { |
Bjorn Helgaas | b6f5f43 | 2016-10-06 13:30:56 -0500 | [diff] [blame] | 195 | struct artpec6_pcie *artpec6_pcie = arg; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 196 | struct dw_pcie *pci = artpec6_pcie->pci; |
| 197 | struct pcie_port *pp = &pci->pp; |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 198 | |
| 199 | return dw_handle_msi_irq(pp); |
| 200 | } |
| 201 | |
Bjorn Helgaas | b6f5f43 | 2016-10-06 13:30:56 -0500 | [diff] [blame] | 202 | static int artpec6_add_pcie_port(struct artpec6_pcie *artpec6_pcie, |
Niklas Cassel | b58ddf1 | 2016-09-09 09:45:30 +0200 | [diff] [blame] | 203 | struct platform_device *pdev) |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 204 | { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 205 | struct dw_pcie *pci = artpec6_pcie->pci; |
| 206 | struct pcie_port *pp = &pci->pp; |
| 207 | struct device *dev = pci->dev; |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 208 | int ret; |
| 209 | |
| 210 | if (IS_ENABLED(CONFIG_PCI_MSI)) { |
| 211 | pp->msi_irq = platform_get_irq_byname(pdev, "msi"); |
| 212 | if (pp->msi_irq <= 0) { |
Bjorn Helgaas | e6f3115 | 2016-10-06 13:30:57 -0500 | [diff] [blame] | 213 | dev_err(dev, "failed to get MSI irq\n"); |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 214 | return -ENODEV; |
| 215 | } |
| 216 | |
Bjorn Helgaas | e6f3115 | 2016-10-06 13:30:57 -0500 | [diff] [blame] | 217 | ret = devm_request_irq(dev, pp->msi_irq, |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 218 | artpec6_pcie_msi_handler, |
| 219 | IRQF_SHARED | IRQF_NO_THREAD, |
Bjorn Helgaas | b6f5f43 | 2016-10-06 13:30:56 -0500 | [diff] [blame] | 220 | "artpec6-pcie-msi", artpec6_pcie); |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 221 | if (ret) { |
Bjorn Helgaas | e6f3115 | 2016-10-06 13:30:57 -0500 | [diff] [blame] | 222 | dev_err(dev, "failed to request MSI irq\n"); |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 223 | return ret; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | pp->root_bus_nr = -1; |
| 228 | pp->ops = &artpec6_pcie_host_ops; |
| 229 | |
| 230 | ret = dw_pcie_host_init(pp); |
| 231 | if (ret) { |
Bjorn Helgaas | e6f3115 | 2016-10-06 13:30:57 -0500 | [diff] [blame] | 232 | dev_err(dev, "failed to initialize host\n"); |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 233 | return ret; |
| 234 | } |
| 235 | |
| 236 | return 0; |
| 237 | } |
| 238 | |
Niklas Cassel | 794a860 | 2017-04-03 17:35:12 -0500 | [diff] [blame] | 239 | static const struct dw_pcie_ops dw_pcie_ops = { |
Kishon Vijay Abraham I | 62c5549f | 2017-03-13 19:13:24 +0530 | [diff] [blame] | 240 | .cpu_addr_fixup = artpec6_pcie_cpu_addr_fixup, |
Niklas Cassel | 794a860 | 2017-04-03 17:35:12 -0500 | [diff] [blame] | 241 | }; |
| 242 | |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 243 | static int artpec6_pcie_probe(struct platform_device *pdev) |
| 244 | { |
Bjorn Helgaas | e6f3115 | 2016-10-06 13:30:57 -0500 | [diff] [blame] | 245 | struct device *dev = &pdev->dev; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 246 | struct dw_pcie *pci; |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 247 | struct artpec6_pcie *artpec6_pcie; |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 248 | struct resource *dbi_base; |
| 249 | struct resource *phy_base; |
| 250 | int ret; |
| 251 | |
Bjorn Helgaas | e6f3115 | 2016-10-06 13:30:57 -0500 | [diff] [blame] | 252 | artpec6_pcie = devm_kzalloc(dev, sizeof(*artpec6_pcie), GFP_KERNEL); |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 253 | if (!artpec6_pcie) |
| 254 | return -ENOMEM; |
| 255 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 256 | pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL); |
| 257 | if (!pci) |
| 258 | return -ENOMEM; |
| 259 | |
| 260 | pci->dev = dev; |
Niklas Cassel | 794a860 | 2017-04-03 17:35:12 -0500 | [diff] [blame] | 261 | pci->ops = &dw_pcie_ops; |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 262 | |
Guenter Roeck | c046406 | 2017-02-25 02:08:12 -0800 | [diff] [blame] | 263 | artpec6_pcie->pci = pci; |
| 264 | |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 265 | dbi_base = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dbi"); |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 266 | pci->dbi_base = devm_ioremap_resource(dev, dbi_base); |
| 267 | if (IS_ERR(pci->dbi_base)) |
| 268 | return PTR_ERR(pci->dbi_base); |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 269 | |
| 270 | phy_base = platform_get_resource_byname(pdev, IORESOURCE_MEM, "phy"); |
Bjorn Helgaas | e6f3115 | 2016-10-06 13:30:57 -0500 | [diff] [blame] | 271 | artpec6_pcie->phy_base = devm_ioremap_resource(dev, phy_base); |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 272 | if (IS_ERR(artpec6_pcie->phy_base)) |
| 273 | return PTR_ERR(artpec6_pcie->phy_base); |
| 274 | |
| 275 | artpec6_pcie->regmap = |
Bjorn Helgaas | e6f3115 | 2016-10-06 13:30:57 -0500 | [diff] [blame] | 276 | syscon_regmap_lookup_by_phandle(dev->of_node, |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 277 | "axis,syscon-pcie"); |
| 278 | if (IS_ERR(artpec6_pcie->regmap)) |
| 279 | return PTR_ERR(artpec6_pcie->regmap); |
| 280 | |
Kishon Vijay Abraham I | 9bcf0a6 | 2017-02-15 18:48:11 +0530 | [diff] [blame] | 281 | platform_set_drvdata(pdev, artpec6_pcie); |
| 282 | |
Bjorn Helgaas | b6f5f43 | 2016-10-06 13:30:56 -0500 | [diff] [blame] | 283 | ret = artpec6_add_pcie_port(artpec6_pcie, pdev); |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 284 | if (ret < 0) |
| 285 | return ret; |
| 286 | |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 287 | return 0; |
| 288 | } |
| 289 | |
| 290 | static const struct of_device_id artpec6_pcie_of_match[] = { |
| 291 | { .compatible = "axis,artpec6-pcie", }, |
| 292 | {}, |
| 293 | }; |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 294 | |
| 295 | static struct platform_driver artpec6_pcie_driver = { |
| 296 | .probe = artpec6_pcie_probe, |
| 297 | .driver = { |
| 298 | .name = "artpec6-pcie", |
| 299 | .of_match_table = artpec6_pcie_of_match, |
Brian Norris | a5f40e80 | 2017-04-20 15:36:25 -0500 | [diff] [blame] | 300 | .suppress_bind_attrs = true, |
Niklas Cassel | a3cbfae | 2016-05-09 13:49:03 +0200 | [diff] [blame] | 301 | }, |
| 302 | }; |
Paul Gortmaker | 58bdaa1 | 2016-07-02 19:13:22 -0400 | [diff] [blame] | 303 | builtin_platform_driver(artpec6_pcie_driver); |