Bjorn Helgaas | 8cfab3c | 2018-01-26 12:50:27 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 2 | /* |
| 3 | * PCIe host controller driver for Freescale i.MX6 SoCs |
| 4 | * |
| 5 | * Copyright (C) 2013 Kosagi |
| 6 | * http://www.kosagi.com |
| 7 | * |
| 8 | * Author: Sean Cross <xobs@kosagi.com> |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <linux/clk.h> |
| 12 | #include <linux/delay.h> |
| 13 | #include <linux/gpio.h> |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/mfd/syscon.h> |
| 16 | #include <linux/mfd/syscon/imx6q-iomuxc-gpr.h> |
Andrey Smirnov | 9b3fe67 | 2017-03-28 08:42:49 -0700 | [diff] [blame] | 17 | #include <linux/mfd/syscon/imx7-iomuxc-gpr.h> |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 18 | #include <linux/module.h> |
| 19 | #include <linux/of_gpio.h> |
Andrey Smirnov | e6f1fef | 2016-05-02 14:08:21 -0500 | [diff] [blame] | 20 | #include <linux/of_device.h> |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 21 | #include <linux/pci.h> |
| 22 | #include <linux/platform_device.h> |
| 23 | #include <linux/regmap.h> |
Quentin Schulz | c26ebe9 | 2017-06-08 10:07:42 +0200 | [diff] [blame] | 24 | #include <linux/regulator/consumer.h> |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 25 | #include <linux/resource.h> |
| 26 | #include <linux/signal.h> |
| 27 | #include <linux/types.h> |
Lucas Stach | d1dc974 | 2014-03-28 17:52:59 +0100 | [diff] [blame] | 28 | #include <linux/interrupt.h> |
Andrey Smirnov | 9b3fe67 | 2017-03-28 08:42:49 -0700 | [diff] [blame] | 29 | #include <linux/reset.h> |
Leonard Crestez | 3f7ccee | 2018-10-08 18:06:21 +0000 | [diff] [blame] | 30 | #include <linux/pm_domain.h> |
| 31 | #include <linux/pm_runtime.h> |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 32 | |
| 33 | #include "pcie-designware.h" |
| 34 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 35 | #define to_imx6_pcie(x) dev_get_drvdata((x)->dev) |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 36 | |
Andrey Smirnov | e6f1fef | 2016-05-02 14:08:21 -0500 | [diff] [blame] | 37 | enum imx6_pcie_variants { |
| 38 | IMX6Q, |
Andrey Smirnov | 4d31c61 | 2016-05-02 14:09:10 -0500 | [diff] [blame] | 39 | IMX6SX, |
| 40 | IMX6QP, |
Andrey Smirnov | 9b3fe67 | 2017-03-28 08:42:49 -0700 | [diff] [blame] | 41 | IMX7D, |
Andrey Smirnov | e6f1fef | 2016-05-02 14:08:21 -0500 | [diff] [blame] | 42 | }; |
| 43 | |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 44 | struct imx6_pcie { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 45 | struct dw_pcie *pci; |
Fabio Estevam | b2d7a9c | 2016-03-28 18:45:36 -0300 | [diff] [blame] | 46 | int reset_gpio; |
Petr Štetiar | 3ea8529a | 2016-04-19 19:42:07 -0500 | [diff] [blame] | 47 | bool gpio_active_high; |
Lucas Stach | 5752613 | 2014-03-28 17:52:55 +0100 | [diff] [blame] | 48 | struct clk *pcie_bus; |
| 49 | struct clk *pcie_phy; |
Christoph Fritz | e3c06cd | 2016-04-05 16:53:27 -0500 | [diff] [blame] | 50 | struct clk *pcie_inbound_axi; |
Lucas Stach | 5752613 | 2014-03-28 17:52:55 +0100 | [diff] [blame] | 51 | struct clk *pcie; |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 52 | struct regmap *iomuxc_gpr; |
Andrey Smirnov | 9b3fe67 | 2017-03-28 08:42:49 -0700 | [diff] [blame] | 53 | struct reset_control *pciephy_reset; |
| 54 | struct reset_control *apps_reset; |
Leonard Crestez | f4e833b | 2018-07-19 17:02:10 +0300 | [diff] [blame] | 55 | struct reset_control *turnoff_reset; |
Andrey Smirnov | e6f1fef | 2016-05-02 14:08:21 -0500 | [diff] [blame] | 56 | enum imx6_pcie_variants variant; |
Justin Waters | 28e3abe | 2016-01-15 10:24:35 -0500 | [diff] [blame] | 57 | u32 tx_deemph_gen1; |
| 58 | u32 tx_deemph_gen2_3p5db; |
| 59 | u32 tx_deemph_gen2_6db; |
| 60 | u32 tx_swing_full; |
| 61 | u32 tx_swing_low; |
Tim Harvey | a5fcec4 | 2016-04-19 19:52:44 -0500 | [diff] [blame] | 62 | int link_gen; |
Quentin Schulz | c26ebe9 | 2017-06-08 10:07:42 +0200 | [diff] [blame] | 63 | struct regulator *vpcie; |
Leonard Crestez | 3f7ccee | 2018-10-08 18:06:21 +0000 | [diff] [blame] | 64 | |
| 65 | /* power domain for pcie */ |
| 66 | struct device *pd_pcie; |
| 67 | /* power domain for pcie phy */ |
| 68 | struct device *pd_pcie_phy; |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 69 | }; |
| 70 | |
Andrey Smirnov | 9b3fe67 | 2017-03-28 08:42:49 -0700 | [diff] [blame] | 71 | /* Parameters for the waiting for PCIe PHY PLL to lock on i.MX7 */ |
| 72 | #define PHY_PLL_LOCK_WAIT_MAX_RETRIES 2000 |
| 73 | #define PHY_PLL_LOCK_WAIT_USLEEP_MIN 50 |
| 74 | #define PHY_PLL_LOCK_WAIT_USLEEP_MAX 200 |
| 75 | |
Marek Vasut | fa33a6d | 2013-12-12 22:50:02 +0100 | [diff] [blame] | 76 | /* PCIe Root Complex registers (memory-mapped) */ |
| 77 | #define PCIE_RC_LCR 0x7c |
| 78 | #define PCIE_RC_LCR_MAX_LINK_SPEEDS_GEN1 0x1 |
| 79 | #define PCIE_RC_LCR_MAX_LINK_SPEEDS_GEN2 0x2 |
| 80 | #define PCIE_RC_LCR_MAX_LINK_SPEEDS_MASK 0xf |
| 81 | |
Bjorn Helgaas | 2393f79 | 2015-06-12 17:27:43 -0500 | [diff] [blame] | 82 | #define PCIE_RC_LCSR 0x80 |
| 83 | |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 84 | /* PCIe Port Logic registers (memory-mapped) */ |
| 85 | #define PL_OFFSET 0x700 |
Lucas Stach | 3e3e406 | 2014-07-31 20:16:05 +0200 | [diff] [blame] | 86 | #define PCIE_PL_PFLR (PL_OFFSET + 0x08) |
| 87 | #define PCIE_PL_PFLR_LINK_STATE_MASK (0x3f << 16) |
| 88 | #define PCIE_PL_PFLR_FORCE_LINK (1 << 15) |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 89 | #define PCIE_PHY_DEBUG_R0 (PL_OFFSET + 0x28) |
| 90 | #define PCIE_PHY_DEBUG_R1 (PL_OFFSET + 0x2c) |
Marek Vasut | 7f9f40c | 2013-12-12 22:49:59 +0100 | [diff] [blame] | 91 | #define PCIE_PHY_DEBUG_R1_XMLH_LINK_IN_TRAINING (1 << 29) |
| 92 | #define PCIE_PHY_DEBUG_R1_XMLH_LINK_UP (1 << 4) |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 93 | |
| 94 | #define PCIE_PHY_CTRL (PL_OFFSET + 0x114) |
| 95 | #define PCIE_PHY_CTRL_DATA_LOC 0 |
| 96 | #define PCIE_PHY_CTRL_CAP_ADR_LOC 16 |
| 97 | #define PCIE_PHY_CTRL_CAP_DAT_LOC 17 |
| 98 | #define PCIE_PHY_CTRL_WR_LOC 18 |
| 99 | #define PCIE_PHY_CTRL_RD_LOC 19 |
| 100 | |
| 101 | #define PCIE_PHY_STAT (PL_OFFSET + 0x110) |
| 102 | #define PCIE_PHY_STAT_ACK_LOC 16 |
| 103 | |
Marek Vasut | fa33a6d | 2013-12-12 22:50:02 +0100 | [diff] [blame] | 104 | #define PCIE_LINK_WIDTH_SPEED_CONTROL 0x80C |
| 105 | #define PORT_LOGIC_SPEED_CHANGE (0x1 << 17) |
| 106 | |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 107 | /* PHY registers (not memory-mapped) */ |
Lucas Stach | f18f42d | 2018-07-31 12:21:49 +0200 | [diff] [blame] | 108 | #define PCIE_PHY_ATEOVRD 0x10 |
| 109 | #define PCIE_PHY_ATEOVRD_EN (0x1 << 2) |
| 110 | #define PCIE_PHY_ATEOVRD_REF_CLKDIV_SHIFT 0 |
| 111 | #define PCIE_PHY_ATEOVRD_REF_CLKDIV_MASK 0x1 |
| 112 | |
| 113 | #define PCIE_PHY_MPLL_OVRD_IN_LO 0x11 |
| 114 | #define PCIE_PHY_MPLL_MULTIPLIER_SHIFT 2 |
| 115 | #define PCIE_PHY_MPLL_MULTIPLIER_MASK 0x7f |
| 116 | #define PCIE_PHY_MPLL_MULTIPLIER_OVRD (0x1 << 9) |
| 117 | |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 118 | #define PCIE_PHY_RX_ASIC_OUT 0x100D |
Fabio Estevam | 111feb7 | 2015-09-11 09:08:53 -0300 | [diff] [blame] | 119 | #define PCIE_PHY_RX_ASIC_OUT_VALID (1 << 0) |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 120 | |
| 121 | #define PHY_RX_OVRD_IN_LO 0x1005 |
| 122 | #define PHY_RX_OVRD_IN_LO_RX_DATA_EN (1 << 5) |
| 123 | #define PHY_RX_OVRD_IN_LO_RX_PLL_EN (1 << 3) |
| 124 | |
Bjorn Helgaas | 8bad7f2 | 2016-10-11 22:09:32 -0500 | [diff] [blame] | 125 | static int pcie_phy_poll_ack(struct imx6_pcie *imx6_pcie, int exp_val) |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 126 | { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 127 | struct dw_pcie *pci = imx6_pcie->pci; |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 128 | u32 val; |
| 129 | u32 max_iterations = 10; |
| 130 | u32 wait_counter = 0; |
| 131 | |
| 132 | do { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 133 | val = dw_pcie_readl_dbi(pci, PCIE_PHY_STAT); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 134 | val = (val >> PCIE_PHY_STAT_ACK_LOC) & 0x1; |
| 135 | wait_counter++; |
| 136 | |
| 137 | if (val == exp_val) |
| 138 | return 0; |
| 139 | |
| 140 | udelay(1); |
| 141 | } while (wait_counter < max_iterations); |
| 142 | |
| 143 | return -ETIMEDOUT; |
| 144 | } |
| 145 | |
Bjorn Helgaas | 8bad7f2 | 2016-10-11 22:09:32 -0500 | [diff] [blame] | 146 | static int pcie_phy_wait_ack(struct imx6_pcie *imx6_pcie, int addr) |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 147 | { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 148 | struct dw_pcie *pci = imx6_pcie->pci; |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 149 | u32 val; |
| 150 | int ret; |
| 151 | |
| 152 | val = addr << PCIE_PHY_CTRL_DATA_LOC; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 153 | dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, val); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 154 | |
| 155 | val |= (0x1 << PCIE_PHY_CTRL_CAP_ADR_LOC); |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 156 | dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, val); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 157 | |
Bjorn Helgaas | 8bad7f2 | 2016-10-11 22:09:32 -0500 | [diff] [blame] | 158 | ret = pcie_phy_poll_ack(imx6_pcie, 1); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 159 | if (ret) |
| 160 | return ret; |
| 161 | |
| 162 | val = addr << PCIE_PHY_CTRL_DATA_LOC; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 163 | dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, val); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 164 | |
Bjorn Helgaas | 8bad7f2 | 2016-10-11 22:09:32 -0500 | [diff] [blame] | 165 | return pcie_phy_poll_ack(imx6_pcie, 0); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | /* Read from the 16-bit PCIe PHY control registers (not memory-mapped) */ |
Bjorn Helgaas | 8bad7f2 | 2016-10-11 22:09:32 -0500 | [diff] [blame] | 169 | static int pcie_phy_read(struct imx6_pcie *imx6_pcie, int addr, int *data) |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 170 | { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 171 | struct dw_pcie *pci = imx6_pcie->pci; |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 172 | u32 val, phy_ctl; |
| 173 | int ret; |
| 174 | |
Bjorn Helgaas | 8bad7f2 | 2016-10-11 22:09:32 -0500 | [diff] [blame] | 175 | ret = pcie_phy_wait_ack(imx6_pcie, addr); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 176 | if (ret) |
| 177 | return ret; |
| 178 | |
| 179 | /* assert Read signal */ |
| 180 | phy_ctl = 0x1 << PCIE_PHY_CTRL_RD_LOC; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 181 | dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, phy_ctl); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 182 | |
Bjorn Helgaas | 8bad7f2 | 2016-10-11 22:09:32 -0500 | [diff] [blame] | 183 | ret = pcie_phy_poll_ack(imx6_pcie, 1); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 184 | if (ret) |
| 185 | return ret; |
| 186 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 187 | val = dw_pcie_readl_dbi(pci, PCIE_PHY_STAT); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 188 | *data = val & 0xffff; |
| 189 | |
| 190 | /* deassert Read signal */ |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 191 | dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, 0x00); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 192 | |
Bjorn Helgaas | 8bad7f2 | 2016-10-11 22:09:32 -0500 | [diff] [blame] | 193 | return pcie_phy_poll_ack(imx6_pcie, 0); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 194 | } |
| 195 | |
Bjorn Helgaas | 8bad7f2 | 2016-10-11 22:09:32 -0500 | [diff] [blame] | 196 | static int pcie_phy_write(struct imx6_pcie *imx6_pcie, int addr, int data) |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 197 | { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 198 | struct dw_pcie *pci = imx6_pcie->pci; |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 199 | u32 var; |
| 200 | int ret; |
| 201 | |
| 202 | /* write addr */ |
| 203 | /* cap addr */ |
Bjorn Helgaas | 8bad7f2 | 2016-10-11 22:09:32 -0500 | [diff] [blame] | 204 | ret = pcie_phy_wait_ack(imx6_pcie, addr); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 205 | if (ret) |
| 206 | return ret; |
| 207 | |
| 208 | var = data << PCIE_PHY_CTRL_DATA_LOC; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 209 | dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, var); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 210 | |
| 211 | /* capture data */ |
| 212 | var |= (0x1 << PCIE_PHY_CTRL_CAP_DAT_LOC); |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 213 | dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, var); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 214 | |
Bjorn Helgaas | 8bad7f2 | 2016-10-11 22:09:32 -0500 | [diff] [blame] | 215 | ret = pcie_phy_poll_ack(imx6_pcie, 1); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 216 | if (ret) |
| 217 | return ret; |
| 218 | |
| 219 | /* deassert cap data */ |
| 220 | var = data << PCIE_PHY_CTRL_DATA_LOC; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 221 | dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, var); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 222 | |
| 223 | /* wait for ack de-assertion */ |
Bjorn Helgaas | 8bad7f2 | 2016-10-11 22:09:32 -0500 | [diff] [blame] | 224 | ret = pcie_phy_poll_ack(imx6_pcie, 0); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 225 | if (ret) |
| 226 | return ret; |
| 227 | |
| 228 | /* assert wr signal */ |
| 229 | var = 0x1 << PCIE_PHY_CTRL_WR_LOC; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 230 | dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, var); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 231 | |
| 232 | /* wait for ack */ |
Bjorn Helgaas | 8bad7f2 | 2016-10-11 22:09:32 -0500 | [diff] [blame] | 233 | ret = pcie_phy_poll_ack(imx6_pcie, 1); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 234 | if (ret) |
| 235 | return ret; |
| 236 | |
| 237 | /* deassert wr signal */ |
| 238 | var = data << PCIE_PHY_CTRL_DATA_LOC; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 239 | dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, var); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 240 | |
| 241 | /* wait for ack de-assertion */ |
Bjorn Helgaas | 8bad7f2 | 2016-10-11 22:09:32 -0500 | [diff] [blame] | 242 | ret = pcie_phy_poll_ack(imx6_pcie, 0); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 243 | if (ret) |
| 244 | return ret; |
| 245 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 246 | dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, 0x0); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 247 | |
| 248 | return 0; |
| 249 | } |
| 250 | |
Bjorn Helgaas | e7d7705 | 2016-10-11 22:06:47 -0500 | [diff] [blame] | 251 | static void imx6_pcie_reset_phy(struct imx6_pcie *imx6_pcie) |
Lucas Stach | 53eeb48 | 2016-01-15 19:56:47 +0100 | [diff] [blame] | 252 | { |
| 253 | u32 tmp; |
| 254 | |
Bjorn Helgaas | 8bad7f2 | 2016-10-11 22:09:32 -0500 | [diff] [blame] | 255 | pcie_phy_read(imx6_pcie, PHY_RX_OVRD_IN_LO, &tmp); |
Lucas Stach | 53eeb48 | 2016-01-15 19:56:47 +0100 | [diff] [blame] | 256 | tmp |= (PHY_RX_OVRD_IN_LO_RX_DATA_EN | |
| 257 | PHY_RX_OVRD_IN_LO_RX_PLL_EN); |
Bjorn Helgaas | 8bad7f2 | 2016-10-11 22:09:32 -0500 | [diff] [blame] | 258 | pcie_phy_write(imx6_pcie, PHY_RX_OVRD_IN_LO, tmp); |
Lucas Stach | 53eeb48 | 2016-01-15 19:56:47 +0100 | [diff] [blame] | 259 | |
| 260 | usleep_range(2000, 3000); |
| 261 | |
Bjorn Helgaas | 8bad7f2 | 2016-10-11 22:09:32 -0500 | [diff] [blame] | 262 | pcie_phy_read(imx6_pcie, PHY_RX_OVRD_IN_LO, &tmp); |
Lucas Stach | 53eeb48 | 2016-01-15 19:56:47 +0100 | [diff] [blame] | 263 | tmp &= ~(PHY_RX_OVRD_IN_LO_RX_DATA_EN | |
| 264 | PHY_RX_OVRD_IN_LO_RX_PLL_EN); |
Bjorn Helgaas | 8bad7f2 | 2016-10-11 22:09:32 -0500 | [diff] [blame] | 265 | pcie_phy_write(imx6_pcie, PHY_RX_OVRD_IN_LO, tmp); |
Lucas Stach | 53eeb48 | 2016-01-15 19:56:47 +0100 | [diff] [blame] | 266 | } |
| 267 | |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 268 | /* Added for PCI abort handling */ |
| 269 | static int imx6q_pcie_abort_handler(unsigned long addr, |
| 270 | unsigned int fsr, struct pt_regs *regs) |
| 271 | { |
Lucas Stach | 415b618 | 2017-05-22 17:06:30 -0500 | [diff] [blame] | 272 | unsigned long pc = instruction_pointer(regs); |
| 273 | unsigned long instr = *(unsigned long *)pc; |
| 274 | int reg = (instr >> 12) & 15; |
| 275 | |
| 276 | /* |
| 277 | * If the instruction being executed was a read, |
| 278 | * make it look like it read all-ones. |
| 279 | */ |
| 280 | if ((instr & 0x0c100000) == 0x04100000) { |
| 281 | unsigned long val; |
| 282 | |
| 283 | if (instr & 0x00400000) |
| 284 | val = 255; |
| 285 | else |
| 286 | val = -1; |
| 287 | |
| 288 | regs->uregs[reg] = val; |
| 289 | regs->ARM_pc += 4; |
| 290 | return 0; |
| 291 | } |
| 292 | |
| 293 | if ((instr & 0x0e100090) == 0x00100090) { |
| 294 | regs->uregs[reg] = -1; |
| 295 | regs->ARM_pc += 4; |
| 296 | return 0; |
| 297 | } |
| 298 | |
| 299 | return 1; |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 300 | } |
| 301 | |
Leonard Crestez | 3f7ccee | 2018-10-08 18:06:21 +0000 | [diff] [blame] | 302 | static int imx6_pcie_attach_pd(struct device *dev) |
| 303 | { |
| 304 | struct imx6_pcie *imx6_pcie = dev_get_drvdata(dev); |
| 305 | struct device_link *link; |
| 306 | |
| 307 | /* Do nothing when in a single power domain */ |
| 308 | if (dev->pm_domain) |
| 309 | return 0; |
| 310 | |
| 311 | imx6_pcie->pd_pcie = dev_pm_domain_attach_by_name(dev, "pcie"); |
| 312 | if (IS_ERR(imx6_pcie->pd_pcie)) |
| 313 | return PTR_ERR(imx6_pcie->pd_pcie); |
| 314 | link = device_link_add(dev, imx6_pcie->pd_pcie, |
| 315 | DL_FLAG_STATELESS | |
| 316 | DL_FLAG_PM_RUNTIME | |
| 317 | DL_FLAG_RPM_ACTIVE); |
| 318 | if (!link) { |
| 319 | dev_err(dev, "Failed to add device_link to pcie pd.\n"); |
| 320 | return -EINVAL; |
| 321 | } |
| 322 | |
| 323 | imx6_pcie->pd_pcie_phy = dev_pm_domain_attach_by_name(dev, "pcie_phy"); |
| 324 | if (IS_ERR(imx6_pcie->pd_pcie_phy)) |
| 325 | return PTR_ERR(imx6_pcie->pd_pcie_phy); |
| 326 | |
| 327 | device_link_add(dev, imx6_pcie->pd_pcie_phy, |
| 328 | DL_FLAG_STATELESS | |
| 329 | DL_FLAG_PM_RUNTIME | |
| 330 | DL_FLAG_RPM_ACTIVE); |
| 331 | if (IS_ERR(link)) { |
| 332 | dev_err(dev, "Failed to add device_link to pcie_phy pd: %ld\n", PTR_ERR(link)); |
| 333 | return PTR_ERR(link); |
| 334 | } |
| 335 | |
| 336 | return 0; |
| 337 | } |
| 338 | |
Bjorn Helgaas | 9ab021b | 2016-10-06 13:35:17 -0500 | [diff] [blame] | 339 | static void imx6_pcie_assert_core_reset(struct imx6_pcie *imx6_pcie) |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 340 | { |
Quentin Schulz | c26ebe9 | 2017-06-08 10:07:42 +0200 | [diff] [blame] | 341 | struct device *dev = imx6_pcie->pci->dev; |
| 342 | |
Andrey Smirnov | e6f1fef | 2016-05-02 14:08:21 -0500 | [diff] [blame] | 343 | switch (imx6_pcie->variant) { |
Andrey Smirnov | 9b3fe67 | 2017-03-28 08:42:49 -0700 | [diff] [blame] | 344 | case IMX7D: |
| 345 | reset_control_assert(imx6_pcie->pciephy_reset); |
| 346 | reset_control_assert(imx6_pcie->apps_reset); |
| 347 | break; |
Andrey Smirnov | e6f1fef | 2016-05-02 14:08:21 -0500 | [diff] [blame] | 348 | case IMX6SX: |
Christoph Fritz | e3c06cd | 2016-04-05 16:53:27 -0500 | [diff] [blame] | 349 | regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12, |
| 350 | IMX6SX_GPR12_PCIE_TEST_POWERDOWN, |
| 351 | IMX6SX_GPR12_PCIE_TEST_POWERDOWN); |
| 352 | /* Force PCIe PHY reset */ |
| 353 | regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR5, |
| 354 | IMX6SX_GPR5_PCIE_BTNRST_RESET, |
| 355 | IMX6SX_GPR5_PCIE_BTNRST_RESET); |
Andrey Smirnov | e6f1fef | 2016-05-02 14:08:21 -0500 | [diff] [blame] | 356 | break; |
Andrey Smirnov | 4d31c61 | 2016-05-02 14:09:10 -0500 | [diff] [blame] | 357 | case IMX6QP: |
| 358 | regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1, |
| 359 | IMX6Q_GPR1_PCIE_SW_RST, |
| 360 | IMX6Q_GPR1_PCIE_SW_RST); |
| 361 | break; |
Andrey Smirnov | e6f1fef | 2016-05-02 14:08:21 -0500 | [diff] [blame] | 362 | case IMX6Q: |
Andrey Smirnov | e6f1fef | 2016-05-02 14:08:21 -0500 | [diff] [blame] | 363 | regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1, |
| 364 | IMX6Q_GPR1_PCIE_TEST_PD, 1 << 18); |
| 365 | regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1, |
| 366 | IMX6Q_GPR1_PCIE_REF_CLK_EN, 0 << 16); |
| 367 | break; |
Christoph Fritz | e3c06cd | 2016-04-05 16:53:27 -0500 | [diff] [blame] | 368 | } |
Quentin Schulz | c26ebe9 | 2017-06-08 10:07:42 +0200 | [diff] [blame] | 369 | |
| 370 | if (imx6_pcie->vpcie && regulator_is_enabled(imx6_pcie->vpcie) > 0) { |
| 371 | int ret = regulator_disable(imx6_pcie->vpcie); |
| 372 | |
| 373 | if (ret) |
| 374 | dev_err(dev, "failed to disable vpcie regulator: %d\n", |
| 375 | ret); |
| 376 | } |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 377 | } |
| 378 | |
Bjorn Helgaas | 4d1821e | 2016-03-14 00:30:55 +0100 | [diff] [blame] | 379 | static int imx6_pcie_enable_ref_clk(struct imx6_pcie *imx6_pcie) |
| 380 | { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 381 | struct dw_pcie *pci = imx6_pcie->pci; |
| 382 | struct device *dev = pci->dev; |
Andrey Smirnov | e6f1fef | 2016-05-02 14:08:21 -0500 | [diff] [blame] | 383 | int ret = 0; |
Christoph Fritz | e3c06cd | 2016-04-05 16:53:27 -0500 | [diff] [blame] | 384 | |
Andrey Smirnov | e6f1fef | 2016-05-02 14:08:21 -0500 | [diff] [blame] | 385 | switch (imx6_pcie->variant) { |
| 386 | case IMX6SX: |
Christoph Fritz | e3c06cd | 2016-04-05 16:53:27 -0500 | [diff] [blame] | 387 | ret = clk_prepare_enable(imx6_pcie->pcie_inbound_axi); |
| 388 | if (ret) { |
Bjorn Helgaas | 1395765 | 2016-10-06 13:35:18 -0500 | [diff] [blame] | 389 | dev_err(dev, "unable to enable pcie_axi clock\n"); |
Andrey Smirnov | e6f1fef | 2016-05-02 14:08:21 -0500 | [diff] [blame] | 390 | break; |
Christoph Fritz | e3c06cd | 2016-04-05 16:53:27 -0500 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12, |
| 394 | IMX6SX_GPR12_PCIE_TEST_POWERDOWN, 0); |
Andrey Smirnov | e6f1fef | 2016-05-02 14:08:21 -0500 | [diff] [blame] | 395 | break; |
Fabio Estevam | c27fd68 | 2018-05-09 14:01:48 -0300 | [diff] [blame] | 396 | case IMX6QP: /* FALLTHROUGH */ |
Andrey Smirnov | e6f1fef | 2016-05-02 14:08:21 -0500 | [diff] [blame] | 397 | case IMX6Q: |
| 398 | /* power up core phy and enable ref clock */ |
| 399 | regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1, |
| 400 | IMX6Q_GPR1_PCIE_TEST_PD, 0 << 18); |
| 401 | /* |
| 402 | * the async reset input need ref clock to sync internally, |
| 403 | * when the ref clock comes after reset, internal synced |
| 404 | * reset time is too short, cannot meet the requirement. |
| 405 | * add one ~10us delay here. |
| 406 | */ |
| 407 | udelay(10); |
| 408 | regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1, |
| 409 | IMX6Q_GPR1_PCIE_REF_CLK_EN, 1 << 16); |
| 410 | break; |
Andrey Smirnov | 9b3fe67 | 2017-03-28 08:42:49 -0700 | [diff] [blame] | 411 | case IMX7D: |
| 412 | break; |
Christoph Fritz | e3c06cd | 2016-04-05 16:53:27 -0500 | [diff] [blame] | 413 | } |
| 414 | |
Andrey Smirnov | e6f1fef | 2016-05-02 14:08:21 -0500 | [diff] [blame] | 415 | return ret; |
Bjorn Helgaas | 4d1821e | 2016-03-14 00:30:55 +0100 | [diff] [blame] | 416 | } |
| 417 | |
Andrey Smirnov | 9b3fe67 | 2017-03-28 08:42:49 -0700 | [diff] [blame] | 418 | static void imx7d_pcie_wait_for_phy_pll_lock(struct imx6_pcie *imx6_pcie) |
| 419 | { |
| 420 | u32 val; |
| 421 | unsigned int retries; |
| 422 | struct device *dev = imx6_pcie->pci->dev; |
| 423 | |
| 424 | for (retries = 0; retries < PHY_PLL_LOCK_WAIT_MAX_RETRIES; retries++) { |
| 425 | regmap_read(imx6_pcie->iomuxc_gpr, IOMUXC_GPR22, &val); |
| 426 | |
| 427 | if (val & IMX7D_GPR22_PCIE_PHY_PLL_LOCKED) |
| 428 | return; |
| 429 | |
| 430 | usleep_range(PHY_PLL_LOCK_WAIT_USLEEP_MIN, |
| 431 | PHY_PLL_LOCK_WAIT_USLEEP_MAX); |
| 432 | } |
| 433 | |
| 434 | dev_err(dev, "PCIe PLL lock timeout\n"); |
| 435 | } |
| 436 | |
Bjorn Helgaas | 9ab021b | 2016-10-06 13:35:17 -0500 | [diff] [blame] | 437 | static void imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie) |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 438 | { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 439 | struct dw_pcie *pci = imx6_pcie->pci; |
| 440 | struct device *dev = pci->dev; |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 441 | int ret; |
| 442 | |
Quentin Schulz | c26ebe9 | 2017-06-08 10:07:42 +0200 | [diff] [blame] | 443 | if (imx6_pcie->vpcie && !regulator_is_enabled(imx6_pcie->vpcie)) { |
| 444 | ret = regulator_enable(imx6_pcie->vpcie); |
| 445 | if (ret) { |
| 446 | dev_err(dev, "failed to enable vpcie regulator: %d\n", |
| 447 | ret); |
| 448 | return; |
| 449 | } |
| 450 | } |
| 451 | |
Lucas Stach | 5752613 | 2014-03-28 17:52:55 +0100 | [diff] [blame] | 452 | ret = clk_prepare_enable(imx6_pcie->pcie_phy); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 453 | if (ret) { |
Bjorn Helgaas | 1395765 | 2016-10-06 13:35:18 -0500 | [diff] [blame] | 454 | dev_err(dev, "unable to enable pcie_phy clock\n"); |
Quentin Schulz | c26ebe9 | 2017-06-08 10:07:42 +0200 | [diff] [blame] | 455 | goto err_pcie_phy; |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 456 | } |
| 457 | |
Lucas Stach | 5752613 | 2014-03-28 17:52:55 +0100 | [diff] [blame] | 458 | ret = clk_prepare_enable(imx6_pcie->pcie_bus); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 459 | if (ret) { |
Bjorn Helgaas | 1395765 | 2016-10-06 13:35:18 -0500 | [diff] [blame] | 460 | dev_err(dev, "unable to enable pcie_bus clock\n"); |
Lucas Stach | 5752613 | 2014-03-28 17:52:55 +0100 | [diff] [blame] | 461 | goto err_pcie_bus; |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 462 | } |
| 463 | |
Lucas Stach | 5752613 | 2014-03-28 17:52:55 +0100 | [diff] [blame] | 464 | ret = clk_prepare_enable(imx6_pcie->pcie); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 465 | if (ret) { |
Bjorn Helgaas | 1395765 | 2016-10-06 13:35:18 -0500 | [diff] [blame] | 466 | dev_err(dev, "unable to enable pcie clock\n"); |
Lucas Stach | 5752613 | 2014-03-28 17:52:55 +0100 | [diff] [blame] | 467 | goto err_pcie; |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 468 | } |
| 469 | |
Bjorn Helgaas | 4d1821e | 2016-03-14 00:30:55 +0100 | [diff] [blame] | 470 | ret = imx6_pcie_enable_ref_clk(imx6_pcie); |
| 471 | if (ret) { |
Bjorn Helgaas | 1395765 | 2016-10-06 13:35:18 -0500 | [diff] [blame] | 472 | dev_err(dev, "unable to enable pcie ref clock\n"); |
Bjorn Helgaas | 4d1821e | 2016-03-14 00:30:55 +0100 | [diff] [blame] | 473 | goto err_ref_clk; |
| 474 | } |
Tim Harvey | 3fce0e8 | 2014-08-07 23:36:40 -0700 | [diff] [blame] | 475 | |
Richard Zhu | a2fa6f6 | 2014-10-27 13:17:32 +0800 | [diff] [blame] | 476 | /* allow the clocks to stabilize */ |
| 477 | usleep_range(200, 500); |
| 478 | |
Richard Zhu | bc9ef77 | 2013-12-12 22:50:03 +0100 | [diff] [blame] | 479 | /* Some boards don't have PCIe reset GPIO. */ |
Fabio Estevam | b2d7a9c | 2016-03-28 18:45:36 -0300 | [diff] [blame] | 480 | if (gpio_is_valid(imx6_pcie->reset_gpio)) { |
Petr Štetiar | 3ea8529a | 2016-04-19 19:42:07 -0500 | [diff] [blame] | 481 | gpio_set_value_cansleep(imx6_pcie->reset_gpio, |
| 482 | imx6_pcie->gpio_active_high); |
Richard Zhu | bc9ef77 | 2013-12-12 22:50:03 +0100 | [diff] [blame] | 483 | msleep(100); |
Petr Štetiar | 3ea8529a | 2016-04-19 19:42:07 -0500 | [diff] [blame] | 484 | gpio_set_value_cansleep(imx6_pcie->reset_gpio, |
| 485 | !imx6_pcie->gpio_active_high); |
Richard Zhu | bc9ef77 | 2013-12-12 22:50:03 +0100 | [diff] [blame] | 486 | } |
Christoph Fritz | e3c06cd | 2016-04-05 16:53:27 -0500 | [diff] [blame] | 487 | |
Andrey Smirnov | 4d31c61 | 2016-05-02 14:09:10 -0500 | [diff] [blame] | 488 | switch (imx6_pcie->variant) { |
Andrey Smirnov | 9b3fe67 | 2017-03-28 08:42:49 -0700 | [diff] [blame] | 489 | case IMX7D: |
| 490 | reset_control_deassert(imx6_pcie->pciephy_reset); |
| 491 | imx7d_pcie_wait_for_phy_pll_lock(imx6_pcie); |
| 492 | break; |
Andrey Smirnov | 4d31c61 | 2016-05-02 14:09:10 -0500 | [diff] [blame] | 493 | case IMX6SX: |
Christoph Fritz | e3c06cd | 2016-04-05 16:53:27 -0500 | [diff] [blame] | 494 | regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR5, |
| 495 | IMX6SX_GPR5_PCIE_BTNRST_RESET, 0); |
Andrey Smirnov | 4d31c61 | 2016-05-02 14:09:10 -0500 | [diff] [blame] | 496 | break; |
| 497 | case IMX6QP: |
| 498 | regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1, |
| 499 | IMX6Q_GPR1_PCIE_SW_RST, 0); |
| 500 | |
| 501 | usleep_range(200, 500); |
| 502 | break; |
| 503 | case IMX6Q: /* Nothing to do */ |
| 504 | break; |
| 505 | } |
Christoph Fritz | e3c06cd | 2016-04-05 16:53:27 -0500 | [diff] [blame] | 506 | |
Bjorn Helgaas | 9ab021b | 2016-10-06 13:35:17 -0500 | [diff] [blame] | 507 | return; |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 508 | |
Bjorn Helgaas | 4d1821e | 2016-03-14 00:30:55 +0100 | [diff] [blame] | 509 | err_ref_clk: |
| 510 | clk_disable_unprepare(imx6_pcie->pcie); |
Lucas Stach | 5752613 | 2014-03-28 17:52:55 +0100 | [diff] [blame] | 511 | err_pcie: |
| 512 | clk_disable_unprepare(imx6_pcie->pcie_bus); |
| 513 | err_pcie_bus: |
| 514 | clk_disable_unprepare(imx6_pcie->pcie_phy); |
Quentin Schulz | c26ebe9 | 2017-06-08 10:07:42 +0200 | [diff] [blame] | 515 | err_pcie_phy: |
| 516 | if (imx6_pcie->vpcie && regulator_is_enabled(imx6_pcie->vpcie) > 0) { |
| 517 | ret = regulator_disable(imx6_pcie->vpcie); |
| 518 | if (ret) |
| 519 | dev_err(dev, "failed to disable vpcie regulator: %d\n", |
| 520 | ret); |
| 521 | } |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 522 | } |
| 523 | |
Bjorn Helgaas | e7d7705 | 2016-10-11 22:06:47 -0500 | [diff] [blame] | 524 | static void imx6_pcie_init_phy(struct imx6_pcie *imx6_pcie) |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 525 | { |
Andrey Smirnov | 9b3fe67 | 2017-03-28 08:42:49 -0700 | [diff] [blame] | 526 | switch (imx6_pcie->variant) { |
| 527 | case IMX7D: |
| 528 | regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12, |
| 529 | IMX7D_GPR12_PCIE_PHY_REFCLK_SEL, 0); |
| 530 | break; |
| 531 | case IMX6SX: |
Christoph Fritz | e3c06cd | 2016-04-05 16:53:27 -0500 | [diff] [blame] | 532 | regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12, |
| 533 | IMX6SX_GPR12_PCIE_RX_EQ_MASK, |
| 534 | IMX6SX_GPR12_PCIE_RX_EQ_2); |
Andrey Smirnov | 9b3fe67 | 2017-03-28 08:42:49 -0700 | [diff] [blame] | 535 | /* FALLTHROUGH */ |
| 536 | default: |
| 537 | regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12, |
| 538 | IMX6Q_GPR12_PCIE_CTL_2, 0 << 10); |
Christoph Fritz | e3c06cd | 2016-04-05 16:53:27 -0500 | [diff] [blame] | 539 | |
Andrey Smirnov | 9b3fe67 | 2017-03-28 08:42:49 -0700 | [diff] [blame] | 540 | /* configure constant input signal to the pcie ctrl and phy */ |
| 541 | regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12, |
| 542 | IMX6Q_GPR12_LOS_LEVEL, 9 << 4); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 543 | |
Andrey Smirnov | 9b3fe67 | 2017-03-28 08:42:49 -0700 | [diff] [blame] | 544 | regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR8, |
| 545 | IMX6Q_GPR8_TX_DEEMPH_GEN1, |
| 546 | imx6_pcie->tx_deemph_gen1 << 0); |
| 547 | regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR8, |
| 548 | IMX6Q_GPR8_TX_DEEMPH_GEN2_3P5DB, |
| 549 | imx6_pcie->tx_deemph_gen2_3p5db << 6); |
| 550 | regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR8, |
| 551 | IMX6Q_GPR8_TX_DEEMPH_GEN2_6DB, |
| 552 | imx6_pcie->tx_deemph_gen2_6db << 12); |
| 553 | regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR8, |
| 554 | IMX6Q_GPR8_TX_SWING_FULL, |
| 555 | imx6_pcie->tx_swing_full << 18); |
| 556 | regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR8, |
| 557 | IMX6Q_GPR8_TX_SWING_LOW, |
| 558 | imx6_pcie->tx_swing_low << 25); |
| 559 | break; |
| 560 | } |
| 561 | |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 562 | regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12, |
| 563 | IMX6Q_GPR12_DEVICE_TYPE, PCI_EXP_TYPE_ROOT_PORT << 12); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 564 | } |
| 565 | |
Lucas Stach | f18f42d | 2018-07-31 12:21:49 +0200 | [diff] [blame] | 566 | static int imx6_setup_phy_mpll(struct imx6_pcie *imx6_pcie) |
| 567 | { |
| 568 | unsigned long phy_rate = clk_get_rate(imx6_pcie->pcie_phy); |
| 569 | int mult, div; |
| 570 | u32 val; |
| 571 | |
| 572 | switch (phy_rate) { |
| 573 | case 125000000: |
| 574 | /* |
| 575 | * The default settings of the MPLL are for a 125MHz input |
| 576 | * clock, so no need to reconfigure anything in that case. |
| 577 | */ |
| 578 | return 0; |
| 579 | case 100000000: |
| 580 | mult = 25; |
| 581 | div = 0; |
| 582 | break; |
| 583 | case 200000000: |
| 584 | mult = 25; |
| 585 | div = 1; |
| 586 | break; |
| 587 | default: |
| 588 | dev_err(imx6_pcie->pci->dev, |
| 589 | "Unsupported PHY reference clock rate %lu\n", phy_rate); |
| 590 | return -EINVAL; |
| 591 | } |
| 592 | |
| 593 | pcie_phy_read(imx6_pcie, PCIE_PHY_MPLL_OVRD_IN_LO, &val); |
| 594 | val &= ~(PCIE_PHY_MPLL_MULTIPLIER_MASK << |
| 595 | PCIE_PHY_MPLL_MULTIPLIER_SHIFT); |
| 596 | val |= mult << PCIE_PHY_MPLL_MULTIPLIER_SHIFT; |
| 597 | val |= PCIE_PHY_MPLL_MULTIPLIER_OVRD; |
| 598 | pcie_phy_write(imx6_pcie, PCIE_PHY_MPLL_OVRD_IN_LO, val); |
| 599 | |
| 600 | pcie_phy_read(imx6_pcie, PCIE_PHY_ATEOVRD, &val); |
| 601 | val &= ~(PCIE_PHY_ATEOVRD_REF_CLKDIV_MASK << |
| 602 | PCIE_PHY_ATEOVRD_REF_CLKDIV_SHIFT); |
| 603 | val |= div << PCIE_PHY_ATEOVRD_REF_CLKDIV_SHIFT; |
| 604 | val |= PCIE_PHY_ATEOVRD_EN; |
| 605 | pcie_phy_write(imx6_pcie, PCIE_PHY_ATEOVRD, val); |
| 606 | |
| 607 | return 0; |
| 608 | } |
| 609 | |
Bjorn Helgaas | e7d7705 | 2016-10-11 22:06:47 -0500 | [diff] [blame] | 610 | static int imx6_pcie_wait_for_link(struct imx6_pcie *imx6_pcie) |
Marek Vasut | 66a60f9 | 2013-12-12 22:50:01 +0100 | [diff] [blame] | 611 | { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 612 | struct dw_pcie *pci = imx6_pcie->pci; |
| 613 | struct device *dev = pci->dev; |
Bjorn Helgaas | 1395765 | 2016-10-06 13:35:18 -0500 | [diff] [blame] | 614 | |
Joao Pinto | 886bc5c | 2016-03-10 14:44:35 -0600 | [diff] [blame] | 615 | /* check if the link is up or not */ |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 616 | if (!dw_pcie_wait_for_link(pci)) |
Joao Pinto | 886bc5c | 2016-03-10 14:44:35 -0600 | [diff] [blame] | 617 | return 0; |
Marek Vasut | 66a60f9 | 2013-12-12 22:50:01 +0100 | [diff] [blame] | 618 | |
Bjorn Helgaas | 1395765 | 2016-10-06 13:35:18 -0500 | [diff] [blame] | 619 | dev_dbg(dev, "DEBUG_R0: 0x%08x, DEBUG_R1: 0x%08x\n", |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 620 | dw_pcie_readl_dbi(pci, PCIE_PHY_DEBUG_R0), |
| 621 | dw_pcie_readl_dbi(pci, PCIE_PHY_DEBUG_R1)); |
Joao Pinto | 886bc5c | 2016-03-10 14:44:35 -0600 | [diff] [blame] | 622 | return -ETIMEDOUT; |
Marek Vasut | 66a60f9 | 2013-12-12 22:50:01 +0100 | [diff] [blame] | 623 | } |
| 624 | |
Bjorn Helgaas | e7d7705 | 2016-10-11 22:06:47 -0500 | [diff] [blame] | 625 | static int imx6_pcie_wait_for_speed_change(struct imx6_pcie *imx6_pcie) |
Troy Kisky | a042746 | 2015-06-12 14:30:16 -0500 | [diff] [blame] | 626 | { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 627 | struct dw_pcie *pci = imx6_pcie->pci; |
| 628 | struct device *dev = pci->dev; |
Bjorn Helgaas | 1c7fae1 | 2015-06-12 15:02:49 -0500 | [diff] [blame] | 629 | u32 tmp; |
Troy Kisky | a042746 | 2015-06-12 14:30:16 -0500 | [diff] [blame] | 630 | unsigned int retries; |
| 631 | |
| 632 | for (retries = 0; retries < 200; retries++) { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 633 | tmp = dw_pcie_readl_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL); |
Troy Kisky | a042746 | 2015-06-12 14:30:16 -0500 | [diff] [blame] | 634 | /* Test if the speed change finished. */ |
| 635 | if (!(tmp & PORT_LOGIC_SPEED_CHANGE)) |
| 636 | return 0; |
| 637 | usleep_range(100, 1000); |
| 638 | } |
| 639 | |
Bjorn Helgaas | 1395765 | 2016-10-06 13:35:18 -0500 | [diff] [blame] | 640 | dev_err(dev, "Speed change timeout\n"); |
Troy Kisky | a042746 | 2015-06-12 14:30:16 -0500 | [diff] [blame] | 641 | return -EINVAL; |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 642 | } |
| 643 | |
Leonard Crestez | 0ee2c1f | 2018-08-27 14:28:37 +0300 | [diff] [blame] | 644 | static void imx6_pcie_ltssm_enable(struct device *dev) |
| 645 | { |
| 646 | struct imx6_pcie *imx6_pcie = dev_get_drvdata(dev); |
| 647 | |
| 648 | switch (imx6_pcie->variant) { |
| 649 | case IMX6Q: |
| 650 | case IMX6SX: |
| 651 | case IMX6QP: |
| 652 | regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12, |
| 653 | IMX6Q_GPR12_PCIE_CTL_2, |
| 654 | IMX6Q_GPR12_PCIE_CTL_2); |
| 655 | break; |
| 656 | case IMX7D: |
| 657 | reset_control_deassert(imx6_pcie->apps_reset); |
| 658 | break; |
| 659 | } |
| 660 | } |
| 661 | |
Bjorn Helgaas | e7d7705 | 2016-10-11 22:06:47 -0500 | [diff] [blame] | 662 | static int imx6_pcie_establish_link(struct imx6_pcie *imx6_pcie) |
Marek Vasut | fa33a6d | 2013-12-12 22:50:02 +0100 | [diff] [blame] | 663 | { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 664 | struct dw_pcie *pci = imx6_pcie->pci; |
| 665 | struct device *dev = pci->dev; |
Bjorn Helgaas | 1c7fae1 | 2015-06-12 15:02:49 -0500 | [diff] [blame] | 666 | u32 tmp; |
Troy Kisky | a042746 | 2015-06-12 14:30:16 -0500 | [diff] [blame] | 667 | int ret; |
Marek Vasut | fa33a6d | 2013-12-12 22:50:02 +0100 | [diff] [blame] | 668 | |
| 669 | /* |
| 670 | * Force Gen1 operation when starting the link. In case the link is |
| 671 | * started in Gen2 mode, there is a possibility the devices on the |
| 672 | * bus will not be detected at all. This happens with PCIe switches. |
| 673 | */ |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 674 | tmp = dw_pcie_readl_dbi(pci, PCIE_RC_LCR); |
Marek Vasut | fa33a6d | 2013-12-12 22:50:02 +0100 | [diff] [blame] | 675 | tmp &= ~PCIE_RC_LCR_MAX_LINK_SPEEDS_MASK; |
| 676 | tmp |= PCIE_RC_LCR_MAX_LINK_SPEEDS_GEN1; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 677 | dw_pcie_writel_dbi(pci, PCIE_RC_LCR, tmp); |
Marek Vasut | fa33a6d | 2013-12-12 22:50:02 +0100 | [diff] [blame] | 678 | |
| 679 | /* Start LTSSM. */ |
Leonard Crestez | 0ee2c1f | 2018-08-27 14:28:37 +0300 | [diff] [blame] | 680 | imx6_pcie_ltssm_enable(dev); |
Marek Vasut | fa33a6d | 2013-12-12 22:50:02 +0100 | [diff] [blame] | 681 | |
Bjorn Helgaas | e7d7705 | 2016-10-11 22:06:47 -0500 | [diff] [blame] | 682 | ret = imx6_pcie_wait_for_link(imx6_pcie); |
Fabio Estevam | caf3f56 | 2016-12-27 12:40:43 -0200 | [diff] [blame] | 683 | if (ret) |
Lucas Stach | 54a47a8 | 2016-01-25 16:49:53 -0600 | [diff] [blame] | 684 | goto err_reset_phy; |
Marek Vasut | fa33a6d | 2013-12-12 22:50:02 +0100 | [diff] [blame] | 685 | |
Tim Harvey | a5fcec4 | 2016-04-19 19:52:44 -0500 | [diff] [blame] | 686 | if (imx6_pcie->link_gen == 2) { |
| 687 | /* Allow Gen2 mode after the link is up. */ |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 688 | tmp = dw_pcie_readl_dbi(pci, PCIE_RC_LCR); |
Tim Harvey | a5fcec4 | 2016-04-19 19:52:44 -0500 | [diff] [blame] | 689 | tmp &= ~PCIE_RC_LCR_MAX_LINK_SPEEDS_MASK; |
| 690 | tmp |= PCIE_RC_LCR_MAX_LINK_SPEEDS_GEN2; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 691 | dw_pcie_writel_dbi(pci, PCIE_RC_LCR, tmp); |
Marek Vasut | fa33a6d | 2013-12-12 22:50:02 +0100 | [diff] [blame] | 692 | |
Andrey Smirnov | e6dcd87 | 2017-03-28 08:42:51 -0700 | [diff] [blame] | 693 | /* |
Andrey Smirnov | 93b226f | 2017-03-28 08:42:52 -0700 | [diff] [blame] | 694 | * Start Directed Speed Change so the best possible |
| 695 | * speed both link partners support can be negotiated. |
Andrey Smirnov | e6dcd87 | 2017-03-28 08:42:51 -0700 | [diff] [blame] | 696 | */ |
Andrey Smirnov | 93b226f | 2017-03-28 08:42:52 -0700 | [diff] [blame] | 697 | tmp = dw_pcie_readl_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL); |
| 698 | tmp |= PORT_LOGIC_SPEED_CHANGE; |
| 699 | dw_pcie_writel_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL, tmp); |
Andrey Smirnov | e6dcd87 | 2017-03-28 08:42:51 -0700 | [diff] [blame] | 700 | |
Andrey Smirnov | 93b226f | 2017-03-28 08:42:52 -0700 | [diff] [blame] | 701 | if (imx6_pcie->variant != IMX7D) { |
| 702 | /* |
| 703 | * On i.MX7, DIRECT_SPEED_CHANGE behaves differently |
| 704 | * from i.MX6 family when no link speed transition |
| 705 | * occurs and we go Gen1 -> yep, Gen1. The difference |
| 706 | * is that, in such case, it will not be cleared by HW |
| 707 | * which will cause the following code to report false |
| 708 | * failure. |
| 709 | */ |
| 710 | |
| 711 | ret = imx6_pcie_wait_for_speed_change(imx6_pcie); |
| 712 | if (ret) { |
| 713 | dev_err(dev, "Failed to bring link up!\n"); |
| 714 | goto err_reset_phy; |
| 715 | } |
| 716 | } |
| 717 | |
| 718 | /* Make sure link training is finished as well! */ |
| 719 | ret = imx6_pcie_wait_for_link(imx6_pcie); |
Andrey Smirnov | e6dcd87 | 2017-03-28 08:42:51 -0700 | [diff] [blame] | 720 | if (ret) { |
| 721 | dev_err(dev, "Failed to bring link up!\n"); |
| 722 | goto err_reset_phy; |
| 723 | } |
Andrey Smirnov | 93b226f | 2017-03-28 08:42:52 -0700 | [diff] [blame] | 724 | } else { |
| 725 | dev_info(dev, "Link: Gen2 disabled\n"); |
Marek Vasut | fa33a6d | 2013-12-12 22:50:02 +0100 | [diff] [blame] | 726 | } |
| 727 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 728 | tmp = dw_pcie_readl_dbi(pci, PCIE_RC_LCSR); |
Bjorn Helgaas | 1395765 | 2016-10-06 13:35:18 -0500 | [diff] [blame] | 729 | dev_info(dev, "Link up, Gen%i\n", (tmp >> 16) & 0xf); |
Troy Kisky | a042746 | 2015-06-12 14:30:16 -0500 | [diff] [blame] | 730 | return 0; |
Lucas Stach | 54a47a8 | 2016-01-25 16:49:53 -0600 | [diff] [blame] | 731 | |
| 732 | err_reset_phy: |
Bjorn Helgaas | 1395765 | 2016-10-06 13:35:18 -0500 | [diff] [blame] | 733 | dev_dbg(dev, "PHY DEBUG_R0=0x%08x DEBUG_R1=0x%08x\n", |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 734 | dw_pcie_readl_dbi(pci, PCIE_PHY_DEBUG_R0), |
| 735 | dw_pcie_readl_dbi(pci, PCIE_PHY_DEBUG_R1)); |
Bjorn Helgaas | 2a6a85d | 2016-10-11 22:18:26 -0500 | [diff] [blame] | 736 | imx6_pcie_reset_phy(imx6_pcie); |
Lucas Stach | 54a47a8 | 2016-01-25 16:49:53 -0600 | [diff] [blame] | 737 | return ret; |
Marek Vasut | fa33a6d | 2013-12-12 22:50:02 +0100 | [diff] [blame] | 738 | } |
| 739 | |
Bjorn Andersson | 4a30176 | 2017-07-15 23:39:45 -0700 | [diff] [blame] | 740 | static int imx6_pcie_host_init(struct pcie_port *pp) |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 741 | { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 742 | struct dw_pcie *pci = to_dw_pcie_from_pp(pp); |
| 743 | struct imx6_pcie *imx6_pcie = to_imx6_pcie(pci); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 744 | |
Bjorn Helgaas | e7d7705 | 2016-10-11 22:06:47 -0500 | [diff] [blame] | 745 | imx6_pcie_assert_core_reset(imx6_pcie); |
| 746 | imx6_pcie_init_phy(imx6_pcie); |
| 747 | imx6_pcie_deassert_core_reset(imx6_pcie); |
Lucas Stach | f18f42d | 2018-07-31 12:21:49 +0200 | [diff] [blame] | 748 | imx6_setup_phy_mpll(imx6_pcie); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 749 | dw_pcie_setup_rc(pp); |
Bjorn Helgaas | e7d7705 | 2016-10-11 22:06:47 -0500 | [diff] [blame] | 750 | imx6_pcie_establish_link(imx6_pcie); |
Lucas Stach | d1dc974 | 2014-03-28 17:52:59 +0100 | [diff] [blame] | 751 | |
| 752 | if (IS_ENABLED(CONFIG_PCI_MSI)) |
| 753 | dw_pcie_msi_init(pp); |
Bjorn Andersson | 4a30176 | 2017-07-15 23:39:45 -0700 | [diff] [blame] | 754 | |
| 755 | return 0; |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 756 | } |
| 757 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 758 | static int imx6_pcie_link_up(struct dw_pcie *pci) |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 759 | { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 760 | return dw_pcie_readl_dbi(pci, PCIE_PHY_DEBUG_R1) & |
Lucas Stach | 4d107d3 | 2016-01-25 16:50:02 -0600 | [diff] [blame] | 761 | PCIE_PHY_DEBUG_R1_XMLH_LINK_UP; |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 762 | } |
| 763 | |
Jisheng Zhang | 4ab2e7c | 2017-06-05 16:53:46 +0800 | [diff] [blame] | 764 | static const struct dw_pcie_host_ops imx6_pcie_host_ops = { |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 765 | .host_init = imx6_pcie_host_init, |
| 766 | }; |
| 767 | |
Andrey Smirnov | bde4a5a | 2017-03-28 08:42:50 -0700 | [diff] [blame] | 768 | static int imx6_add_pcie_port(struct imx6_pcie *imx6_pcie, |
| 769 | struct platform_device *pdev) |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 770 | { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 771 | struct dw_pcie *pci = imx6_pcie->pci; |
| 772 | struct pcie_port *pp = &pci->pp; |
| 773 | struct device *dev = &pdev->dev; |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 774 | int ret; |
| 775 | |
Lucas Stach | d1dc974 | 2014-03-28 17:52:59 +0100 | [diff] [blame] | 776 | if (IS_ENABLED(CONFIG_PCI_MSI)) { |
| 777 | pp->msi_irq = platform_get_irq_byname(pdev, "msi"); |
| 778 | if (pp->msi_irq <= 0) { |
Bjorn Helgaas | 1395765 | 2016-10-06 13:35:18 -0500 | [diff] [blame] | 779 | dev_err(dev, "failed to get MSI irq\n"); |
Lucas Stach | d1dc974 | 2014-03-28 17:52:59 +0100 | [diff] [blame] | 780 | return -ENODEV; |
| 781 | } |
Lucas Stach | d1dc974 | 2014-03-28 17:52:59 +0100 | [diff] [blame] | 782 | } |
| 783 | |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 784 | pp->ops = &imx6_pcie_host_ops; |
| 785 | |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 786 | ret = dw_pcie_host_init(pp); |
| 787 | if (ret) { |
Bjorn Helgaas | 1395765 | 2016-10-06 13:35:18 -0500 | [diff] [blame] | 788 | dev_err(dev, "failed to initialize host\n"); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 789 | return ret; |
| 790 | } |
| 791 | |
| 792 | return 0; |
| 793 | } |
| 794 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 795 | static const struct dw_pcie_ops dw_pcie_ops = { |
| 796 | .link_up = imx6_pcie_link_up, |
| 797 | }; |
| 798 | |
Leonard Crestez | 0ee2c1f | 2018-08-27 14:28:37 +0300 | [diff] [blame] | 799 | #ifdef CONFIG_PM_SLEEP |
| 800 | static void imx6_pcie_ltssm_disable(struct device *dev) |
| 801 | { |
| 802 | struct imx6_pcie *imx6_pcie = dev_get_drvdata(dev); |
| 803 | |
| 804 | switch (imx6_pcie->variant) { |
| 805 | case IMX6SX: |
| 806 | case IMX6QP: |
| 807 | regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12, |
| 808 | IMX6Q_GPR12_PCIE_CTL_2, 0); |
| 809 | break; |
| 810 | case IMX7D: |
| 811 | reset_control_assert(imx6_pcie->apps_reset); |
| 812 | break; |
| 813 | default: |
| 814 | dev_err(dev, "ltssm_disable not supported\n"); |
| 815 | } |
| 816 | } |
| 817 | |
Leonard Crestez | f4e833b | 2018-07-19 17:02:10 +0300 | [diff] [blame] | 818 | static void imx6_pcie_pm_turnoff(struct imx6_pcie *imx6_pcie) |
| 819 | { |
Leonard Crestez | 9e56f0d | 2018-11-07 13:57:03 +0000 | [diff] [blame^] | 820 | struct device *dev = imx6_pcie->pci->dev; |
| 821 | |
| 822 | /* Some variants have a turnoff reset in DT */ |
| 823 | if (imx6_pcie->turnoff_reset) { |
| 824 | reset_control_assert(imx6_pcie->turnoff_reset); |
| 825 | reset_control_deassert(imx6_pcie->turnoff_reset); |
| 826 | goto pm_turnoff_sleep; |
| 827 | } |
| 828 | |
| 829 | /* Others poke directly at IOMUXC registers */ |
| 830 | switch (imx6_pcie->variant) { |
| 831 | case IMX6SX: |
| 832 | regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12, |
| 833 | IMX6SX_GPR12_PCIE_PM_TURN_OFF, |
| 834 | IMX6SX_GPR12_PCIE_PM_TURN_OFF); |
| 835 | regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12, |
| 836 | IMX6SX_GPR12_PCIE_PM_TURN_OFF, 0); |
| 837 | break; |
| 838 | default: |
| 839 | dev_err(dev, "PME_Turn_Off not implemented\n"); |
| 840 | return; |
| 841 | } |
Leonard Crestez | f4e833b | 2018-07-19 17:02:10 +0300 | [diff] [blame] | 842 | |
| 843 | /* |
| 844 | * Components with an upstream port must respond to |
| 845 | * PME_Turn_Off with PME_TO_Ack but we can't check. |
| 846 | * |
| 847 | * The standard recommends a 1-10ms timeout after which to |
| 848 | * proceed anyway as if acks were received. |
| 849 | */ |
Leonard Crestez | 9e56f0d | 2018-11-07 13:57:03 +0000 | [diff] [blame^] | 850 | pm_turnoff_sleep: |
Leonard Crestez | f4e833b | 2018-07-19 17:02:10 +0300 | [diff] [blame] | 851 | usleep_range(1000, 10000); |
| 852 | } |
| 853 | |
Leonard Crestez | 0ee2c1f | 2018-08-27 14:28:37 +0300 | [diff] [blame] | 854 | static void imx6_pcie_clk_disable(struct imx6_pcie *imx6_pcie) |
| 855 | { |
| 856 | clk_disable_unprepare(imx6_pcie->pcie); |
| 857 | clk_disable_unprepare(imx6_pcie->pcie_phy); |
| 858 | clk_disable_unprepare(imx6_pcie->pcie_bus); |
| 859 | |
Leonard Crestez | 9e56f0d | 2018-11-07 13:57:03 +0000 | [diff] [blame^] | 860 | switch (imx6_pcie->variant) { |
| 861 | case IMX6SX: |
| 862 | clk_disable_unprepare(imx6_pcie->pcie_inbound_axi); |
| 863 | break; |
| 864 | case IMX7D: |
Leonard Crestez | 0ee2c1f | 2018-08-27 14:28:37 +0300 | [diff] [blame] | 865 | regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12, |
| 866 | IMX7D_GPR12_PCIE_PHY_REFCLK_SEL, |
| 867 | IMX7D_GPR12_PCIE_PHY_REFCLK_SEL); |
Leonard Crestez | 9e56f0d | 2018-11-07 13:57:03 +0000 | [diff] [blame^] | 868 | break; |
| 869 | default: |
| 870 | break; |
Leonard Crestez | 0ee2c1f | 2018-08-27 14:28:37 +0300 | [diff] [blame] | 871 | } |
| 872 | } |
| 873 | |
Leonard Crestez | 9e56f0d | 2018-11-07 13:57:03 +0000 | [diff] [blame^] | 874 | static inline bool imx6_pcie_supports_suspend(struct imx6_pcie *imx6_pcie) |
| 875 | { |
| 876 | return (imx6_pcie->variant == IMX7D || |
| 877 | imx6_pcie->variant == IMX6SX); |
| 878 | } |
| 879 | |
Leonard Crestez | 0ee2c1f | 2018-08-27 14:28:37 +0300 | [diff] [blame] | 880 | static int imx6_pcie_suspend_noirq(struct device *dev) |
| 881 | { |
| 882 | struct imx6_pcie *imx6_pcie = dev_get_drvdata(dev); |
| 883 | |
Leonard Crestez | 9e56f0d | 2018-11-07 13:57:03 +0000 | [diff] [blame^] | 884 | if (!imx6_pcie_supports_suspend(imx6_pcie)) |
Leonard Crestez | 0ee2c1f | 2018-08-27 14:28:37 +0300 | [diff] [blame] | 885 | return 0; |
| 886 | |
Leonard Crestez | f4e833b | 2018-07-19 17:02:10 +0300 | [diff] [blame] | 887 | imx6_pcie_pm_turnoff(imx6_pcie); |
Leonard Crestez | 0ee2c1f | 2018-08-27 14:28:37 +0300 | [diff] [blame] | 888 | imx6_pcie_clk_disable(imx6_pcie); |
| 889 | imx6_pcie_ltssm_disable(dev); |
| 890 | |
| 891 | return 0; |
| 892 | } |
| 893 | |
| 894 | static int imx6_pcie_resume_noirq(struct device *dev) |
| 895 | { |
| 896 | int ret; |
| 897 | struct imx6_pcie *imx6_pcie = dev_get_drvdata(dev); |
| 898 | struct pcie_port *pp = &imx6_pcie->pci->pp; |
| 899 | |
Leonard Crestez | 9e56f0d | 2018-11-07 13:57:03 +0000 | [diff] [blame^] | 900 | if (!imx6_pcie_supports_suspend(imx6_pcie)) |
Leonard Crestez | 0ee2c1f | 2018-08-27 14:28:37 +0300 | [diff] [blame] | 901 | return 0; |
| 902 | |
| 903 | imx6_pcie_assert_core_reset(imx6_pcie); |
| 904 | imx6_pcie_init_phy(imx6_pcie); |
| 905 | imx6_pcie_deassert_core_reset(imx6_pcie); |
| 906 | dw_pcie_setup_rc(pp); |
| 907 | |
| 908 | ret = imx6_pcie_establish_link(imx6_pcie); |
| 909 | if (ret < 0) |
| 910 | dev_info(dev, "pcie link is down after resume.\n"); |
| 911 | |
| 912 | return 0; |
| 913 | } |
| 914 | #endif |
| 915 | |
| 916 | static const struct dev_pm_ops imx6_pcie_pm_ops = { |
| 917 | SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(imx6_pcie_suspend_noirq, |
| 918 | imx6_pcie_resume_noirq) |
| 919 | }; |
| 920 | |
Andrey Smirnov | bde4a5a | 2017-03-28 08:42:50 -0700 | [diff] [blame] | 921 | static int imx6_pcie_probe(struct platform_device *pdev) |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 922 | { |
Bjorn Helgaas | 1395765 | 2016-10-06 13:35:18 -0500 | [diff] [blame] | 923 | struct device *dev = &pdev->dev; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 924 | struct dw_pcie *pci; |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 925 | struct imx6_pcie *imx6_pcie; |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 926 | struct resource *dbi_base; |
Bjorn Helgaas | 1395765 | 2016-10-06 13:35:18 -0500 | [diff] [blame] | 927 | struct device_node *node = dev->of_node; |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 928 | int ret; |
| 929 | |
Bjorn Helgaas | 1395765 | 2016-10-06 13:35:18 -0500 | [diff] [blame] | 930 | imx6_pcie = devm_kzalloc(dev, sizeof(*imx6_pcie), GFP_KERNEL); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 931 | if (!imx6_pcie) |
| 932 | return -ENOMEM; |
| 933 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 934 | pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL); |
| 935 | if (!pci) |
| 936 | return -ENOMEM; |
| 937 | |
| 938 | pci->dev = dev; |
| 939 | pci->ops = &dw_pcie_ops; |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 940 | |
Guenter Roeck | c046406 | 2017-02-25 02:08:12 -0800 | [diff] [blame] | 941 | imx6_pcie->pci = pci; |
Andrey Smirnov | e6f1fef | 2016-05-02 14:08:21 -0500 | [diff] [blame] | 942 | imx6_pcie->variant = |
Bjorn Helgaas | 1395765 | 2016-10-06 13:35:18 -0500 | [diff] [blame] | 943 | (enum imx6_pcie_variants)of_device_get_match_data(dev); |
Christoph Fritz | e3c06cd | 2016-04-05 16:53:27 -0500 | [diff] [blame] | 944 | |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 945 | dbi_base = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 946 | pci->dbi_base = devm_ioremap_resource(dev, dbi_base); |
| 947 | if (IS_ERR(pci->dbi_base)) |
| 948 | return PTR_ERR(pci->dbi_base); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 949 | |
| 950 | /* Fetch GPIOs */ |
Bjorn Helgaas | c5af407 | 2016-10-06 13:35:18 -0500 | [diff] [blame] | 951 | imx6_pcie->reset_gpio = of_get_named_gpio(node, "reset-gpio", 0); |
| 952 | imx6_pcie->gpio_active_high = of_property_read_bool(node, |
Petr Štetiar | 3ea8529a | 2016-04-19 19:42:07 -0500 | [diff] [blame] | 953 | "reset-gpio-active-high"); |
Fabio Estevam | b2d7a9c | 2016-03-28 18:45:36 -0300 | [diff] [blame] | 954 | if (gpio_is_valid(imx6_pcie->reset_gpio)) { |
Bjorn Helgaas | 1395765 | 2016-10-06 13:35:18 -0500 | [diff] [blame] | 955 | ret = devm_gpio_request_one(dev, imx6_pcie->reset_gpio, |
Petr Štetiar | 3ea8529a | 2016-04-19 19:42:07 -0500 | [diff] [blame] | 956 | imx6_pcie->gpio_active_high ? |
| 957 | GPIOF_OUT_INIT_HIGH : |
| 958 | GPIOF_OUT_INIT_LOW, |
| 959 | "PCIe reset"); |
Fabio Estevam | b2d7a9c | 2016-03-28 18:45:36 -0300 | [diff] [blame] | 960 | if (ret) { |
Bjorn Helgaas | 1395765 | 2016-10-06 13:35:18 -0500 | [diff] [blame] | 961 | dev_err(dev, "unable to get reset gpio\n"); |
Fabio Estevam | b2d7a9c | 2016-03-28 18:45:36 -0300 | [diff] [blame] | 962 | return ret; |
| 963 | } |
Andrey Smirnov | bde4a5a | 2017-03-28 08:42:50 -0700 | [diff] [blame] | 964 | } else if (imx6_pcie->reset_gpio == -EPROBE_DEFER) { |
| 965 | return imx6_pcie->reset_gpio; |
Fabio Estevam | b2d7a9c | 2016-03-28 18:45:36 -0300 | [diff] [blame] | 966 | } |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 967 | |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 968 | /* Fetch clocks */ |
Bjorn Helgaas | 1395765 | 2016-10-06 13:35:18 -0500 | [diff] [blame] | 969 | imx6_pcie->pcie_phy = devm_clk_get(dev, "pcie_phy"); |
Lucas Stach | 5752613 | 2014-03-28 17:52:55 +0100 | [diff] [blame] | 970 | if (IS_ERR(imx6_pcie->pcie_phy)) { |
Bjorn Helgaas | 1395765 | 2016-10-06 13:35:18 -0500 | [diff] [blame] | 971 | dev_err(dev, "pcie_phy clock source missing or invalid\n"); |
Lucas Stach | 5752613 | 2014-03-28 17:52:55 +0100 | [diff] [blame] | 972 | return PTR_ERR(imx6_pcie->pcie_phy); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 973 | } |
| 974 | |
Bjorn Helgaas | 1395765 | 2016-10-06 13:35:18 -0500 | [diff] [blame] | 975 | imx6_pcie->pcie_bus = devm_clk_get(dev, "pcie_bus"); |
Lucas Stach | 5752613 | 2014-03-28 17:52:55 +0100 | [diff] [blame] | 976 | if (IS_ERR(imx6_pcie->pcie_bus)) { |
Bjorn Helgaas | 1395765 | 2016-10-06 13:35:18 -0500 | [diff] [blame] | 977 | dev_err(dev, "pcie_bus clock source missing or invalid\n"); |
Lucas Stach | 5752613 | 2014-03-28 17:52:55 +0100 | [diff] [blame] | 978 | return PTR_ERR(imx6_pcie->pcie_bus); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 979 | } |
| 980 | |
Bjorn Helgaas | 1395765 | 2016-10-06 13:35:18 -0500 | [diff] [blame] | 981 | imx6_pcie->pcie = devm_clk_get(dev, "pcie"); |
Lucas Stach | 5752613 | 2014-03-28 17:52:55 +0100 | [diff] [blame] | 982 | if (IS_ERR(imx6_pcie->pcie)) { |
Bjorn Helgaas | 1395765 | 2016-10-06 13:35:18 -0500 | [diff] [blame] | 983 | dev_err(dev, "pcie clock source missing or invalid\n"); |
Lucas Stach | 5752613 | 2014-03-28 17:52:55 +0100 | [diff] [blame] | 984 | return PTR_ERR(imx6_pcie->pcie); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 985 | } |
| 986 | |
Andrey Smirnov | 9b3fe67 | 2017-03-28 08:42:49 -0700 | [diff] [blame] | 987 | switch (imx6_pcie->variant) { |
| 988 | case IMX6SX: |
Bjorn Helgaas | 1395765 | 2016-10-06 13:35:18 -0500 | [diff] [blame] | 989 | imx6_pcie->pcie_inbound_axi = devm_clk_get(dev, |
Christoph Fritz | e3c06cd | 2016-04-05 16:53:27 -0500 | [diff] [blame] | 990 | "pcie_inbound_axi"); |
| 991 | if (IS_ERR(imx6_pcie->pcie_inbound_axi)) { |
Andrey Smirnov | 21b7245 | 2017-02-07 07:50:25 -0800 | [diff] [blame] | 992 | dev_err(dev, "pcie_inbound_axi clock missing or invalid\n"); |
Christoph Fritz | e3c06cd | 2016-04-05 16:53:27 -0500 | [diff] [blame] | 993 | return PTR_ERR(imx6_pcie->pcie_inbound_axi); |
| 994 | } |
Andrey Smirnov | 9b3fe67 | 2017-03-28 08:42:49 -0700 | [diff] [blame] | 995 | break; |
| 996 | case IMX7D: |
Philipp Zabel | 7c18058 | 2017-07-19 17:25:56 +0200 | [diff] [blame] | 997 | imx6_pcie->pciephy_reset = devm_reset_control_get_exclusive(dev, |
| 998 | "pciephy"); |
Andrey Smirnov | 9b3fe67 | 2017-03-28 08:42:49 -0700 | [diff] [blame] | 999 | if (IS_ERR(imx6_pcie->pciephy_reset)) { |
Colin Ian King | 7221547 | 2017-04-21 08:02:30 +0100 | [diff] [blame] | 1000 | dev_err(dev, "Failed to get PCIEPHY reset control\n"); |
Andrey Smirnov | 9b3fe67 | 2017-03-28 08:42:49 -0700 | [diff] [blame] | 1001 | return PTR_ERR(imx6_pcie->pciephy_reset); |
| 1002 | } |
| 1003 | |
Philipp Zabel | 7c18058 | 2017-07-19 17:25:56 +0200 | [diff] [blame] | 1004 | imx6_pcie->apps_reset = devm_reset_control_get_exclusive(dev, |
| 1005 | "apps"); |
Andrey Smirnov | 9b3fe67 | 2017-03-28 08:42:49 -0700 | [diff] [blame] | 1006 | if (IS_ERR(imx6_pcie->apps_reset)) { |
Colin Ian King | 7221547 | 2017-04-21 08:02:30 +0100 | [diff] [blame] | 1007 | dev_err(dev, "Failed to get PCIE APPS reset control\n"); |
Andrey Smirnov | 9b3fe67 | 2017-03-28 08:42:49 -0700 | [diff] [blame] | 1008 | return PTR_ERR(imx6_pcie->apps_reset); |
| 1009 | } |
| 1010 | break; |
| 1011 | default: |
| 1012 | break; |
Christoph Fritz | e3c06cd | 2016-04-05 16:53:27 -0500 | [diff] [blame] | 1013 | } |
| 1014 | |
Leonard Crestez | f4e833b | 2018-07-19 17:02:10 +0300 | [diff] [blame] | 1015 | /* Grab turnoff reset */ |
| 1016 | imx6_pcie->turnoff_reset = devm_reset_control_get_optional_exclusive(dev, "turnoff"); |
| 1017 | if (IS_ERR(imx6_pcie->turnoff_reset)) { |
| 1018 | dev_err(dev, "Failed to get TURNOFF reset control\n"); |
| 1019 | return PTR_ERR(imx6_pcie->turnoff_reset); |
| 1020 | } |
| 1021 | |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 1022 | /* Grab GPR config register range */ |
| 1023 | imx6_pcie->iomuxc_gpr = |
| 1024 | syscon_regmap_lookup_by_compatible("fsl,imx6q-iomuxc-gpr"); |
| 1025 | if (IS_ERR(imx6_pcie->iomuxc_gpr)) { |
Bjorn Helgaas | 1395765 | 2016-10-06 13:35:18 -0500 | [diff] [blame] | 1026 | dev_err(dev, "unable to find iomuxc registers\n"); |
Fabio Estevam | b391bf3 | 2013-12-02 01:39:35 -0200 | [diff] [blame] | 1027 | return PTR_ERR(imx6_pcie->iomuxc_gpr); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 1028 | } |
| 1029 | |
Justin Waters | 28e3abe | 2016-01-15 10:24:35 -0500 | [diff] [blame] | 1030 | /* Grab PCIe PHY Tx Settings */ |
| 1031 | if (of_property_read_u32(node, "fsl,tx-deemph-gen1", |
| 1032 | &imx6_pcie->tx_deemph_gen1)) |
| 1033 | imx6_pcie->tx_deemph_gen1 = 0; |
| 1034 | |
| 1035 | if (of_property_read_u32(node, "fsl,tx-deemph-gen2-3p5db", |
| 1036 | &imx6_pcie->tx_deemph_gen2_3p5db)) |
| 1037 | imx6_pcie->tx_deemph_gen2_3p5db = 0; |
| 1038 | |
| 1039 | if (of_property_read_u32(node, "fsl,tx-deemph-gen2-6db", |
| 1040 | &imx6_pcie->tx_deemph_gen2_6db)) |
| 1041 | imx6_pcie->tx_deemph_gen2_6db = 20; |
| 1042 | |
| 1043 | if (of_property_read_u32(node, "fsl,tx-swing-full", |
| 1044 | &imx6_pcie->tx_swing_full)) |
| 1045 | imx6_pcie->tx_swing_full = 127; |
| 1046 | |
| 1047 | if (of_property_read_u32(node, "fsl,tx-swing-low", |
| 1048 | &imx6_pcie->tx_swing_low)) |
| 1049 | imx6_pcie->tx_swing_low = 127; |
| 1050 | |
Tim Harvey | a5fcec4 | 2016-04-19 19:52:44 -0500 | [diff] [blame] | 1051 | /* Limit link speed */ |
Bjorn Helgaas | c5af407 | 2016-10-06 13:35:18 -0500 | [diff] [blame] | 1052 | ret = of_property_read_u32(node, "fsl,max-link-speed", |
Tim Harvey | a5fcec4 | 2016-04-19 19:52:44 -0500 | [diff] [blame] | 1053 | &imx6_pcie->link_gen); |
| 1054 | if (ret) |
| 1055 | imx6_pcie->link_gen = 1; |
| 1056 | |
Quentin Schulz | c26ebe9 | 2017-06-08 10:07:42 +0200 | [diff] [blame] | 1057 | imx6_pcie->vpcie = devm_regulator_get_optional(&pdev->dev, "vpcie"); |
| 1058 | if (IS_ERR(imx6_pcie->vpcie)) { |
| 1059 | if (PTR_ERR(imx6_pcie->vpcie) == -EPROBE_DEFER) |
| 1060 | return -EPROBE_DEFER; |
| 1061 | imx6_pcie->vpcie = NULL; |
| 1062 | } |
| 1063 | |
Kishon Vijay Abraham I | 9bcf0a6 | 2017-02-15 18:48:11 +0530 | [diff] [blame] | 1064 | platform_set_drvdata(pdev, imx6_pcie); |
| 1065 | |
Leonard Crestez | 3f7ccee | 2018-10-08 18:06:21 +0000 | [diff] [blame] | 1066 | ret = imx6_pcie_attach_pd(dev); |
| 1067 | if (ret) |
| 1068 | return ret; |
| 1069 | |
Bjorn Helgaas | e7d7705 | 2016-10-11 22:06:47 -0500 | [diff] [blame] | 1070 | ret = imx6_add_pcie_port(imx6_pcie, pdev); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 1071 | if (ret < 0) |
Fabio Estevam | b391bf3 | 2013-12-02 01:39:35 -0200 | [diff] [blame] | 1072 | return ret; |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 1073 | |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 1074 | return 0; |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 1075 | } |
| 1076 | |
Lucas Stach | 3e3e406 | 2014-07-31 20:16:05 +0200 | [diff] [blame] | 1077 | static void imx6_pcie_shutdown(struct platform_device *pdev) |
| 1078 | { |
| 1079 | struct imx6_pcie *imx6_pcie = platform_get_drvdata(pdev); |
| 1080 | |
| 1081 | /* bring down link, so bootloader gets clean state in case of reboot */ |
Bjorn Helgaas | e7d7705 | 2016-10-11 22:06:47 -0500 | [diff] [blame] | 1082 | imx6_pcie_assert_core_reset(imx6_pcie); |
Lucas Stach | 3e3e406 | 2014-07-31 20:16:05 +0200 | [diff] [blame] | 1083 | } |
| 1084 | |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 1085 | static const struct of_device_id imx6_pcie_of_match[] = { |
Andrey Smirnov | e6f1fef | 2016-05-02 14:08:21 -0500 | [diff] [blame] | 1086 | { .compatible = "fsl,imx6q-pcie", .data = (void *)IMX6Q, }, |
| 1087 | { .compatible = "fsl,imx6sx-pcie", .data = (void *)IMX6SX, }, |
Andrey Smirnov | 4d31c61 | 2016-05-02 14:09:10 -0500 | [diff] [blame] | 1088 | { .compatible = "fsl,imx6qp-pcie", .data = (void *)IMX6QP, }, |
Andrey Smirnov | 9b3fe67 | 2017-03-28 08:42:49 -0700 | [diff] [blame] | 1089 | { .compatible = "fsl,imx7d-pcie", .data = (void *)IMX7D, }, |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 1090 | {}, |
| 1091 | }; |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 1092 | |
| 1093 | static struct platform_driver imx6_pcie_driver = { |
| 1094 | .driver = { |
| 1095 | .name = "imx6q-pcie", |
Sachin Kamat | 8bcadbe | 2013-10-21 14:36:41 +0530 | [diff] [blame] | 1096 | .of_match_table = imx6_pcie_of_match, |
Brian Norris | a5f40e8 | 2017-04-20 15:36:25 -0500 | [diff] [blame] | 1097 | .suppress_bind_attrs = true, |
Leonard Crestez | 0ee2c1f | 2018-08-27 14:28:37 +0300 | [diff] [blame] | 1098 | .pm = &imx6_pcie_pm_ops, |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 1099 | }, |
Andrey Smirnov | bde4a5a | 2017-03-28 08:42:50 -0700 | [diff] [blame] | 1100 | .probe = imx6_pcie_probe, |
Lucas Stach | 3e3e406 | 2014-07-31 20:16:05 +0200 | [diff] [blame] | 1101 | .shutdown = imx6_pcie_shutdown, |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 1102 | }; |
| 1103 | |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 1104 | static int __init imx6_pcie_init(void) |
| 1105 | { |
Andrey Smirnov | bde4a5a | 2017-03-28 08:42:50 -0700 | [diff] [blame] | 1106 | /* |
| 1107 | * Since probe() can be deferred we need to make sure that |
| 1108 | * hook_fault_code is not called after __init memory is freed |
| 1109 | * by kernel and since imx6q_pcie_abort_handler() is a no-op, |
| 1110 | * we can install the handler here without risking it |
| 1111 | * accessing some uninitialized driver state. |
| 1112 | */ |
Lucas Stach | 415b618 | 2017-05-22 17:06:30 -0500 | [diff] [blame] | 1113 | hook_fault_code(8, imx6q_pcie_abort_handler, SIGBUS, 0, |
| 1114 | "external abort on non-linefetch"); |
Andrey Smirnov | bde4a5a | 2017-03-28 08:42:50 -0700 | [diff] [blame] | 1115 | |
| 1116 | return platform_driver_register(&imx6_pcie_driver); |
Sean Cross | bb38919 | 2013-09-26 11:24:47 +0800 | [diff] [blame] | 1117 | } |
Paul Gortmaker | f90d8e8 | 2016-08-22 17:59:43 -0400 | [diff] [blame] | 1118 | device_initcall(imx6_pcie_init); |