Bjorn Helgaas | 8cfab3c | 2018-01-26 12:50:27 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 2 | /* |
| 3 | * PCIe host controller driver for Marvell Armada-8K SoCs |
| 4 | * |
| 5 | * Armada-8K PCIe Glue Layer Source Code |
| 6 | * |
| 7 | * Copyright (C) 2016 Marvell Technology Group Ltd. |
| 8 | * |
Paul Gortmaker | 0e6f98c | 2016-07-02 19:13:21 -0400 | [diff] [blame] | 9 | * Author: Yehuda Yitshak <yehuday@marvell.com> |
| 10 | * Author: Shadi Ammouri <shadi@marvell.com> |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include <linux/clk.h> |
| 14 | #include <linux/delay.h> |
| 15 | #include <linux/interrupt.h> |
| 16 | #include <linux/kernel.h> |
Paul Gortmaker | 0e6f98c | 2016-07-02 19:13:21 -0400 | [diff] [blame] | 17 | #include <linux/init.h> |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 18 | #include <linux/of.h> |
| 19 | #include <linux/pci.h> |
| 20 | #include <linux/phy/phy.h> |
| 21 | #include <linux/platform_device.h> |
| 22 | #include <linux/resource.h> |
| 23 | #include <linux/of_pci.h> |
| 24 | #include <linux/of_irq.h> |
| 25 | |
| 26 | #include "pcie-designware.h" |
| 27 | |
| 28 | struct armada8k_pcie { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 29 | struct dw_pcie *pci; |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 30 | struct clk *clk; |
Gregory CLEMENT | 2435cdd | 2018-02-28 17:35:30 +0100 | [diff] [blame] | 31 | struct clk *clk_reg; |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 32 | }; |
| 33 | |
| 34 | #define PCIE_VENDOR_REGS_OFFSET 0x8000 |
| 35 | |
Bjorn Helgaas | 74e6907 | 2016-10-06 13:29:59 -0500 | [diff] [blame] | 36 | #define PCIE_GLOBAL_CONTROL_REG (PCIE_VENDOR_REGS_OFFSET + 0x0) |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 37 | #define PCIE_APP_LTSSM_EN BIT(2) |
| 38 | #define PCIE_DEVICE_TYPE_SHIFT 4 |
| 39 | #define PCIE_DEVICE_TYPE_MASK 0xF |
| 40 | #define PCIE_DEVICE_TYPE_RC 0x4 /* Root complex */ |
| 41 | |
Bjorn Helgaas | 74e6907 | 2016-10-06 13:29:59 -0500 | [diff] [blame] | 42 | #define PCIE_GLOBAL_STATUS_REG (PCIE_VENDOR_REGS_OFFSET + 0x8) |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 43 | #define PCIE_GLB_STS_RDLH_LINK_UP BIT(1) |
| 44 | #define PCIE_GLB_STS_PHY_LINK_UP BIT(9) |
| 45 | |
Bjorn Helgaas | 74e6907 | 2016-10-06 13:29:59 -0500 | [diff] [blame] | 46 | #define PCIE_GLOBAL_INT_CAUSE1_REG (PCIE_VENDOR_REGS_OFFSET + 0x1C) |
| 47 | #define PCIE_GLOBAL_INT_MASK1_REG (PCIE_VENDOR_REGS_OFFSET + 0x20) |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 48 | #define PCIE_INT_A_ASSERT_MASK BIT(9) |
| 49 | #define PCIE_INT_B_ASSERT_MASK BIT(10) |
| 50 | #define PCIE_INT_C_ASSERT_MASK BIT(11) |
| 51 | #define PCIE_INT_D_ASSERT_MASK BIT(12) |
| 52 | |
Bjorn Helgaas | 74e6907 | 2016-10-06 13:29:59 -0500 | [diff] [blame] | 53 | #define PCIE_ARCACHE_TRC_REG (PCIE_VENDOR_REGS_OFFSET + 0x50) |
| 54 | #define PCIE_AWCACHE_TRC_REG (PCIE_VENDOR_REGS_OFFSET + 0x54) |
| 55 | #define PCIE_ARUSER_REG (PCIE_VENDOR_REGS_OFFSET + 0x5C) |
| 56 | #define PCIE_AWUSER_REG (PCIE_VENDOR_REGS_OFFSET + 0x60) |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 57 | /* |
| 58 | * AR/AW Cache defauls: Normal memory, Write-Back, Read / Write |
| 59 | * allocate |
| 60 | */ |
| 61 | #define ARCACHE_DEFAULT_VALUE 0x3511 |
| 62 | #define AWCACHE_DEFAULT_VALUE 0x5311 |
| 63 | |
| 64 | #define DOMAIN_OUTER_SHAREABLE 0x2 |
| 65 | #define AX_USER_DOMAIN_MASK 0x3 |
| 66 | #define AX_USER_DOMAIN_SHIFT 4 |
| 67 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 68 | #define to_armada8k_pcie(x) dev_get_drvdata((x)->dev) |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 69 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 70 | static int armada8k_pcie_link_up(struct dw_pcie *pci) |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 71 | { |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 72 | u32 reg; |
| 73 | u32 mask = PCIE_GLB_STS_RDLH_LINK_UP | PCIE_GLB_STS_PHY_LINK_UP; |
| 74 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 75 | reg = dw_pcie_readl_dbi(pci, PCIE_GLOBAL_STATUS_REG); |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 76 | |
| 77 | if ((reg & mask) == mask) |
| 78 | return 1; |
| 79 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 80 | dev_dbg(pci->dev, "No link detected (Global-Status: 0x%08x).\n", reg); |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 81 | return 0; |
| 82 | } |
| 83 | |
Bjorn Helgaas | b2d6fd7 | 2016-10-06 13:30:00 -0500 | [diff] [blame] | 84 | static void armada8k_pcie_establish_link(struct armada8k_pcie *pcie) |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 85 | { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 86 | struct dw_pcie *pci = pcie->pci; |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 87 | u32 reg; |
| 88 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 89 | if (!dw_pcie_link_up(pci)) { |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 90 | /* Disable LTSSM state machine to enable configuration */ |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 91 | reg = dw_pcie_readl_dbi(pci, PCIE_GLOBAL_CONTROL_REG); |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 92 | reg &= ~(PCIE_APP_LTSSM_EN); |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 93 | dw_pcie_writel_dbi(pci, PCIE_GLOBAL_CONTROL_REG, reg); |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | /* Set the device to root complex mode */ |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 97 | reg = dw_pcie_readl_dbi(pci, PCIE_GLOBAL_CONTROL_REG); |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 98 | reg &= ~(PCIE_DEVICE_TYPE_MASK << PCIE_DEVICE_TYPE_SHIFT); |
| 99 | reg |= PCIE_DEVICE_TYPE_RC << PCIE_DEVICE_TYPE_SHIFT; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 100 | dw_pcie_writel_dbi(pci, PCIE_GLOBAL_CONTROL_REG, reg); |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 101 | |
| 102 | /* Set the PCIe master AxCache attributes */ |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 103 | dw_pcie_writel_dbi(pci, PCIE_ARCACHE_TRC_REG, ARCACHE_DEFAULT_VALUE); |
| 104 | dw_pcie_writel_dbi(pci, PCIE_AWCACHE_TRC_REG, AWCACHE_DEFAULT_VALUE); |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 105 | |
| 106 | /* Set the PCIe master AxDomain attributes */ |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 107 | reg = dw_pcie_readl_dbi(pci, PCIE_ARUSER_REG); |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 108 | reg &= ~(AX_USER_DOMAIN_MASK << AX_USER_DOMAIN_SHIFT); |
| 109 | reg |= DOMAIN_OUTER_SHAREABLE << AX_USER_DOMAIN_SHIFT; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 110 | dw_pcie_writel_dbi(pci, PCIE_ARUSER_REG, reg); |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 111 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 112 | reg = dw_pcie_readl_dbi(pci, PCIE_AWUSER_REG); |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 113 | reg &= ~(AX_USER_DOMAIN_MASK << AX_USER_DOMAIN_SHIFT); |
| 114 | reg |= DOMAIN_OUTER_SHAREABLE << AX_USER_DOMAIN_SHIFT; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 115 | dw_pcie_writel_dbi(pci, PCIE_AWUSER_REG, reg); |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 116 | |
| 117 | /* Enable INT A-D interrupts */ |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 118 | reg = dw_pcie_readl_dbi(pci, PCIE_GLOBAL_INT_MASK1_REG); |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 119 | reg |= PCIE_INT_A_ASSERT_MASK | PCIE_INT_B_ASSERT_MASK | |
| 120 | PCIE_INT_C_ASSERT_MASK | PCIE_INT_D_ASSERT_MASK; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 121 | dw_pcie_writel_dbi(pci, PCIE_GLOBAL_INT_MASK1_REG, reg); |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 122 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 123 | if (!dw_pcie_link_up(pci)) { |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 124 | /* Configuration done. Start LTSSM */ |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 125 | reg = dw_pcie_readl_dbi(pci, PCIE_GLOBAL_CONTROL_REG); |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 126 | reg |= PCIE_APP_LTSSM_EN; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 127 | dw_pcie_writel_dbi(pci, PCIE_GLOBAL_CONTROL_REG, reg); |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | /* Wait until the link becomes active again */ |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 131 | if (dw_pcie_wait_for_link(pci)) |
| 132 | dev_err(pci->dev, "Link not up after reconfiguration\n"); |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 133 | } |
| 134 | |
Bjorn Andersson | 4a30176 | 2017-07-15 23:39:45 -0700 | [diff] [blame] | 135 | static int armada8k_pcie_host_init(struct pcie_port *pp) |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 136 | { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 137 | struct dw_pcie *pci = to_dw_pcie_from_pp(pp); |
| 138 | struct armada8k_pcie *pcie = to_armada8k_pcie(pci); |
Bjorn Helgaas | b2d6fd7 | 2016-10-06 13:30:00 -0500 | [diff] [blame] | 139 | |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 140 | dw_pcie_setup_rc(pp); |
Bjorn Helgaas | b2d6fd7 | 2016-10-06 13:30:00 -0500 | [diff] [blame] | 141 | armada8k_pcie_establish_link(pcie); |
Bjorn Andersson | 4a30176 | 2017-07-15 23:39:45 -0700 | [diff] [blame] | 142 | |
| 143 | return 0; |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | static irqreturn_t armada8k_pcie_irq_handler(int irq, void *arg) |
| 147 | { |
Bjorn Helgaas | b2d6fd7 | 2016-10-06 13:30:00 -0500 | [diff] [blame] | 148 | struct armada8k_pcie *pcie = arg; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 149 | struct dw_pcie *pci = pcie->pci; |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 150 | u32 val; |
| 151 | |
| 152 | /* |
| 153 | * Interrupts are directly handled by the device driver of the |
| 154 | * PCI device. However, they are also latched into the PCIe |
| 155 | * controller, so we simply discard them. |
| 156 | */ |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 157 | val = dw_pcie_readl_dbi(pci, PCIE_GLOBAL_INT_CAUSE1_REG); |
| 158 | dw_pcie_writel_dbi(pci, PCIE_GLOBAL_INT_CAUSE1_REG, val); |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 159 | |
| 160 | return IRQ_HANDLED; |
| 161 | } |
| 162 | |
Jisheng Zhang | 4ab2e7c | 2017-06-05 16:53:46 +0800 | [diff] [blame] | 163 | static const struct dw_pcie_host_ops armada8k_pcie_host_ops = { |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 164 | .host_init = armada8k_pcie_host_init, |
| 165 | }; |
| 166 | |
Bjorn Helgaas | b2d6fd7 | 2016-10-06 13:30:00 -0500 | [diff] [blame] | 167 | static int armada8k_add_pcie_port(struct armada8k_pcie *pcie, |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 168 | struct platform_device *pdev) |
| 169 | { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 170 | struct dw_pcie *pci = pcie->pci; |
| 171 | struct pcie_port *pp = &pci->pp; |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 172 | struct device *dev = &pdev->dev; |
| 173 | int ret; |
| 174 | |
| 175 | pp->root_bus_nr = -1; |
| 176 | pp->ops = &armada8k_pcie_host_ops; |
| 177 | |
| 178 | pp->irq = platform_get_irq(pdev, 0); |
Fabio Estevam | 0fe5f1c | 2017-08-31 14:52:03 -0300 | [diff] [blame] | 179 | if (pp->irq < 0) { |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 180 | dev_err(dev, "failed to get irq for port\n"); |
Fabio Estevam | 0fe5f1c | 2017-08-31 14:52:03 -0300 | [diff] [blame] | 181 | return pp->irq; |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | ret = devm_request_irq(dev, pp->irq, armada8k_pcie_irq_handler, |
Bjorn Helgaas | b2d6fd7 | 2016-10-06 13:30:00 -0500 | [diff] [blame] | 185 | IRQF_SHARED, "armada8k-pcie", pcie); |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 186 | if (ret) { |
| 187 | dev_err(dev, "failed to request irq %d\n", pp->irq); |
| 188 | return ret; |
| 189 | } |
| 190 | |
| 191 | ret = dw_pcie_host_init(pp); |
| 192 | if (ret) { |
| 193 | dev_err(dev, "failed to initialize host: %d\n", ret); |
| 194 | return ret; |
| 195 | } |
| 196 | |
| 197 | return 0; |
| 198 | } |
| 199 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 200 | static const struct dw_pcie_ops dw_pcie_ops = { |
| 201 | .link_up = armada8k_pcie_link_up, |
| 202 | }; |
| 203 | |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 204 | static int armada8k_pcie_probe(struct platform_device *pdev) |
| 205 | { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 206 | struct dw_pcie *pci; |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 207 | struct armada8k_pcie *pcie; |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 208 | struct device *dev = &pdev->dev; |
| 209 | struct resource *base; |
| 210 | int ret; |
| 211 | |
| 212 | pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL); |
| 213 | if (!pcie) |
| 214 | return -ENOMEM; |
| 215 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 216 | pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL); |
| 217 | if (!pci) |
| 218 | return -ENOMEM; |
| 219 | |
| 220 | pci->dev = dev; |
| 221 | pci->ops = &dw_pcie_ops; |
| 222 | |
Guenter Roeck | c046406 | 2017-02-25 02:08:12 -0800 | [diff] [blame] | 223 | pcie->pci = pci; |
| 224 | |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 225 | pcie->clk = devm_clk_get(dev, NULL); |
| 226 | if (IS_ERR(pcie->clk)) |
| 227 | return PTR_ERR(pcie->clk); |
| 228 | |
Fabio Estevam | e2e5d7b | 2017-07-22 17:25:19 -0300 | [diff] [blame] | 229 | ret = clk_prepare_enable(pcie->clk); |
| 230 | if (ret) |
| 231 | return ret; |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 232 | |
Gregory CLEMENT | 2435cdd | 2018-02-28 17:35:30 +0100 | [diff] [blame] | 233 | pcie->clk_reg = devm_clk_get(dev, "reg"); |
| 234 | if (pcie->clk_reg == ERR_PTR(-EPROBE_DEFER)) { |
| 235 | ret = -EPROBE_DEFER; |
| 236 | goto fail; |
| 237 | } |
| 238 | if (!IS_ERR(pcie->clk_reg)) { |
| 239 | ret = clk_prepare_enable(pcie->clk_reg); |
| 240 | if (ret) |
| 241 | goto fail_clkreg; |
| 242 | } |
| 243 | |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 244 | /* Get the dw-pcie unit configuration/control registers base. */ |
| 245 | base = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ctrl"); |
Lorenzo Pieralisi | 53dfa17 | 2017-04-19 17:49:04 +0100 | [diff] [blame] | 246 | pci->dbi_base = devm_pci_remap_cfg_resource(dev, base); |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 247 | if (IS_ERR(pci->dbi_base)) { |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 248 | dev_err(dev, "couldn't remap regs base %p\n", base); |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 249 | ret = PTR_ERR(pci->dbi_base); |
Gregory CLEMENT | 2435cdd | 2018-02-28 17:35:30 +0100 | [diff] [blame] | 250 | goto fail_clkreg; |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 251 | } |
| 252 | |
Kishon Vijay Abraham I | 9bcf0a6 | 2017-02-15 18:48:11 +0530 | [diff] [blame] | 253 | platform_set_drvdata(pdev, pcie); |
| 254 | |
Bjorn Helgaas | b2d6fd7 | 2016-10-06 13:30:00 -0500 | [diff] [blame] | 255 | ret = armada8k_add_pcie_port(pcie, pdev); |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 256 | if (ret) |
Gregory CLEMENT | 2435cdd | 2018-02-28 17:35:30 +0100 | [diff] [blame] | 257 | goto fail_clkreg; |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 258 | |
| 259 | return 0; |
| 260 | |
Gregory CLEMENT | 2435cdd | 2018-02-28 17:35:30 +0100 | [diff] [blame] | 261 | fail_clkreg: |
| 262 | clk_disable_unprepare(pcie->clk_reg); |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 263 | fail: |
Gregory CLEMENT | 5dcd7f1 | 2018-02-28 17:35:29 +0100 | [diff] [blame] | 264 | clk_disable_unprepare(pcie->clk); |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 265 | |
| 266 | return ret; |
| 267 | } |
| 268 | |
| 269 | static const struct of_device_id armada8k_pcie_of_match[] = { |
| 270 | { .compatible = "marvell,armada8k-pcie", }, |
| 271 | {}, |
| 272 | }; |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 273 | |
| 274 | static struct platform_driver armada8k_pcie_driver = { |
| 275 | .probe = armada8k_pcie_probe, |
| 276 | .driver = { |
| 277 | .name = "armada8k-pcie", |
| 278 | .of_match_table = of_match_ptr(armada8k_pcie_of_match), |
Brian Norris | a5f40e8 | 2017-04-20 15:36:25 -0500 | [diff] [blame] | 279 | .suppress_bind_attrs = true, |
Thomas Petazzoni | 1c52a51 | 2016-04-26 10:31:46 +0200 | [diff] [blame] | 280 | }, |
| 281 | }; |
Paul Gortmaker | 0e6f98c | 2016-07-02 19:13:21 -0400 | [diff] [blame] | 282 | builtin_platform_driver(armada8k_pcie_driver); |