blob: ac5f6ae0b2549ab4e4e75044f4998938db5700c3 [file] [log] [blame]
Bjorn Helgaas8cfab3c2018-01-26 12:50:27 -06001// SPDX-License-Identifier: GPL-2.0
Sean Crossbb389192013-09-26 11:24:47 +08002/*
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 Crossbb389192013-09-26 11:24:47 +08009 */
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 Smirnov9b3fe672017-03-28 08:42:49 -070017#include <linux/mfd/syscon/imx7-iomuxc-gpr.h>
Sean Crossbb389192013-09-26 11:24:47 +080018#include <linux/module.h>
19#include <linux/of_gpio.h>
Andrey Smirnove6f1fef2016-05-02 14:08:21 -050020#include <linux/of_device.h>
Sean Crossbb389192013-09-26 11:24:47 +080021#include <linux/pci.h>
22#include <linux/platform_device.h>
23#include <linux/regmap.h>
Quentin Schulzc26ebe92017-06-08 10:07:42 +020024#include <linux/regulator/consumer.h>
Sean Crossbb389192013-09-26 11:24:47 +080025#include <linux/resource.h>
26#include <linux/signal.h>
27#include <linux/types.h>
Lucas Stachd1dc9742014-03-28 17:52:59 +010028#include <linux/interrupt.h>
Andrey Smirnov9b3fe672017-03-28 08:42:49 -070029#include <linux/reset.h>
Leonard Crestez3f7ccee2018-10-08 18:06:21 +000030#include <linux/pm_domain.h>
31#include <linux/pm_runtime.h>
Sean Crossbb389192013-09-26 11:24:47 +080032
33#include "pcie-designware.h"
34
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +053035#define to_imx6_pcie(x) dev_get_drvdata((x)->dev)
Sean Crossbb389192013-09-26 11:24:47 +080036
Andrey Smirnove6f1fef2016-05-02 14:08:21 -050037enum imx6_pcie_variants {
38 IMX6Q,
Andrey Smirnov4d31c612016-05-02 14:09:10 -050039 IMX6SX,
40 IMX6QP,
Andrey Smirnov9b3fe672017-03-28 08:42:49 -070041 IMX7D,
Andrey Smirnove6f1fef2016-05-02 14:08:21 -050042};
43
Sean Crossbb389192013-09-26 11:24:47 +080044struct imx6_pcie {
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +053045 struct dw_pcie *pci;
Fabio Estevamb2d7a9c2016-03-28 18:45:36 -030046 int reset_gpio;
Petr Štetiar3ea8529a2016-04-19 19:42:07 -050047 bool gpio_active_high;
Lucas Stach57526132014-03-28 17:52:55 +010048 struct clk *pcie_bus;
49 struct clk *pcie_phy;
Christoph Fritze3c06cd2016-04-05 16:53:27 -050050 struct clk *pcie_inbound_axi;
Lucas Stach57526132014-03-28 17:52:55 +010051 struct clk *pcie;
Sean Crossbb389192013-09-26 11:24:47 +080052 struct regmap *iomuxc_gpr;
Andrey Smirnov9b3fe672017-03-28 08:42:49 -070053 struct reset_control *pciephy_reset;
54 struct reset_control *apps_reset;
Leonard Crestezf4e833b2018-07-19 17:02:10 +030055 struct reset_control *turnoff_reset;
Andrey Smirnove6f1fef2016-05-02 14:08:21 -050056 enum imx6_pcie_variants variant;
Justin Waters28e3abe2016-01-15 10:24:35 -050057 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 Harveya5fcec42016-04-19 19:52:44 -050062 int link_gen;
Quentin Schulzc26ebe92017-06-08 10:07:42 +020063 struct regulator *vpcie;
Leonard Crestez3f7ccee2018-10-08 18:06:21 +000064
65 /* power domain for pcie */
66 struct device *pd_pcie;
67 /* power domain for pcie phy */
68 struct device *pd_pcie_phy;
Sean Crossbb389192013-09-26 11:24:47 +080069};
70
Andrey Smirnov9b3fe672017-03-28 08:42:49 -070071/* 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 Vasutfa33a6d2013-12-12 22:50:02 +010076/* PCIe Root Complex registers (memory-mapped) */
Richard Zhu75cb8d22018-12-21 04:33:38 +000077#define PCIE_RC_IMX6_MSI_CAP 0x50
Marek Vasutfa33a6d2013-12-12 22:50:02 +010078#define PCIE_RC_LCR 0x7c
79#define PCIE_RC_LCR_MAX_LINK_SPEEDS_GEN1 0x1
80#define PCIE_RC_LCR_MAX_LINK_SPEEDS_GEN2 0x2
81#define PCIE_RC_LCR_MAX_LINK_SPEEDS_MASK 0xf
82
Bjorn Helgaas2393f792015-06-12 17:27:43 -050083#define PCIE_RC_LCSR 0x80
84
Sean Crossbb389192013-09-26 11:24:47 +080085/* PCIe Port Logic registers (memory-mapped) */
86#define PL_OFFSET 0x700
Lucas Stach3e3e4062014-07-31 20:16:05 +020087#define PCIE_PL_PFLR (PL_OFFSET + 0x08)
88#define PCIE_PL_PFLR_LINK_STATE_MASK (0x3f << 16)
89#define PCIE_PL_PFLR_FORCE_LINK (1 << 15)
Sean Crossbb389192013-09-26 11:24:47 +080090#define PCIE_PHY_DEBUG_R0 (PL_OFFSET + 0x28)
91#define PCIE_PHY_DEBUG_R1 (PL_OFFSET + 0x2c)
92
93#define PCIE_PHY_CTRL (PL_OFFSET + 0x114)
94#define PCIE_PHY_CTRL_DATA_LOC 0
95#define PCIE_PHY_CTRL_CAP_ADR_LOC 16
96#define PCIE_PHY_CTRL_CAP_DAT_LOC 17
97#define PCIE_PHY_CTRL_WR_LOC 18
98#define PCIE_PHY_CTRL_RD_LOC 19
99
100#define PCIE_PHY_STAT (PL_OFFSET + 0x110)
101#define PCIE_PHY_STAT_ACK_LOC 16
102
Marek Vasutfa33a6d2013-12-12 22:50:02 +0100103#define PCIE_LINK_WIDTH_SPEED_CONTROL 0x80C
104#define PORT_LOGIC_SPEED_CHANGE (0x1 << 17)
105
Sean Crossbb389192013-09-26 11:24:47 +0800106/* PHY registers (not memory-mapped) */
Lucas Stachf18f42d2018-07-31 12:21:49 +0200107#define PCIE_PHY_ATEOVRD 0x10
108#define PCIE_PHY_ATEOVRD_EN (0x1 << 2)
109#define PCIE_PHY_ATEOVRD_REF_CLKDIV_SHIFT 0
110#define PCIE_PHY_ATEOVRD_REF_CLKDIV_MASK 0x1
111
112#define PCIE_PHY_MPLL_OVRD_IN_LO 0x11
113#define PCIE_PHY_MPLL_MULTIPLIER_SHIFT 2
114#define PCIE_PHY_MPLL_MULTIPLIER_MASK 0x7f
115#define PCIE_PHY_MPLL_MULTIPLIER_OVRD (0x1 << 9)
116
Sean Crossbb389192013-09-26 11:24:47 +0800117#define PCIE_PHY_RX_ASIC_OUT 0x100D
Fabio Estevam111feb72015-09-11 09:08:53 -0300118#define PCIE_PHY_RX_ASIC_OUT_VALID (1 << 0)
Sean Crossbb389192013-09-26 11:24:47 +0800119
120#define PHY_RX_OVRD_IN_LO 0x1005
121#define PHY_RX_OVRD_IN_LO_RX_DATA_EN (1 << 5)
122#define PHY_RX_OVRD_IN_LO_RX_PLL_EN (1 << 3)
123
Bjorn Helgaas8bad7f22016-10-11 22:09:32 -0500124static int pcie_phy_poll_ack(struct imx6_pcie *imx6_pcie, int exp_val)
Sean Crossbb389192013-09-26 11:24:47 +0800125{
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530126 struct dw_pcie *pci = imx6_pcie->pci;
Sean Crossbb389192013-09-26 11:24:47 +0800127 u32 val;
128 u32 max_iterations = 10;
129 u32 wait_counter = 0;
130
131 do {
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530132 val = dw_pcie_readl_dbi(pci, PCIE_PHY_STAT);
Sean Crossbb389192013-09-26 11:24:47 +0800133 val = (val >> PCIE_PHY_STAT_ACK_LOC) & 0x1;
134 wait_counter++;
135
136 if (val == exp_val)
137 return 0;
138
139 udelay(1);
140 } while (wait_counter < max_iterations);
141
142 return -ETIMEDOUT;
143}
144
Bjorn Helgaas8bad7f22016-10-11 22:09:32 -0500145static int pcie_phy_wait_ack(struct imx6_pcie *imx6_pcie, int addr)
Sean Crossbb389192013-09-26 11:24:47 +0800146{
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530147 struct dw_pcie *pci = imx6_pcie->pci;
Sean Crossbb389192013-09-26 11:24:47 +0800148 u32 val;
149 int ret;
150
151 val = addr << PCIE_PHY_CTRL_DATA_LOC;
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530152 dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, val);
Sean Crossbb389192013-09-26 11:24:47 +0800153
154 val |= (0x1 << PCIE_PHY_CTRL_CAP_ADR_LOC);
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530155 dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, val);
Sean Crossbb389192013-09-26 11:24:47 +0800156
Bjorn Helgaas8bad7f22016-10-11 22:09:32 -0500157 ret = pcie_phy_poll_ack(imx6_pcie, 1);
Sean Crossbb389192013-09-26 11:24:47 +0800158 if (ret)
159 return ret;
160
161 val = addr << PCIE_PHY_CTRL_DATA_LOC;
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530162 dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, val);
Sean Crossbb389192013-09-26 11:24:47 +0800163
Bjorn Helgaas8bad7f22016-10-11 22:09:32 -0500164 return pcie_phy_poll_ack(imx6_pcie, 0);
Sean Crossbb389192013-09-26 11:24:47 +0800165}
166
167/* Read from the 16-bit PCIe PHY control registers (not memory-mapped) */
Bjorn Helgaas8bad7f22016-10-11 22:09:32 -0500168static int pcie_phy_read(struct imx6_pcie *imx6_pcie, int addr, int *data)
Sean Crossbb389192013-09-26 11:24:47 +0800169{
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530170 struct dw_pcie *pci = imx6_pcie->pci;
Sean Crossbb389192013-09-26 11:24:47 +0800171 u32 val, phy_ctl;
172 int ret;
173
Bjorn Helgaas8bad7f22016-10-11 22:09:32 -0500174 ret = pcie_phy_wait_ack(imx6_pcie, addr);
Sean Crossbb389192013-09-26 11:24:47 +0800175 if (ret)
176 return ret;
177
178 /* assert Read signal */
179 phy_ctl = 0x1 << PCIE_PHY_CTRL_RD_LOC;
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530180 dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, phy_ctl);
Sean Crossbb389192013-09-26 11:24:47 +0800181
Bjorn Helgaas8bad7f22016-10-11 22:09:32 -0500182 ret = pcie_phy_poll_ack(imx6_pcie, 1);
Sean Crossbb389192013-09-26 11:24:47 +0800183 if (ret)
184 return ret;
185
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530186 val = dw_pcie_readl_dbi(pci, PCIE_PHY_STAT);
Sean Crossbb389192013-09-26 11:24:47 +0800187 *data = val & 0xffff;
188
189 /* deassert Read signal */
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530190 dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, 0x00);
Sean Crossbb389192013-09-26 11:24:47 +0800191
Bjorn Helgaas8bad7f22016-10-11 22:09:32 -0500192 return pcie_phy_poll_ack(imx6_pcie, 0);
Sean Crossbb389192013-09-26 11:24:47 +0800193}
194
Bjorn Helgaas8bad7f22016-10-11 22:09:32 -0500195static int pcie_phy_write(struct imx6_pcie *imx6_pcie, int addr, int data)
Sean Crossbb389192013-09-26 11:24:47 +0800196{
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530197 struct dw_pcie *pci = imx6_pcie->pci;
Sean Crossbb389192013-09-26 11:24:47 +0800198 u32 var;
199 int ret;
200
201 /* write addr */
202 /* cap addr */
Bjorn Helgaas8bad7f22016-10-11 22:09:32 -0500203 ret = pcie_phy_wait_ack(imx6_pcie, addr);
Sean Crossbb389192013-09-26 11:24:47 +0800204 if (ret)
205 return ret;
206
207 var = data << PCIE_PHY_CTRL_DATA_LOC;
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530208 dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, var);
Sean Crossbb389192013-09-26 11:24:47 +0800209
210 /* capture data */
211 var |= (0x1 << PCIE_PHY_CTRL_CAP_DAT_LOC);
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530212 dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, var);
Sean Crossbb389192013-09-26 11:24:47 +0800213
Bjorn Helgaas8bad7f22016-10-11 22:09:32 -0500214 ret = pcie_phy_poll_ack(imx6_pcie, 1);
Sean Crossbb389192013-09-26 11:24:47 +0800215 if (ret)
216 return ret;
217
218 /* deassert cap data */
219 var = data << PCIE_PHY_CTRL_DATA_LOC;
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530220 dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, var);
Sean Crossbb389192013-09-26 11:24:47 +0800221
222 /* wait for ack de-assertion */
Bjorn Helgaas8bad7f22016-10-11 22:09:32 -0500223 ret = pcie_phy_poll_ack(imx6_pcie, 0);
Sean Crossbb389192013-09-26 11:24:47 +0800224 if (ret)
225 return ret;
226
227 /* assert wr signal */
228 var = 0x1 << PCIE_PHY_CTRL_WR_LOC;
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530229 dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, var);
Sean Crossbb389192013-09-26 11:24:47 +0800230
231 /* wait for ack */
Bjorn Helgaas8bad7f22016-10-11 22:09:32 -0500232 ret = pcie_phy_poll_ack(imx6_pcie, 1);
Sean Crossbb389192013-09-26 11:24:47 +0800233 if (ret)
234 return ret;
235
236 /* deassert wr signal */
237 var = data << PCIE_PHY_CTRL_DATA_LOC;
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530238 dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, var);
Sean Crossbb389192013-09-26 11:24:47 +0800239
240 /* wait for ack de-assertion */
Bjorn Helgaas8bad7f22016-10-11 22:09:32 -0500241 ret = pcie_phy_poll_ack(imx6_pcie, 0);
Sean Crossbb389192013-09-26 11:24:47 +0800242 if (ret)
243 return ret;
244
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530245 dw_pcie_writel_dbi(pci, PCIE_PHY_CTRL, 0x0);
Sean Crossbb389192013-09-26 11:24:47 +0800246
247 return 0;
248}
249
Bjorn Helgaase7d77052016-10-11 22:06:47 -0500250static void imx6_pcie_reset_phy(struct imx6_pcie *imx6_pcie)
Lucas Stach53eeb482016-01-15 19:56:47 +0100251{
252 u32 tmp;
253
Bjorn Helgaas8bad7f22016-10-11 22:09:32 -0500254 pcie_phy_read(imx6_pcie, PHY_RX_OVRD_IN_LO, &tmp);
Lucas Stach53eeb482016-01-15 19:56:47 +0100255 tmp |= (PHY_RX_OVRD_IN_LO_RX_DATA_EN |
256 PHY_RX_OVRD_IN_LO_RX_PLL_EN);
Bjorn Helgaas8bad7f22016-10-11 22:09:32 -0500257 pcie_phy_write(imx6_pcie, PHY_RX_OVRD_IN_LO, tmp);
Lucas Stach53eeb482016-01-15 19:56:47 +0100258
259 usleep_range(2000, 3000);
260
Bjorn Helgaas8bad7f22016-10-11 22:09:32 -0500261 pcie_phy_read(imx6_pcie, PHY_RX_OVRD_IN_LO, &tmp);
Lucas Stach53eeb482016-01-15 19:56:47 +0100262 tmp &= ~(PHY_RX_OVRD_IN_LO_RX_DATA_EN |
263 PHY_RX_OVRD_IN_LO_RX_PLL_EN);
Bjorn Helgaas8bad7f22016-10-11 22:09:32 -0500264 pcie_phy_write(imx6_pcie, PHY_RX_OVRD_IN_LO, tmp);
Lucas Stach53eeb482016-01-15 19:56:47 +0100265}
266
Sean Crossbb389192013-09-26 11:24:47 +0800267/* Added for PCI abort handling */
268static int imx6q_pcie_abort_handler(unsigned long addr,
269 unsigned int fsr, struct pt_regs *regs)
270{
Lucas Stach415b6182017-05-22 17:06:30 -0500271 unsigned long pc = instruction_pointer(regs);
272 unsigned long instr = *(unsigned long *)pc;
273 int reg = (instr >> 12) & 15;
274
275 /*
276 * If the instruction being executed was a read,
277 * make it look like it read all-ones.
278 */
279 if ((instr & 0x0c100000) == 0x04100000) {
280 unsigned long val;
281
282 if (instr & 0x00400000)
283 val = 255;
284 else
285 val = -1;
286
287 regs->uregs[reg] = val;
288 regs->ARM_pc += 4;
289 return 0;
290 }
291
292 if ((instr & 0x0e100090) == 0x00100090) {
293 regs->uregs[reg] = -1;
294 regs->ARM_pc += 4;
295 return 0;
296 }
297
298 return 1;
Sean Crossbb389192013-09-26 11:24:47 +0800299}
300
Leonard Crestez3f7ccee2018-10-08 18:06:21 +0000301static int imx6_pcie_attach_pd(struct device *dev)
302{
303 struct imx6_pcie *imx6_pcie = dev_get_drvdata(dev);
304 struct device_link *link;
305
306 /* Do nothing when in a single power domain */
307 if (dev->pm_domain)
308 return 0;
309
310 imx6_pcie->pd_pcie = dev_pm_domain_attach_by_name(dev, "pcie");
311 if (IS_ERR(imx6_pcie->pd_pcie))
312 return PTR_ERR(imx6_pcie->pd_pcie);
Leonard Cresteza6093ad2019-01-31 14:59:50 -0600313 /* Do nothing when power domain missing */
314 if (!imx6_pcie->pd_pcie)
315 return 0;
Leonard Crestez3f7ccee2018-10-08 18:06:21 +0000316 link = device_link_add(dev, imx6_pcie->pd_pcie,
317 DL_FLAG_STATELESS |
318 DL_FLAG_PM_RUNTIME |
319 DL_FLAG_RPM_ACTIVE);
320 if (!link) {
321 dev_err(dev, "Failed to add device_link to pcie pd.\n");
322 return -EINVAL;
323 }
324
325 imx6_pcie->pd_pcie_phy = dev_pm_domain_attach_by_name(dev, "pcie_phy");
326 if (IS_ERR(imx6_pcie->pd_pcie_phy))
327 return PTR_ERR(imx6_pcie->pd_pcie_phy);
328
329 device_link_add(dev, imx6_pcie->pd_pcie_phy,
330 DL_FLAG_STATELESS |
331 DL_FLAG_PM_RUNTIME |
332 DL_FLAG_RPM_ACTIVE);
333 if (IS_ERR(link)) {
334 dev_err(dev, "Failed to add device_link to pcie_phy pd: %ld\n", PTR_ERR(link));
335 return PTR_ERR(link);
336 }
337
338 return 0;
339}
340
Bjorn Helgaas9ab021b2016-10-06 13:35:17 -0500341static void imx6_pcie_assert_core_reset(struct imx6_pcie *imx6_pcie)
Sean Crossbb389192013-09-26 11:24:47 +0800342{
Quentin Schulzc26ebe92017-06-08 10:07:42 +0200343 struct device *dev = imx6_pcie->pci->dev;
344
Andrey Smirnove6f1fef2016-05-02 14:08:21 -0500345 switch (imx6_pcie->variant) {
Andrey Smirnov9b3fe672017-03-28 08:42:49 -0700346 case IMX7D:
347 reset_control_assert(imx6_pcie->pciephy_reset);
348 reset_control_assert(imx6_pcie->apps_reset);
349 break;
Andrey Smirnove6f1fef2016-05-02 14:08:21 -0500350 case IMX6SX:
Christoph Fritze3c06cd2016-04-05 16:53:27 -0500351 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
352 IMX6SX_GPR12_PCIE_TEST_POWERDOWN,
353 IMX6SX_GPR12_PCIE_TEST_POWERDOWN);
354 /* Force PCIe PHY reset */
355 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR5,
356 IMX6SX_GPR5_PCIE_BTNRST_RESET,
357 IMX6SX_GPR5_PCIE_BTNRST_RESET);
Andrey Smirnove6f1fef2016-05-02 14:08:21 -0500358 break;
Andrey Smirnov4d31c612016-05-02 14:09:10 -0500359 case IMX6QP:
360 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1,
361 IMX6Q_GPR1_PCIE_SW_RST,
362 IMX6Q_GPR1_PCIE_SW_RST);
363 break;
Andrey Smirnove6f1fef2016-05-02 14:08:21 -0500364 case IMX6Q:
Andrey Smirnove6f1fef2016-05-02 14:08:21 -0500365 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1,
366 IMX6Q_GPR1_PCIE_TEST_PD, 1 << 18);
367 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1,
368 IMX6Q_GPR1_PCIE_REF_CLK_EN, 0 << 16);
369 break;
Christoph Fritze3c06cd2016-04-05 16:53:27 -0500370 }
Quentin Schulzc26ebe92017-06-08 10:07:42 +0200371
372 if (imx6_pcie->vpcie && regulator_is_enabled(imx6_pcie->vpcie) > 0) {
373 int ret = regulator_disable(imx6_pcie->vpcie);
374
375 if (ret)
376 dev_err(dev, "failed to disable vpcie regulator: %d\n",
377 ret);
378 }
Sean Crossbb389192013-09-26 11:24:47 +0800379}
380
Bjorn Helgaas4d1821e2016-03-14 00:30:55 +0100381static int imx6_pcie_enable_ref_clk(struct imx6_pcie *imx6_pcie)
382{
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530383 struct dw_pcie *pci = imx6_pcie->pci;
384 struct device *dev = pci->dev;
Andrey Smirnove6f1fef2016-05-02 14:08:21 -0500385 int ret = 0;
Christoph Fritze3c06cd2016-04-05 16:53:27 -0500386
Andrey Smirnove6f1fef2016-05-02 14:08:21 -0500387 switch (imx6_pcie->variant) {
388 case IMX6SX:
Christoph Fritze3c06cd2016-04-05 16:53:27 -0500389 ret = clk_prepare_enable(imx6_pcie->pcie_inbound_axi);
390 if (ret) {
Bjorn Helgaas13957652016-10-06 13:35:18 -0500391 dev_err(dev, "unable to enable pcie_axi clock\n");
Andrey Smirnove6f1fef2016-05-02 14:08:21 -0500392 break;
Christoph Fritze3c06cd2016-04-05 16:53:27 -0500393 }
394
395 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
396 IMX6SX_GPR12_PCIE_TEST_POWERDOWN, 0);
Andrey Smirnove6f1fef2016-05-02 14:08:21 -0500397 break;
Fabio Estevamc27fd682018-05-09 14:01:48 -0300398 case IMX6QP: /* FALLTHROUGH */
Andrey Smirnove6f1fef2016-05-02 14:08:21 -0500399 case IMX6Q:
400 /* power up core phy and enable ref clock */
401 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1,
402 IMX6Q_GPR1_PCIE_TEST_PD, 0 << 18);
403 /*
404 * the async reset input need ref clock to sync internally,
405 * when the ref clock comes after reset, internal synced
406 * reset time is too short, cannot meet the requirement.
407 * add one ~10us delay here.
408 */
409 udelay(10);
410 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1,
411 IMX6Q_GPR1_PCIE_REF_CLK_EN, 1 << 16);
412 break;
Andrey Smirnov9b3fe672017-03-28 08:42:49 -0700413 case IMX7D:
414 break;
Christoph Fritze3c06cd2016-04-05 16:53:27 -0500415 }
416
Andrey Smirnove6f1fef2016-05-02 14:08:21 -0500417 return ret;
Bjorn Helgaas4d1821e2016-03-14 00:30:55 +0100418}
419
Andrey Smirnov9b3fe672017-03-28 08:42:49 -0700420static void imx7d_pcie_wait_for_phy_pll_lock(struct imx6_pcie *imx6_pcie)
421{
422 u32 val;
423 unsigned int retries;
424 struct device *dev = imx6_pcie->pci->dev;
425
426 for (retries = 0; retries < PHY_PLL_LOCK_WAIT_MAX_RETRIES; retries++) {
427 regmap_read(imx6_pcie->iomuxc_gpr, IOMUXC_GPR22, &val);
428
429 if (val & IMX7D_GPR22_PCIE_PHY_PLL_LOCKED)
430 return;
431
432 usleep_range(PHY_PLL_LOCK_WAIT_USLEEP_MIN,
433 PHY_PLL_LOCK_WAIT_USLEEP_MAX);
434 }
435
436 dev_err(dev, "PCIe PLL lock timeout\n");
437}
438
Bjorn Helgaas9ab021b2016-10-06 13:35:17 -0500439static void imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
Sean Crossbb389192013-09-26 11:24:47 +0800440{
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530441 struct dw_pcie *pci = imx6_pcie->pci;
442 struct device *dev = pci->dev;
Sean Crossbb389192013-09-26 11:24:47 +0800443 int ret;
444
Quentin Schulzc26ebe92017-06-08 10:07:42 +0200445 if (imx6_pcie->vpcie && !regulator_is_enabled(imx6_pcie->vpcie)) {
446 ret = regulator_enable(imx6_pcie->vpcie);
447 if (ret) {
448 dev_err(dev, "failed to enable vpcie regulator: %d\n",
449 ret);
450 return;
451 }
452 }
453
Lucas Stach57526132014-03-28 17:52:55 +0100454 ret = clk_prepare_enable(imx6_pcie->pcie_phy);
Sean Crossbb389192013-09-26 11:24:47 +0800455 if (ret) {
Bjorn Helgaas13957652016-10-06 13:35:18 -0500456 dev_err(dev, "unable to enable pcie_phy clock\n");
Quentin Schulzc26ebe92017-06-08 10:07:42 +0200457 goto err_pcie_phy;
Sean Crossbb389192013-09-26 11:24:47 +0800458 }
459
Lucas Stach57526132014-03-28 17:52:55 +0100460 ret = clk_prepare_enable(imx6_pcie->pcie_bus);
Sean Crossbb389192013-09-26 11:24:47 +0800461 if (ret) {
Bjorn Helgaas13957652016-10-06 13:35:18 -0500462 dev_err(dev, "unable to enable pcie_bus clock\n");
Lucas Stach57526132014-03-28 17:52:55 +0100463 goto err_pcie_bus;
Sean Crossbb389192013-09-26 11:24:47 +0800464 }
465
Lucas Stach57526132014-03-28 17:52:55 +0100466 ret = clk_prepare_enable(imx6_pcie->pcie);
Sean Crossbb389192013-09-26 11:24:47 +0800467 if (ret) {
Bjorn Helgaas13957652016-10-06 13:35:18 -0500468 dev_err(dev, "unable to enable pcie clock\n");
Lucas Stach57526132014-03-28 17:52:55 +0100469 goto err_pcie;
Sean Crossbb389192013-09-26 11:24:47 +0800470 }
471
Bjorn Helgaas4d1821e2016-03-14 00:30:55 +0100472 ret = imx6_pcie_enable_ref_clk(imx6_pcie);
473 if (ret) {
Bjorn Helgaas13957652016-10-06 13:35:18 -0500474 dev_err(dev, "unable to enable pcie ref clock\n");
Bjorn Helgaas4d1821e2016-03-14 00:30:55 +0100475 goto err_ref_clk;
476 }
Tim Harvey3fce0e82014-08-07 23:36:40 -0700477
Richard Zhua2fa6f62014-10-27 13:17:32 +0800478 /* allow the clocks to stabilize */
479 usleep_range(200, 500);
480
Richard Zhubc9ef772013-12-12 22:50:03 +0100481 /* Some boards don't have PCIe reset GPIO. */
Fabio Estevamb2d7a9c2016-03-28 18:45:36 -0300482 if (gpio_is_valid(imx6_pcie->reset_gpio)) {
Petr Štetiar3ea8529a2016-04-19 19:42:07 -0500483 gpio_set_value_cansleep(imx6_pcie->reset_gpio,
484 imx6_pcie->gpio_active_high);
Richard Zhubc9ef772013-12-12 22:50:03 +0100485 msleep(100);
Petr Štetiar3ea8529a2016-04-19 19:42:07 -0500486 gpio_set_value_cansleep(imx6_pcie->reset_gpio,
487 !imx6_pcie->gpio_active_high);
Richard Zhubc9ef772013-12-12 22:50:03 +0100488 }
Christoph Fritze3c06cd2016-04-05 16:53:27 -0500489
Andrey Smirnov4d31c612016-05-02 14:09:10 -0500490 switch (imx6_pcie->variant) {
Andrey Smirnov9b3fe672017-03-28 08:42:49 -0700491 case IMX7D:
492 reset_control_deassert(imx6_pcie->pciephy_reset);
493 imx7d_pcie_wait_for_phy_pll_lock(imx6_pcie);
494 break;
Andrey Smirnov4d31c612016-05-02 14:09:10 -0500495 case IMX6SX:
Christoph Fritze3c06cd2016-04-05 16:53:27 -0500496 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR5,
497 IMX6SX_GPR5_PCIE_BTNRST_RESET, 0);
Andrey Smirnov4d31c612016-05-02 14:09:10 -0500498 break;
499 case IMX6QP:
500 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1,
501 IMX6Q_GPR1_PCIE_SW_RST, 0);
502
503 usleep_range(200, 500);
504 break;
505 case IMX6Q: /* Nothing to do */
506 break;
507 }
Christoph Fritze3c06cd2016-04-05 16:53:27 -0500508
Bjorn Helgaas9ab021b2016-10-06 13:35:17 -0500509 return;
Sean Crossbb389192013-09-26 11:24:47 +0800510
Bjorn Helgaas4d1821e2016-03-14 00:30:55 +0100511err_ref_clk:
512 clk_disable_unprepare(imx6_pcie->pcie);
Lucas Stach57526132014-03-28 17:52:55 +0100513err_pcie:
514 clk_disable_unprepare(imx6_pcie->pcie_bus);
515err_pcie_bus:
516 clk_disable_unprepare(imx6_pcie->pcie_phy);
Quentin Schulzc26ebe92017-06-08 10:07:42 +0200517err_pcie_phy:
518 if (imx6_pcie->vpcie && regulator_is_enabled(imx6_pcie->vpcie) > 0) {
519 ret = regulator_disable(imx6_pcie->vpcie);
520 if (ret)
521 dev_err(dev, "failed to disable vpcie regulator: %d\n",
522 ret);
523 }
Sean Crossbb389192013-09-26 11:24:47 +0800524}
525
Bjorn Helgaase7d77052016-10-11 22:06:47 -0500526static void imx6_pcie_init_phy(struct imx6_pcie *imx6_pcie)
Sean Crossbb389192013-09-26 11:24:47 +0800527{
Andrey Smirnov9b3fe672017-03-28 08:42:49 -0700528 switch (imx6_pcie->variant) {
529 case IMX7D:
530 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
531 IMX7D_GPR12_PCIE_PHY_REFCLK_SEL, 0);
532 break;
533 case IMX6SX:
Christoph Fritze3c06cd2016-04-05 16:53:27 -0500534 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
535 IMX6SX_GPR12_PCIE_RX_EQ_MASK,
536 IMX6SX_GPR12_PCIE_RX_EQ_2);
Andrey Smirnov9b3fe672017-03-28 08:42:49 -0700537 /* FALLTHROUGH */
538 default:
539 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
540 IMX6Q_GPR12_PCIE_CTL_2, 0 << 10);
Christoph Fritze3c06cd2016-04-05 16:53:27 -0500541
Andrey Smirnov9b3fe672017-03-28 08:42:49 -0700542 /* configure constant input signal to the pcie ctrl and phy */
543 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
544 IMX6Q_GPR12_LOS_LEVEL, 9 << 4);
Sean Crossbb389192013-09-26 11:24:47 +0800545
Andrey Smirnov9b3fe672017-03-28 08:42:49 -0700546 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR8,
547 IMX6Q_GPR8_TX_DEEMPH_GEN1,
548 imx6_pcie->tx_deemph_gen1 << 0);
549 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR8,
550 IMX6Q_GPR8_TX_DEEMPH_GEN2_3P5DB,
551 imx6_pcie->tx_deemph_gen2_3p5db << 6);
552 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR8,
553 IMX6Q_GPR8_TX_DEEMPH_GEN2_6DB,
554 imx6_pcie->tx_deemph_gen2_6db << 12);
555 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR8,
556 IMX6Q_GPR8_TX_SWING_FULL,
557 imx6_pcie->tx_swing_full << 18);
558 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR8,
559 IMX6Q_GPR8_TX_SWING_LOW,
560 imx6_pcie->tx_swing_low << 25);
561 break;
562 }
563
Sean Crossbb389192013-09-26 11:24:47 +0800564 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
565 IMX6Q_GPR12_DEVICE_TYPE, PCI_EXP_TYPE_ROOT_PORT << 12);
Sean Crossbb389192013-09-26 11:24:47 +0800566}
567
Lucas Stachf18f42d2018-07-31 12:21:49 +0200568static int imx6_setup_phy_mpll(struct imx6_pcie *imx6_pcie)
569{
570 unsigned long phy_rate = clk_get_rate(imx6_pcie->pcie_phy);
571 int mult, div;
572 u32 val;
573
574 switch (phy_rate) {
575 case 125000000:
576 /*
577 * The default settings of the MPLL are for a 125MHz input
578 * clock, so no need to reconfigure anything in that case.
579 */
580 return 0;
581 case 100000000:
582 mult = 25;
583 div = 0;
584 break;
585 case 200000000:
586 mult = 25;
587 div = 1;
588 break;
589 default:
590 dev_err(imx6_pcie->pci->dev,
591 "Unsupported PHY reference clock rate %lu\n", phy_rate);
592 return -EINVAL;
593 }
594
595 pcie_phy_read(imx6_pcie, PCIE_PHY_MPLL_OVRD_IN_LO, &val);
596 val &= ~(PCIE_PHY_MPLL_MULTIPLIER_MASK <<
597 PCIE_PHY_MPLL_MULTIPLIER_SHIFT);
598 val |= mult << PCIE_PHY_MPLL_MULTIPLIER_SHIFT;
599 val |= PCIE_PHY_MPLL_MULTIPLIER_OVRD;
600 pcie_phy_write(imx6_pcie, PCIE_PHY_MPLL_OVRD_IN_LO, val);
601
602 pcie_phy_read(imx6_pcie, PCIE_PHY_ATEOVRD, &val);
603 val &= ~(PCIE_PHY_ATEOVRD_REF_CLKDIV_MASK <<
604 PCIE_PHY_ATEOVRD_REF_CLKDIV_SHIFT);
605 val |= div << PCIE_PHY_ATEOVRD_REF_CLKDIV_SHIFT;
606 val |= PCIE_PHY_ATEOVRD_EN;
607 pcie_phy_write(imx6_pcie, PCIE_PHY_ATEOVRD, val);
608
609 return 0;
610}
611
Bjorn Helgaase7d77052016-10-11 22:06:47 -0500612static int imx6_pcie_wait_for_link(struct imx6_pcie *imx6_pcie)
Marek Vasut66a60f92013-12-12 22:50:01 +0100613{
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530614 struct dw_pcie *pci = imx6_pcie->pci;
615 struct device *dev = pci->dev;
Bjorn Helgaas13957652016-10-06 13:35:18 -0500616
Joao Pinto886bc5c2016-03-10 14:44:35 -0600617 /* check if the link is up or not */
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530618 if (!dw_pcie_wait_for_link(pci))
Joao Pinto886bc5c2016-03-10 14:44:35 -0600619 return 0;
Marek Vasut66a60f92013-12-12 22:50:01 +0100620
Bjorn Helgaas13957652016-10-06 13:35:18 -0500621 dev_dbg(dev, "DEBUG_R0: 0x%08x, DEBUG_R1: 0x%08x\n",
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530622 dw_pcie_readl_dbi(pci, PCIE_PHY_DEBUG_R0),
623 dw_pcie_readl_dbi(pci, PCIE_PHY_DEBUG_R1));
Joao Pinto886bc5c2016-03-10 14:44:35 -0600624 return -ETIMEDOUT;
Marek Vasut66a60f92013-12-12 22:50:01 +0100625}
626
Bjorn Helgaase7d77052016-10-11 22:06:47 -0500627static int imx6_pcie_wait_for_speed_change(struct imx6_pcie *imx6_pcie)
Troy Kiskya0427462015-06-12 14:30:16 -0500628{
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530629 struct dw_pcie *pci = imx6_pcie->pci;
630 struct device *dev = pci->dev;
Bjorn Helgaas1c7fae12015-06-12 15:02:49 -0500631 u32 tmp;
Troy Kiskya0427462015-06-12 14:30:16 -0500632 unsigned int retries;
633
634 for (retries = 0; retries < 200; retries++) {
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530635 tmp = dw_pcie_readl_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL);
Troy Kiskya0427462015-06-12 14:30:16 -0500636 /* Test if the speed change finished. */
637 if (!(tmp & PORT_LOGIC_SPEED_CHANGE))
638 return 0;
639 usleep_range(100, 1000);
640 }
641
Bjorn Helgaas13957652016-10-06 13:35:18 -0500642 dev_err(dev, "Speed change timeout\n");
Troy Kiskya0427462015-06-12 14:30:16 -0500643 return -EINVAL;
Sean Crossbb389192013-09-26 11:24:47 +0800644}
645
Leonard Crestez0ee2c1f2018-08-27 14:28:37 +0300646static void imx6_pcie_ltssm_enable(struct device *dev)
647{
648 struct imx6_pcie *imx6_pcie = dev_get_drvdata(dev);
649
650 switch (imx6_pcie->variant) {
651 case IMX6Q:
652 case IMX6SX:
653 case IMX6QP:
654 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
655 IMX6Q_GPR12_PCIE_CTL_2,
656 IMX6Q_GPR12_PCIE_CTL_2);
657 break;
658 case IMX7D:
659 reset_control_deassert(imx6_pcie->apps_reset);
660 break;
661 }
662}
663
Bjorn Helgaase7d77052016-10-11 22:06:47 -0500664static int imx6_pcie_establish_link(struct imx6_pcie *imx6_pcie)
Marek Vasutfa33a6d2013-12-12 22:50:02 +0100665{
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530666 struct dw_pcie *pci = imx6_pcie->pci;
667 struct device *dev = pci->dev;
Bjorn Helgaas1c7fae12015-06-12 15:02:49 -0500668 u32 tmp;
Troy Kiskya0427462015-06-12 14:30:16 -0500669 int ret;
Marek Vasutfa33a6d2013-12-12 22:50:02 +0100670
671 /*
672 * Force Gen1 operation when starting the link. In case the link is
673 * started in Gen2 mode, there is a possibility the devices on the
674 * bus will not be detected at all. This happens with PCIe switches.
675 */
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530676 tmp = dw_pcie_readl_dbi(pci, PCIE_RC_LCR);
Marek Vasutfa33a6d2013-12-12 22:50:02 +0100677 tmp &= ~PCIE_RC_LCR_MAX_LINK_SPEEDS_MASK;
678 tmp |= PCIE_RC_LCR_MAX_LINK_SPEEDS_GEN1;
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530679 dw_pcie_writel_dbi(pci, PCIE_RC_LCR, tmp);
Marek Vasutfa33a6d2013-12-12 22:50:02 +0100680
681 /* Start LTSSM. */
Leonard Crestez0ee2c1f2018-08-27 14:28:37 +0300682 imx6_pcie_ltssm_enable(dev);
Marek Vasutfa33a6d2013-12-12 22:50:02 +0100683
Bjorn Helgaase7d77052016-10-11 22:06:47 -0500684 ret = imx6_pcie_wait_for_link(imx6_pcie);
Fabio Estevamcaf3f562016-12-27 12:40:43 -0200685 if (ret)
Lucas Stach54a47a82016-01-25 16:49:53 -0600686 goto err_reset_phy;
Marek Vasutfa33a6d2013-12-12 22:50:02 +0100687
Tim Harveya5fcec42016-04-19 19:52:44 -0500688 if (imx6_pcie->link_gen == 2) {
689 /* Allow Gen2 mode after the link is up. */
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530690 tmp = dw_pcie_readl_dbi(pci, PCIE_RC_LCR);
Tim Harveya5fcec42016-04-19 19:52:44 -0500691 tmp &= ~PCIE_RC_LCR_MAX_LINK_SPEEDS_MASK;
692 tmp |= PCIE_RC_LCR_MAX_LINK_SPEEDS_GEN2;
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530693 dw_pcie_writel_dbi(pci, PCIE_RC_LCR, tmp);
Marek Vasutfa33a6d2013-12-12 22:50:02 +0100694
Andrey Smirnove6dcd872017-03-28 08:42:51 -0700695 /*
Andrey Smirnov93b226f2017-03-28 08:42:52 -0700696 * Start Directed Speed Change so the best possible
697 * speed both link partners support can be negotiated.
Andrey Smirnove6dcd872017-03-28 08:42:51 -0700698 */
Andrey Smirnov93b226f2017-03-28 08:42:52 -0700699 tmp = dw_pcie_readl_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL);
700 tmp |= PORT_LOGIC_SPEED_CHANGE;
701 dw_pcie_writel_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL, tmp);
Andrey Smirnove6dcd872017-03-28 08:42:51 -0700702
Andrey Smirnov93b226f2017-03-28 08:42:52 -0700703 if (imx6_pcie->variant != IMX7D) {
704 /*
705 * On i.MX7, DIRECT_SPEED_CHANGE behaves differently
706 * from i.MX6 family when no link speed transition
707 * occurs and we go Gen1 -> yep, Gen1. The difference
708 * is that, in such case, it will not be cleared by HW
709 * which will cause the following code to report false
710 * failure.
711 */
712
713 ret = imx6_pcie_wait_for_speed_change(imx6_pcie);
714 if (ret) {
715 dev_err(dev, "Failed to bring link up!\n");
716 goto err_reset_phy;
717 }
718 }
719
720 /* Make sure link training is finished as well! */
721 ret = imx6_pcie_wait_for_link(imx6_pcie);
Andrey Smirnove6dcd872017-03-28 08:42:51 -0700722 if (ret) {
723 dev_err(dev, "Failed to bring link up!\n");
724 goto err_reset_phy;
725 }
Andrey Smirnov93b226f2017-03-28 08:42:52 -0700726 } else {
727 dev_info(dev, "Link: Gen2 disabled\n");
Marek Vasutfa33a6d2013-12-12 22:50:02 +0100728 }
729
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530730 tmp = dw_pcie_readl_dbi(pci, PCIE_RC_LCSR);
Bjorn Helgaas13957652016-10-06 13:35:18 -0500731 dev_info(dev, "Link up, Gen%i\n", (tmp >> 16) & 0xf);
Troy Kiskya0427462015-06-12 14:30:16 -0500732 return 0;
Lucas Stach54a47a82016-01-25 16:49:53 -0600733
734err_reset_phy:
Bjorn Helgaas13957652016-10-06 13:35:18 -0500735 dev_dbg(dev, "PHY DEBUG_R0=0x%08x DEBUG_R1=0x%08x\n",
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530736 dw_pcie_readl_dbi(pci, PCIE_PHY_DEBUG_R0),
737 dw_pcie_readl_dbi(pci, PCIE_PHY_DEBUG_R1));
Bjorn Helgaas2a6a85d2016-10-11 22:18:26 -0500738 imx6_pcie_reset_phy(imx6_pcie);
Lucas Stach54a47a82016-01-25 16:49:53 -0600739 return ret;
Marek Vasutfa33a6d2013-12-12 22:50:02 +0100740}
741
Bjorn Andersson4a301762017-07-15 23:39:45 -0700742static int imx6_pcie_host_init(struct pcie_port *pp)
Sean Crossbb389192013-09-26 11:24:47 +0800743{
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530744 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
745 struct imx6_pcie *imx6_pcie = to_imx6_pcie(pci);
Sean Crossbb389192013-09-26 11:24:47 +0800746
Bjorn Helgaase7d77052016-10-11 22:06:47 -0500747 imx6_pcie_assert_core_reset(imx6_pcie);
748 imx6_pcie_init_phy(imx6_pcie);
749 imx6_pcie_deassert_core_reset(imx6_pcie);
Lucas Stachf18f42d2018-07-31 12:21:49 +0200750 imx6_setup_phy_mpll(imx6_pcie);
Sean Crossbb389192013-09-26 11:24:47 +0800751 dw_pcie_setup_rc(pp);
Bjorn Helgaase7d77052016-10-11 22:06:47 -0500752 imx6_pcie_establish_link(imx6_pcie);
Lucas Stachd1dc9742014-03-28 17:52:59 +0100753
754 if (IS_ENABLED(CONFIG_PCI_MSI))
755 dw_pcie_msi_init(pp);
Bjorn Andersson4a301762017-07-15 23:39:45 -0700756
757 return 0;
Sean Crossbb389192013-09-26 11:24:47 +0800758}
759
Jisheng Zhang4ab2e7c2017-06-05 16:53:46 +0800760static const struct dw_pcie_host_ops imx6_pcie_host_ops = {
Sean Crossbb389192013-09-26 11:24:47 +0800761 .host_init = imx6_pcie_host_init,
762};
763
Andrey Smirnovbde4a5a2017-03-28 08:42:50 -0700764static int imx6_add_pcie_port(struct imx6_pcie *imx6_pcie,
765 struct platform_device *pdev)
Sean Crossbb389192013-09-26 11:24:47 +0800766{
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530767 struct dw_pcie *pci = imx6_pcie->pci;
768 struct pcie_port *pp = &pci->pp;
769 struct device *dev = &pdev->dev;
Sean Crossbb389192013-09-26 11:24:47 +0800770 int ret;
771
Lucas Stachd1dc9742014-03-28 17:52:59 +0100772 if (IS_ENABLED(CONFIG_PCI_MSI)) {
773 pp->msi_irq = platform_get_irq_byname(pdev, "msi");
774 if (pp->msi_irq <= 0) {
Bjorn Helgaas13957652016-10-06 13:35:18 -0500775 dev_err(dev, "failed to get MSI irq\n");
Lucas Stachd1dc9742014-03-28 17:52:59 +0100776 return -ENODEV;
777 }
Lucas Stachd1dc9742014-03-28 17:52:59 +0100778 }
779
Sean Crossbb389192013-09-26 11:24:47 +0800780 pp->ops = &imx6_pcie_host_ops;
781
Sean Crossbb389192013-09-26 11:24:47 +0800782 ret = dw_pcie_host_init(pp);
783 if (ret) {
Bjorn Helgaas13957652016-10-06 13:35:18 -0500784 dev_err(dev, "failed to initialize host\n");
Sean Crossbb389192013-09-26 11:24:47 +0800785 return ret;
786 }
787
788 return 0;
789}
790
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530791static const struct dw_pcie_ops dw_pcie_ops = {
Trent Piepho68bc10b2018-11-05 18:11:36 +0000792 /* No special ops needed, but pcie-designware still expects this struct */
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530793};
794
Leonard Crestez0ee2c1f2018-08-27 14:28:37 +0300795#ifdef CONFIG_PM_SLEEP
796static void imx6_pcie_ltssm_disable(struct device *dev)
797{
798 struct imx6_pcie *imx6_pcie = dev_get_drvdata(dev);
799
800 switch (imx6_pcie->variant) {
801 case IMX6SX:
802 case IMX6QP:
803 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
804 IMX6Q_GPR12_PCIE_CTL_2, 0);
805 break;
806 case IMX7D:
807 reset_control_assert(imx6_pcie->apps_reset);
808 break;
809 default:
810 dev_err(dev, "ltssm_disable not supported\n");
811 }
812}
813
Leonard Crestezf4e833b2018-07-19 17:02:10 +0300814static void imx6_pcie_pm_turnoff(struct imx6_pcie *imx6_pcie)
815{
Leonard Crestez9e56f0d2018-11-07 13:57:03 +0000816 struct device *dev = imx6_pcie->pci->dev;
817
818 /* Some variants have a turnoff reset in DT */
819 if (imx6_pcie->turnoff_reset) {
820 reset_control_assert(imx6_pcie->turnoff_reset);
821 reset_control_deassert(imx6_pcie->turnoff_reset);
822 goto pm_turnoff_sleep;
823 }
824
825 /* Others poke directly at IOMUXC registers */
826 switch (imx6_pcie->variant) {
827 case IMX6SX:
828 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
829 IMX6SX_GPR12_PCIE_PM_TURN_OFF,
830 IMX6SX_GPR12_PCIE_PM_TURN_OFF);
831 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
832 IMX6SX_GPR12_PCIE_PM_TURN_OFF, 0);
833 break;
834 default:
835 dev_err(dev, "PME_Turn_Off not implemented\n");
836 return;
837 }
Leonard Crestezf4e833b2018-07-19 17:02:10 +0300838
839 /*
840 * Components with an upstream port must respond to
841 * PME_Turn_Off with PME_TO_Ack but we can't check.
842 *
843 * The standard recommends a 1-10ms timeout after which to
844 * proceed anyway as if acks were received.
845 */
Leonard Crestez9e56f0d2018-11-07 13:57:03 +0000846pm_turnoff_sleep:
Leonard Crestezf4e833b2018-07-19 17:02:10 +0300847 usleep_range(1000, 10000);
848}
849
Leonard Crestez0ee2c1f2018-08-27 14:28:37 +0300850static void imx6_pcie_clk_disable(struct imx6_pcie *imx6_pcie)
851{
852 clk_disable_unprepare(imx6_pcie->pcie);
853 clk_disable_unprepare(imx6_pcie->pcie_phy);
854 clk_disable_unprepare(imx6_pcie->pcie_bus);
855
Leonard Crestez9e56f0d2018-11-07 13:57:03 +0000856 switch (imx6_pcie->variant) {
857 case IMX6SX:
858 clk_disable_unprepare(imx6_pcie->pcie_inbound_axi);
859 break;
860 case IMX7D:
Leonard Crestez0ee2c1f2018-08-27 14:28:37 +0300861 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
862 IMX7D_GPR12_PCIE_PHY_REFCLK_SEL,
863 IMX7D_GPR12_PCIE_PHY_REFCLK_SEL);
Leonard Crestez9e56f0d2018-11-07 13:57:03 +0000864 break;
865 default:
866 break;
Leonard Crestez0ee2c1f2018-08-27 14:28:37 +0300867 }
868}
869
Leonard Crestez9e56f0d2018-11-07 13:57:03 +0000870static inline bool imx6_pcie_supports_suspend(struct imx6_pcie *imx6_pcie)
871{
872 return (imx6_pcie->variant == IMX7D ||
873 imx6_pcie->variant == IMX6SX);
874}
875
Leonard Crestez0ee2c1f2018-08-27 14:28:37 +0300876static int imx6_pcie_suspend_noirq(struct device *dev)
877{
878 struct imx6_pcie *imx6_pcie = dev_get_drvdata(dev);
879
Leonard Crestez9e56f0d2018-11-07 13:57:03 +0000880 if (!imx6_pcie_supports_suspend(imx6_pcie))
Leonard Crestez0ee2c1f2018-08-27 14:28:37 +0300881 return 0;
882
Leonard Crestezf4e833b2018-07-19 17:02:10 +0300883 imx6_pcie_pm_turnoff(imx6_pcie);
Leonard Crestez0ee2c1f2018-08-27 14:28:37 +0300884 imx6_pcie_clk_disable(imx6_pcie);
885 imx6_pcie_ltssm_disable(dev);
886
887 return 0;
888}
889
890static int imx6_pcie_resume_noirq(struct device *dev)
891{
892 int ret;
893 struct imx6_pcie *imx6_pcie = dev_get_drvdata(dev);
894 struct pcie_port *pp = &imx6_pcie->pci->pp;
895
Leonard Crestez9e56f0d2018-11-07 13:57:03 +0000896 if (!imx6_pcie_supports_suspend(imx6_pcie))
Leonard Crestez0ee2c1f2018-08-27 14:28:37 +0300897 return 0;
898
899 imx6_pcie_assert_core_reset(imx6_pcie);
900 imx6_pcie_init_phy(imx6_pcie);
901 imx6_pcie_deassert_core_reset(imx6_pcie);
902 dw_pcie_setup_rc(pp);
903
904 ret = imx6_pcie_establish_link(imx6_pcie);
905 if (ret < 0)
906 dev_info(dev, "pcie link is down after resume.\n");
907
908 return 0;
909}
910#endif
911
912static const struct dev_pm_ops imx6_pcie_pm_ops = {
913 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(imx6_pcie_suspend_noirq,
914 imx6_pcie_resume_noirq)
915};
916
Andrey Smirnovbde4a5a2017-03-28 08:42:50 -0700917static int imx6_pcie_probe(struct platform_device *pdev)
Sean Crossbb389192013-09-26 11:24:47 +0800918{
Bjorn Helgaas13957652016-10-06 13:35:18 -0500919 struct device *dev = &pdev->dev;
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530920 struct dw_pcie *pci;
Sean Crossbb389192013-09-26 11:24:47 +0800921 struct imx6_pcie *imx6_pcie;
Sean Crossbb389192013-09-26 11:24:47 +0800922 struct resource *dbi_base;
Bjorn Helgaas13957652016-10-06 13:35:18 -0500923 struct device_node *node = dev->of_node;
Sean Crossbb389192013-09-26 11:24:47 +0800924 int ret;
Richard Zhu75cb8d22018-12-21 04:33:38 +0000925 u16 val;
Sean Crossbb389192013-09-26 11:24:47 +0800926
Bjorn Helgaas13957652016-10-06 13:35:18 -0500927 imx6_pcie = devm_kzalloc(dev, sizeof(*imx6_pcie), GFP_KERNEL);
Sean Crossbb389192013-09-26 11:24:47 +0800928 if (!imx6_pcie)
929 return -ENOMEM;
930
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530931 pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL);
932 if (!pci)
933 return -ENOMEM;
934
935 pci->dev = dev;
936 pci->ops = &dw_pcie_ops;
Sean Crossbb389192013-09-26 11:24:47 +0800937
Guenter Roeckc0464062017-02-25 02:08:12 -0800938 imx6_pcie->pci = pci;
Andrey Smirnove6f1fef2016-05-02 14:08:21 -0500939 imx6_pcie->variant =
Bjorn Helgaas13957652016-10-06 13:35:18 -0500940 (enum imx6_pcie_variants)of_device_get_match_data(dev);
Christoph Fritze3c06cd2016-04-05 16:53:27 -0500941
Sean Crossbb389192013-09-26 11:24:47 +0800942 dbi_base = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Kishon Vijay Abraham I442ec4c2017-02-15 18:48:14 +0530943 pci->dbi_base = devm_ioremap_resource(dev, dbi_base);
944 if (IS_ERR(pci->dbi_base))
945 return PTR_ERR(pci->dbi_base);
Sean Crossbb389192013-09-26 11:24:47 +0800946
947 /* Fetch GPIOs */
Bjorn Helgaasc5af4072016-10-06 13:35:18 -0500948 imx6_pcie->reset_gpio = of_get_named_gpio(node, "reset-gpio", 0);
949 imx6_pcie->gpio_active_high = of_property_read_bool(node,
Petr Štetiar3ea8529a2016-04-19 19:42:07 -0500950 "reset-gpio-active-high");
Fabio Estevamb2d7a9c2016-03-28 18:45:36 -0300951 if (gpio_is_valid(imx6_pcie->reset_gpio)) {
Bjorn Helgaas13957652016-10-06 13:35:18 -0500952 ret = devm_gpio_request_one(dev, imx6_pcie->reset_gpio,
Petr Štetiar3ea8529a2016-04-19 19:42:07 -0500953 imx6_pcie->gpio_active_high ?
954 GPIOF_OUT_INIT_HIGH :
955 GPIOF_OUT_INIT_LOW,
956 "PCIe reset");
Fabio Estevamb2d7a9c2016-03-28 18:45:36 -0300957 if (ret) {
Bjorn Helgaas13957652016-10-06 13:35:18 -0500958 dev_err(dev, "unable to get reset gpio\n");
Fabio Estevamb2d7a9c2016-03-28 18:45:36 -0300959 return ret;
960 }
Andrey Smirnovbde4a5a2017-03-28 08:42:50 -0700961 } else if (imx6_pcie->reset_gpio == -EPROBE_DEFER) {
962 return imx6_pcie->reset_gpio;
Fabio Estevamb2d7a9c2016-03-28 18:45:36 -0300963 }
Sean Crossbb389192013-09-26 11:24:47 +0800964
Sean Crossbb389192013-09-26 11:24:47 +0800965 /* Fetch clocks */
Bjorn Helgaas13957652016-10-06 13:35:18 -0500966 imx6_pcie->pcie_phy = devm_clk_get(dev, "pcie_phy");
Lucas Stach57526132014-03-28 17:52:55 +0100967 if (IS_ERR(imx6_pcie->pcie_phy)) {
Bjorn Helgaas13957652016-10-06 13:35:18 -0500968 dev_err(dev, "pcie_phy clock source missing or invalid\n");
Lucas Stach57526132014-03-28 17:52:55 +0100969 return PTR_ERR(imx6_pcie->pcie_phy);
Sean Crossbb389192013-09-26 11:24:47 +0800970 }
971
Bjorn Helgaas13957652016-10-06 13:35:18 -0500972 imx6_pcie->pcie_bus = devm_clk_get(dev, "pcie_bus");
Lucas Stach57526132014-03-28 17:52:55 +0100973 if (IS_ERR(imx6_pcie->pcie_bus)) {
Bjorn Helgaas13957652016-10-06 13:35:18 -0500974 dev_err(dev, "pcie_bus clock source missing or invalid\n");
Lucas Stach57526132014-03-28 17:52:55 +0100975 return PTR_ERR(imx6_pcie->pcie_bus);
Sean Crossbb389192013-09-26 11:24:47 +0800976 }
977
Bjorn Helgaas13957652016-10-06 13:35:18 -0500978 imx6_pcie->pcie = devm_clk_get(dev, "pcie");
Lucas Stach57526132014-03-28 17:52:55 +0100979 if (IS_ERR(imx6_pcie->pcie)) {
Bjorn Helgaas13957652016-10-06 13:35:18 -0500980 dev_err(dev, "pcie clock source missing or invalid\n");
Lucas Stach57526132014-03-28 17:52:55 +0100981 return PTR_ERR(imx6_pcie->pcie);
Sean Crossbb389192013-09-26 11:24:47 +0800982 }
983
Andrey Smirnov9b3fe672017-03-28 08:42:49 -0700984 switch (imx6_pcie->variant) {
985 case IMX6SX:
Bjorn Helgaas13957652016-10-06 13:35:18 -0500986 imx6_pcie->pcie_inbound_axi = devm_clk_get(dev,
Christoph Fritze3c06cd2016-04-05 16:53:27 -0500987 "pcie_inbound_axi");
988 if (IS_ERR(imx6_pcie->pcie_inbound_axi)) {
Andrey Smirnov21b72452017-02-07 07:50:25 -0800989 dev_err(dev, "pcie_inbound_axi clock missing or invalid\n");
Christoph Fritze3c06cd2016-04-05 16:53:27 -0500990 return PTR_ERR(imx6_pcie->pcie_inbound_axi);
991 }
Andrey Smirnov9b3fe672017-03-28 08:42:49 -0700992 break;
993 case IMX7D:
Philipp Zabel7c180582017-07-19 17:25:56 +0200994 imx6_pcie->pciephy_reset = devm_reset_control_get_exclusive(dev,
995 "pciephy");
Andrey Smirnov9b3fe672017-03-28 08:42:49 -0700996 if (IS_ERR(imx6_pcie->pciephy_reset)) {
Colin Ian King72215472017-04-21 08:02:30 +0100997 dev_err(dev, "Failed to get PCIEPHY reset control\n");
Andrey Smirnov9b3fe672017-03-28 08:42:49 -0700998 return PTR_ERR(imx6_pcie->pciephy_reset);
999 }
1000
Philipp Zabel7c180582017-07-19 17:25:56 +02001001 imx6_pcie->apps_reset = devm_reset_control_get_exclusive(dev,
1002 "apps");
Andrey Smirnov9b3fe672017-03-28 08:42:49 -07001003 if (IS_ERR(imx6_pcie->apps_reset)) {
Colin Ian King72215472017-04-21 08:02:30 +01001004 dev_err(dev, "Failed to get PCIE APPS reset control\n");
Andrey Smirnov9b3fe672017-03-28 08:42:49 -07001005 return PTR_ERR(imx6_pcie->apps_reset);
1006 }
1007 break;
1008 default:
1009 break;
Christoph Fritze3c06cd2016-04-05 16:53:27 -05001010 }
1011
Leonard Crestezf4e833b2018-07-19 17:02:10 +03001012 /* Grab turnoff reset */
1013 imx6_pcie->turnoff_reset = devm_reset_control_get_optional_exclusive(dev, "turnoff");
1014 if (IS_ERR(imx6_pcie->turnoff_reset)) {
1015 dev_err(dev, "Failed to get TURNOFF reset control\n");
1016 return PTR_ERR(imx6_pcie->turnoff_reset);
1017 }
1018
Sean Crossbb389192013-09-26 11:24:47 +08001019 /* Grab GPR config register range */
1020 imx6_pcie->iomuxc_gpr =
1021 syscon_regmap_lookup_by_compatible("fsl,imx6q-iomuxc-gpr");
1022 if (IS_ERR(imx6_pcie->iomuxc_gpr)) {
Bjorn Helgaas13957652016-10-06 13:35:18 -05001023 dev_err(dev, "unable to find iomuxc registers\n");
Fabio Estevamb391bf32013-12-02 01:39:35 -02001024 return PTR_ERR(imx6_pcie->iomuxc_gpr);
Sean Crossbb389192013-09-26 11:24:47 +08001025 }
1026
Justin Waters28e3abe2016-01-15 10:24:35 -05001027 /* Grab PCIe PHY Tx Settings */
1028 if (of_property_read_u32(node, "fsl,tx-deemph-gen1",
1029 &imx6_pcie->tx_deemph_gen1))
1030 imx6_pcie->tx_deemph_gen1 = 0;
1031
1032 if (of_property_read_u32(node, "fsl,tx-deemph-gen2-3p5db",
1033 &imx6_pcie->tx_deemph_gen2_3p5db))
1034 imx6_pcie->tx_deemph_gen2_3p5db = 0;
1035
1036 if (of_property_read_u32(node, "fsl,tx-deemph-gen2-6db",
1037 &imx6_pcie->tx_deemph_gen2_6db))
1038 imx6_pcie->tx_deemph_gen2_6db = 20;
1039
1040 if (of_property_read_u32(node, "fsl,tx-swing-full",
1041 &imx6_pcie->tx_swing_full))
1042 imx6_pcie->tx_swing_full = 127;
1043
1044 if (of_property_read_u32(node, "fsl,tx-swing-low",
1045 &imx6_pcie->tx_swing_low))
1046 imx6_pcie->tx_swing_low = 127;
1047
Tim Harveya5fcec42016-04-19 19:52:44 -05001048 /* Limit link speed */
Bjorn Helgaasc5af4072016-10-06 13:35:18 -05001049 ret = of_property_read_u32(node, "fsl,max-link-speed",
Tim Harveya5fcec42016-04-19 19:52:44 -05001050 &imx6_pcie->link_gen);
1051 if (ret)
1052 imx6_pcie->link_gen = 1;
1053
Quentin Schulzc26ebe92017-06-08 10:07:42 +02001054 imx6_pcie->vpcie = devm_regulator_get_optional(&pdev->dev, "vpcie");
1055 if (IS_ERR(imx6_pcie->vpcie)) {
1056 if (PTR_ERR(imx6_pcie->vpcie) == -EPROBE_DEFER)
1057 return -EPROBE_DEFER;
1058 imx6_pcie->vpcie = NULL;
1059 }
1060
Kishon Vijay Abraham I9bcf0a62017-02-15 18:48:11 +05301061 platform_set_drvdata(pdev, imx6_pcie);
1062
Leonard Crestez3f7ccee2018-10-08 18:06:21 +00001063 ret = imx6_pcie_attach_pd(dev);
1064 if (ret)
1065 return ret;
1066
Bjorn Helgaase7d77052016-10-11 22:06:47 -05001067 ret = imx6_add_pcie_port(imx6_pcie, pdev);
Sean Crossbb389192013-09-26 11:24:47 +08001068 if (ret < 0)
Fabio Estevamb391bf32013-12-02 01:39:35 -02001069 return ret;
Sean Crossbb389192013-09-26 11:24:47 +08001070
Richard Zhu75cb8d22018-12-21 04:33:38 +00001071 if (pci_msi_enabled()) {
1072 val = dw_pcie_readw_dbi(pci, PCIE_RC_IMX6_MSI_CAP +
1073 PCI_MSI_FLAGS);
1074 val |= PCI_MSI_FLAGS_ENABLE;
1075 dw_pcie_writew_dbi(pci, PCIE_RC_IMX6_MSI_CAP + PCI_MSI_FLAGS,
1076 val);
1077 }
1078
Sean Crossbb389192013-09-26 11:24:47 +08001079 return 0;
Sean Crossbb389192013-09-26 11:24:47 +08001080}
1081
Lucas Stach3e3e4062014-07-31 20:16:05 +02001082static void imx6_pcie_shutdown(struct platform_device *pdev)
1083{
1084 struct imx6_pcie *imx6_pcie = platform_get_drvdata(pdev);
1085
1086 /* bring down link, so bootloader gets clean state in case of reboot */
Bjorn Helgaase7d77052016-10-11 22:06:47 -05001087 imx6_pcie_assert_core_reset(imx6_pcie);
Lucas Stach3e3e4062014-07-31 20:16:05 +02001088}
1089
Sean Crossbb389192013-09-26 11:24:47 +08001090static const struct of_device_id imx6_pcie_of_match[] = {
Andrey Smirnove6f1fef2016-05-02 14:08:21 -05001091 { .compatible = "fsl,imx6q-pcie", .data = (void *)IMX6Q, },
1092 { .compatible = "fsl,imx6sx-pcie", .data = (void *)IMX6SX, },
Andrey Smirnov4d31c612016-05-02 14:09:10 -05001093 { .compatible = "fsl,imx6qp-pcie", .data = (void *)IMX6QP, },
Andrey Smirnov9b3fe672017-03-28 08:42:49 -07001094 { .compatible = "fsl,imx7d-pcie", .data = (void *)IMX7D, },
Sean Crossbb389192013-09-26 11:24:47 +08001095 {},
1096};
Sean Crossbb389192013-09-26 11:24:47 +08001097
1098static struct platform_driver imx6_pcie_driver = {
1099 .driver = {
1100 .name = "imx6q-pcie",
Sachin Kamat8bcadbe2013-10-21 14:36:41 +05301101 .of_match_table = imx6_pcie_of_match,
Brian Norrisa5f40e82017-04-20 15:36:25 -05001102 .suppress_bind_attrs = true,
Leonard Crestez0ee2c1f2018-08-27 14:28:37 +03001103 .pm = &imx6_pcie_pm_ops,
Sean Crossbb389192013-09-26 11:24:47 +08001104 },
Andrey Smirnovbde4a5a2017-03-28 08:42:50 -07001105 .probe = imx6_pcie_probe,
Lucas Stach3e3e4062014-07-31 20:16:05 +02001106 .shutdown = imx6_pcie_shutdown,
Sean Crossbb389192013-09-26 11:24:47 +08001107};
1108
Sean Crossbb389192013-09-26 11:24:47 +08001109static int __init imx6_pcie_init(void)
1110{
Andrey Smirnovbde4a5a2017-03-28 08:42:50 -07001111 /*
1112 * Since probe() can be deferred we need to make sure that
1113 * hook_fault_code is not called after __init memory is freed
1114 * by kernel and since imx6q_pcie_abort_handler() is a no-op,
1115 * we can install the handler here without risking it
1116 * accessing some uninitialized driver state.
1117 */
Lucas Stach415b6182017-05-22 17:06:30 -05001118 hook_fault_code(8, imx6q_pcie_abort_handler, SIGBUS, 0,
1119 "external abort on non-linefetch");
Andrey Smirnovbde4a5a2017-03-28 08:42:50 -07001120
1121 return platform_driver_register(&imx6_pcie_driver);
Sean Crossbb389192013-09-26 11:24:47 +08001122}
Paul Gortmakerf90d8e82016-08-22 17:59:43 -04001123device_initcall(imx6_pcie_init);