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