1 // SPDX-License-Identifier: GPL-2.0+
3 * PCIe host controller driver for the following SoCs
7 * Copyright (C) 2019-2022 NVIDIA Corporation.
12 #include <linux/clk.h>
13 #include <linux/debugfs.h>
14 #include <linux/delay.h>
15 #include <linux/gpio.h>
16 #include <linux/gpio/consumer.h>
17 #include <linux/interrupt.h>
18 #include <linux/iopoll.h>
19 #include <linux/kernel.h>
20 #include <linux/module.h>
22 #include <linux/of_device.h>
23 #include <linux/of_gpio.h>
24 #include <linux/of_irq.h>
25 #include <linux/of_pci.h>
26 #include <linux/pci.h>
27 #include <linux/phy/phy.h>
28 #include <linux/pinctrl/consumer.h>
29 #include <linux/platform_device.h>
30 #include <linux/pm_runtime.h>
31 #include <linux/random.h>
32 #include <linux/reset.h>
33 #include <linux/resource.h>
34 #include <linux/types.h>
35 #include "pcie-designware.h"
36 #include <soc/tegra/bpmp.h>
37 #include <soc/tegra/bpmp-abi.h>
38 #include "../../pci.h"
40 #define TEGRA194_DWC_IP_VER 0x490A
41 #define TEGRA234_DWC_IP_VER 0x562A
43 #define APPL_PINMUX 0x0
44 #define APPL_PINMUX_PEX_RST BIT(0)
45 #define APPL_PINMUX_CLKREQ_OVERRIDE_EN BIT(2)
46 #define APPL_PINMUX_CLKREQ_OVERRIDE BIT(3)
47 #define APPL_PINMUX_CLK_OUTPUT_IN_OVERRIDE_EN BIT(4)
48 #define APPL_PINMUX_CLK_OUTPUT_IN_OVERRIDE BIT(5)
51 #define APPL_CTRL_SYS_PRE_DET_STATE BIT(6)
52 #define APPL_CTRL_LTSSM_EN BIT(7)
53 #define APPL_CTRL_HW_HOT_RST_EN BIT(20)
54 #define APPL_CTRL_HW_HOT_RST_MODE_MASK GENMASK(1, 0)
55 #define APPL_CTRL_HW_HOT_RST_MODE_SHIFT 22
56 #define APPL_CTRL_HW_HOT_RST_MODE_IMDT_RST 0x1
57 #define APPL_CTRL_HW_HOT_RST_MODE_IMDT_RST_LTSSM_EN 0x2
59 #define APPL_INTR_EN_L0_0 0x8
60 #define APPL_INTR_EN_L0_0_LINK_STATE_INT_EN BIT(0)
61 #define APPL_INTR_EN_L0_0_MSI_RCV_INT_EN BIT(4)
62 #define APPL_INTR_EN_L0_0_INT_INT_EN BIT(8)
63 #define APPL_INTR_EN_L0_0_PCI_CMD_EN_INT_EN BIT(15)
64 #define APPL_INTR_EN_L0_0_CDM_REG_CHK_INT_EN BIT(19)
65 #define APPL_INTR_EN_L0_0_SYS_INTR_EN BIT(30)
66 #define APPL_INTR_EN_L0_0_SYS_MSI_INTR_EN BIT(31)
68 #define APPL_INTR_STATUS_L0 0xC
69 #define APPL_INTR_STATUS_L0_LINK_STATE_INT BIT(0)
70 #define APPL_INTR_STATUS_L0_INT_INT BIT(8)
71 #define APPL_INTR_STATUS_L0_PCI_CMD_EN_INT BIT(15)
72 #define APPL_INTR_STATUS_L0_PEX_RST_INT BIT(16)
73 #define APPL_INTR_STATUS_L0_CDM_REG_CHK_INT BIT(18)
75 #define APPL_INTR_EN_L1_0_0 0x1C
76 #define APPL_INTR_EN_L1_0_0_LINK_REQ_RST_NOT_INT_EN BIT(1)
77 #define APPL_INTR_EN_L1_0_0_RDLH_LINK_UP_INT_EN BIT(3)
78 #define APPL_INTR_EN_L1_0_0_HOT_RESET_DONE_INT_EN BIT(30)
80 #define APPL_INTR_STATUS_L1_0_0 0x20
81 #define APPL_INTR_STATUS_L1_0_0_LINK_REQ_RST_NOT_CHGED BIT(1)
82 #define APPL_INTR_STATUS_L1_0_0_RDLH_LINK_UP_CHGED BIT(3)
83 #define APPL_INTR_STATUS_L1_0_0_HOT_RESET_DONE BIT(30)
85 #define APPL_INTR_STATUS_L1_1 0x2C
86 #define APPL_INTR_STATUS_L1_2 0x30
87 #define APPL_INTR_STATUS_L1_3 0x34
88 #define APPL_INTR_STATUS_L1_6 0x3C
89 #define APPL_INTR_STATUS_L1_7 0x40
90 #define APPL_INTR_STATUS_L1_15_CFG_BME_CHGED BIT(1)
92 #define APPL_INTR_EN_L1_8_0 0x44
93 #define APPL_INTR_EN_L1_8_BW_MGT_INT_EN BIT(2)
94 #define APPL_INTR_EN_L1_8_AUTO_BW_INT_EN BIT(3)
95 #define APPL_INTR_EN_L1_8_INTX_EN BIT(11)
96 #define APPL_INTR_EN_L1_8_AER_INT_EN BIT(15)
98 #define APPL_INTR_STATUS_L1_8_0 0x4C
99 #define APPL_INTR_STATUS_L1_8_0_EDMA_INT_MASK GENMASK(11, 6)
100 #define APPL_INTR_STATUS_L1_8_0_BW_MGT_INT_STS BIT(2)
101 #define APPL_INTR_STATUS_L1_8_0_AUTO_BW_INT_STS BIT(3)
103 #define APPL_INTR_STATUS_L1_9 0x54
104 #define APPL_INTR_STATUS_L1_10 0x58
105 #define APPL_INTR_STATUS_L1_11 0x64
106 #define APPL_INTR_STATUS_L1_13 0x74
107 #define APPL_INTR_STATUS_L1_14 0x78
108 #define APPL_INTR_STATUS_L1_15 0x7C
109 #define APPL_INTR_STATUS_L1_17 0x88
111 #define APPL_INTR_EN_L1_18 0x90
112 #define APPL_INTR_EN_L1_18_CDM_REG_CHK_CMPLT BIT(2)
113 #define APPL_INTR_EN_L1_18_CDM_REG_CHK_CMP_ERR BIT(1)
114 #define APPL_INTR_EN_L1_18_CDM_REG_CHK_LOGIC_ERR BIT(0)
116 #define APPL_INTR_STATUS_L1_18 0x94
117 #define APPL_INTR_STATUS_L1_18_CDM_REG_CHK_CMPLT BIT(2)
118 #define APPL_INTR_STATUS_L1_18_CDM_REG_CHK_CMP_ERR BIT(1)
119 #define APPL_INTR_STATUS_L1_18_CDM_REG_CHK_LOGIC_ERR BIT(0)
121 #define APPL_MSI_CTRL_1 0xAC
123 #define APPL_MSI_CTRL_2 0xB0
125 #define APPL_LEGACY_INTX 0xB8
127 #define APPL_LTR_MSG_1 0xC4
128 #define LTR_MSG_REQ BIT(15)
129 #define LTR_MST_NO_SNOOP_SHIFT 16
131 #define APPL_LTR_MSG_2 0xC8
132 #define APPL_LTR_MSG_2_LTR_MSG_REQ_STATE BIT(3)
134 #define APPL_LINK_STATUS 0xCC
135 #define APPL_LINK_STATUS_RDLH_LINK_UP BIT(0)
137 #define APPL_DEBUG 0xD0
138 #define APPL_DEBUG_PM_LINKST_IN_L2_LAT BIT(21)
139 #define APPL_DEBUG_PM_LINKST_IN_L0 0x11
140 #define APPL_DEBUG_LTSSM_STATE_MASK GENMASK(8, 3)
141 #define APPL_DEBUG_LTSSM_STATE_SHIFT 3
142 #define LTSSM_STATE_PRE_DETECT 5
144 #define APPL_RADM_STATUS 0xE4
145 #define APPL_PM_XMT_TURNOFF_STATE BIT(0)
147 #define APPL_DM_TYPE 0x100
148 #define APPL_DM_TYPE_MASK GENMASK(3, 0)
149 #define APPL_DM_TYPE_RP 0x4
150 #define APPL_DM_TYPE_EP 0x0
152 #define APPL_CFG_BASE_ADDR 0x104
153 #define APPL_CFG_BASE_ADDR_MASK GENMASK(31, 12)
155 #define APPL_CFG_IATU_DMA_BASE_ADDR 0x108
156 #define APPL_CFG_IATU_DMA_BASE_ADDR_MASK GENMASK(31, 18)
158 #define APPL_CFG_MISC 0x110
159 #define APPL_CFG_MISC_SLV_EP_MODE BIT(14)
160 #define APPL_CFG_MISC_ARCACHE_MASK GENMASK(13, 10)
161 #define APPL_CFG_MISC_ARCACHE_SHIFT 10
162 #define APPL_CFG_MISC_ARCACHE_VAL 3
164 #define APPL_CFG_SLCG_OVERRIDE 0x114
165 #define APPL_CFG_SLCG_OVERRIDE_SLCG_EN_MASTER BIT(0)
167 #define APPL_CAR_RESET_OVRD 0x12C
168 #define APPL_CAR_RESET_OVRD_CYA_OVERRIDE_CORE_RST_N BIT(0)
170 #define IO_BASE_IO_DECODE BIT(0)
171 #define IO_BASE_IO_DECODE_BIT8 BIT(8)
173 #define CFG_PREF_MEM_LIMIT_BASE_MEM_DECODE BIT(0)
174 #define CFG_PREF_MEM_LIMIT_BASE_MEM_LIMIT_DECODE BIT(16)
176 #define CFG_TIMER_CTRL_MAX_FUNC_NUM_OFF 0x718
177 #define CFG_TIMER_CTRL_ACK_NAK_SHIFT (19)
182 #define GEN3_EQ_CONTROL_OFF 0x8a8
183 #define GEN3_EQ_CONTROL_OFF_PSET_REQ_VEC_SHIFT 8
184 #define GEN3_EQ_CONTROL_OFF_PSET_REQ_VEC_MASK GENMASK(23, 8)
185 #define GEN3_EQ_CONTROL_OFF_FB_MODE_MASK GENMASK(3, 0)
187 #define PORT_LOGIC_AMBA_ERROR_RESPONSE_DEFAULT 0x8D0
188 #define AMBA_ERROR_RESPONSE_CRS_SHIFT 3
189 #define AMBA_ERROR_RESPONSE_CRS_MASK GENMASK(1, 0)
190 #define AMBA_ERROR_RESPONSE_CRS_OKAY 0
191 #define AMBA_ERROR_RESPONSE_CRS_OKAY_FFFFFFFF 1
192 #define AMBA_ERROR_RESPONSE_CRS_OKAY_FFFF0001 2
194 #define MSIX_ADDR_MATCH_LOW_OFF 0x940
195 #define MSIX_ADDR_MATCH_LOW_OFF_EN BIT(0)
196 #define MSIX_ADDR_MATCH_LOW_OFF_MASK GENMASK(31, 2)
198 #define MSIX_ADDR_MATCH_HIGH_OFF 0x944
199 #define MSIX_ADDR_MATCH_HIGH_OFF_MASK GENMASK(31, 0)
201 #define PORT_LOGIC_MSIX_DOORBELL 0x948
203 #define CAP_SPCIE_CAP_OFF 0x154
204 #define CAP_SPCIE_CAP_OFF_DSP_TX_PRESET0_MASK GENMASK(3, 0)
205 #define CAP_SPCIE_CAP_OFF_USP_TX_PRESET0_MASK GENMASK(11, 8)
206 #define CAP_SPCIE_CAP_OFF_USP_TX_PRESET0_SHIFT 8
208 #define PME_ACK_TIMEOUT 10000
210 #define LTSSM_TIMEOUT 50000 /* 50ms */
212 #define GEN3_GEN4_EQ_PRESET_INIT 5
214 #define GEN1_CORE_CLK_FREQ 62500000
215 #define GEN2_CORE_CLK_FREQ 125000000
216 #define GEN3_CORE_CLK_FREQ 250000000
217 #define GEN4_CORE_CLK_FREQ 500000000
219 #define LTR_MSG_TIMEOUT (100 * 1000)
221 #define PERST_DEBOUNCE_TIME (5 * 1000)
223 #define EP_STATE_DISABLED 0
224 #define EP_STATE_ENABLED 1
226 static const unsigned int pcie_gen_freq[] = {
233 struct tegra_pcie_dw_of_data {
235 enum dw_pcie_device_mode mode;
236 bool has_msix_doorbell_access_fix;
237 bool has_sbr_reset_fix;
238 bool has_l1ss_exit_fix;
239 bool has_ltr_req_fix;
240 u32 cdm_chk_int_en_bit;
245 struct tegra_pcie_dw {
247 struct resource *appl_res;
248 struct resource *dbi_res;
249 struct resource *atu_dma_res;
250 void __iomem *appl_base;
251 struct clk *core_clk;
252 struct reset_control *core_apb_rst;
253 struct reset_control *core_rst;
255 struct tegra_bpmp *bpmp;
257 struct tegra_pcie_dw_of_data *of_data;
259 bool supports_clkreq;
260 bool enable_cdm_check;
263 bool update_fc_fixup;
264 bool enable_ext_refclk;
269 u32 cfg_link_cap_l1sub;
274 u32 aspm_l0s_enter_lat;
276 struct regulator *pex_ctl_supply;
277 struct regulator *slot_ctl_3v3;
278 struct regulator *slot_ctl_12v;
280 unsigned int phy_count;
283 struct dentry *debugfs;
285 /* Endpoint mode specific */
286 struct gpio_desc *pex_rst_gpiod;
287 struct gpio_desc *pex_refclk_sel_gpiod;
288 unsigned int pex_rst_irq;
292 static inline struct tegra_pcie_dw *to_tegra_pcie(struct dw_pcie *pci)
294 return container_of(pci, struct tegra_pcie_dw, pci);
297 static inline void appl_writel(struct tegra_pcie_dw *pcie, const u32 value,
300 writel_relaxed(value, pcie->appl_base + reg);
303 static inline u32 appl_readl(struct tegra_pcie_dw *pcie, const u32 reg)
305 return readl_relaxed(pcie->appl_base + reg);
308 struct tegra_pcie_soc {
309 enum dw_pcie_device_mode mode;
312 static void apply_bad_link_workaround(struct dw_pcie_rp *pp)
314 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
315 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci);
316 u32 current_link_width;
320 * NOTE:- Since this scenario is uncommon and link as such is not
321 * stable anyway, not waiting to confirm if link is really
322 * transitioning to Gen-2 speed
324 val = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKSTA);
325 if (val & PCI_EXP_LNKSTA_LBMS) {
326 current_link_width = (val & PCI_EXP_LNKSTA_NLW) >>
327 PCI_EXP_LNKSTA_NLW_SHIFT;
328 if (pcie->init_link_width > current_link_width) {
329 dev_warn(pci->dev, "PCIe link is bad, width reduced\n");
330 val = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base +
332 val &= ~PCI_EXP_LNKCTL2_TLS;
333 val |= PCI_EXP_LNKCTL2_TLS_2_5GT;
334 dw_pcie_writew_dbi(pci, pcie->pcie_cap_base +
335 PCI_EXP_LNKCTL2, val);
337 val = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base +
339 val |= PCI_EXP_LNKCTL_RL;
340 dw_pcie_writew_dbi(pci, pcie->pcie_cap_base +
341 PCI_EXP_LNKCTL, val);
346 static irqreturn_t tegra_pcie_rp_irq_handler(int irq, void *arg)
348 struct tegra_pcie_dw *pcie = arg;
349 struct dw_pcie *pci = &pcie->pci;
350 struct dw_pcie_rp *pp = &pci->pp;
351 u32 val, status_l0, status_l1;
354 status_l0 = appl_readl(pcie, APPL_INTR_STATUS_L0);
355 if (status_l0 & APPL_INTR_STATUS_L0_LINK_STATE_INT) {
356 status_l1 = appl_readl(pcie, APPL_INTR_STATUS_L1_0_0);
357 appl_writel(pcie, status_l1, APPL_INTR_STATUS_L1_0_0);
358 if (!pcie->of_data->has_sbr_reset_fix &&
359 status_l1 & APPL_INTR_STATUS_L1_0_0_LINK_REQ_RST_NOT_CHGED) {
360 /* SBR & Surprise Link Down WAR */
361 val = appl_readl(pcie, APPL_CAR_RESET_OVRD);
362 val &= ~APPL_CAR_RESET_OVRD_CYA_OVERRIDE_CORE_RST_N;
363 appl_writel(pcie, val, APPL_CAR_RESET_OVRD);
365 val = appl_readl(pcie, APPL_CAR_RESET_OVRD);
366 val |= APPL_CAR_RESET_OVRD_CYA_OVERRIDE_CORE_RST_N;
367 appl_writel(pcie, val, APPL_CAR_RESET_OVRD);
369 val = dw_pcie_readl_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL);
370 val |= PORT_LOGIC_SPEED_CHANGE;
371 dw_pcie_writel_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL, val);
375 if (status_l0 & APPL_INTR_STATUS_L0_INT_INT) {
376 status_l1 = appl_readl(pcie, APPL_INTR_STATUS_L1_8_0);
377 if (status_l1 & APPL_INTR_STATUS_L1_8_0_AUTO_BW_INT_STS) {
379 APPL_INTR_STATUS_L1_8_0_AUTO_BW_INT_STS,
380 APPL_INTR_STATUS_L1_8_0);
381 apply_bad_link_workaround(pp);
383 if (status_l1 & APPL_INTR_STATUS_L1_8_0_BW_MGT_INT_STS) {
384 val_w = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base +
386 val_w |= PCI_EXP_LNKSTA_LBMS;
387 dw_pcie_writew_dbi(pci, pcie->pcie_cap_base +
388 PCI_EXP_LNKSTA, val_w);
391 APPL_INTR_STATUS_L1_8_0_BW_MGT_INT_STS,
392 APPL_INTR_STATUS_L1_8_0);
394 val_w = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base +
396 dev_dbg(pci->dev, "Link Speed : Gen-%u\n", val_w &
401 if (status_l0 & APPL_INTR_STATUS_L0_CDM_REG_CHK_INT) {
402 status_l1 = appl_readl(pcie, APPL_INTR_STATUS_L1_18);
403 val = dw_pcie_readl_dbi(pci, PCIE_PL_CHK_REG_CONTROL_STATUS);
404 if (status_l1 & APPL_INTR_STATUS_L1_18_CDM_REG_CHK_CMPLT) {
405 dev_info(pci->dev, "CDM check complete\n");
406 val |= PCIE_PL_CHK_REG_CHK_REG_COMPLETE;
408 if (status_l1 & APPL_INTR_STATUS_L1_18_CDM_REG_CHK_CMP_ERR) {
409 dev_err(pci->dev, "CDM comparison mismatch\n");
410 val |= PCIE_PL_CHK_REG_CHK_REG_COMPARISON_ERROR;
412 if (status_l1 & APPL_INTR_STATUS_L1_18_CDM_REG_CHK_LOGIC_ERR) {
413 dev_err(pci->dev, "CDM Logic error\n");
414 val |= PCIE_PL_CHK_REG_CHK_REG_LOGIC_ERROR;
416 dw_pcie_writel_dbi(pci, PCIE_PL_CHK_REG_CONTROL_STATUS, val);
417 val = dw_pcie_readl_dbi(pci, PCIE_PL_CHK_REG_ERR_ADDR);
418 dev_err(pci->dev, "CDM Error Address Offset = 0x%08X\n", val);
424 static void pex_ep_event_hot_rst_done(struct tegra_pcie_dw *pcie)
428 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L0);
429 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_0_0);
430 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_1);
431 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_2);
432 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_3);
433 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_6);
434 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_7);
435 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_8_0);
436 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_9);
437 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_10);
438 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_11);
439 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_13);
440 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_14);
441 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_15);
442 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_17);
443 appl_writel(pcie, 0xFFFFFFFF, APPL_MSI_CTRL_2);
445 val = appl_readl(pcie, APPL_CTRL);
446 val |= APPL_CTRL_LTSSM_EN;
447 appl_writel(pcie, val, APPL_CTRL);
450 static irqreturn_t tegra_pcie_ep_irq_thread(int irq, void *arg)
452 struct tegra_pcie_dw *pcie = arg;
453 struct dw_pcie *pci = &pcie->pci;
456 speed = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKSTA) &
458 clk_set_rate(pcie->core_clk, pcie_gen_freq[speed - 1]);
460 if (pcie->of_data->has_ltr_req_fix)
463 /* If EP doesn't advertise L1SS, just return */
464 val = dw_pcie_readl_dbi(pci, pcie->cfg_link_cap_l1sub);
465 if (!(val & (PCI_L1SS_CAP_ASPM_L1_1 | PCI_L1SS_CAP_ASPM_L1_2)))
468 /* Check if BME is set to '1' */
469 val = dw_pcie_readl_dbi(pci, PCI_COMMAND);
470 if (val & PCI_COMMAND_MASTER) {
473 /* 110us for both snoop and no-snoop */
474 val = 110 | (2 << PCI_LTR_SCALE_SHIFT) | LTR_MSG_REQ;
475 val |= (val << LTR_MST_NO_SNOOP_SHIFT);
476 appl_writel(pcie, val, APPL_LTR_MSG_1);
478 /* Send LTR upstream */
479 val = appl_readl(pcie, APPL_LTR_MSG_2);
480 val |= APPL_LTR_MSG_2_LTR_MSG_REQ_STATE;
481 appl_writel(pcie, val, APPL_LTR_MSG_2);
483 timeout = ktime_add_us(ktime_get(), LTR_MSG_TIMEOUT);
485 val = appl_readl(pcie, APPL_LTR_MSG_2);
486 if (!(val & APPL_LTR_MSG_2_LTR_MSG_REQ_STATE))
488 if (ktime_after(ktime_get(), timeout))
490 usleep_range(1000, 1100);
492 if (val & APPL_LTR_MSG_2_LTR_MSG_REQ_STATE)
493 dev_err(pcie->dev, "Failed to send LTR message\n");
499 static irqreturn_t tegra_pcie_ep_hard_irq(int irq, void *arg)
501 struct tegra_pcie_dw *pcie = arg;
502 struct dw_pcie_ep *ep = &pcie->pci.ep;
504 u32 status_l0, status_l1, link_status;
506 status_l0 = appl_readl(pcie, APPL_INTR_STATUS_L0);
507 if (status_l0 & APPL_INTR_STATUS_L0_LINK_STATE_INT) {
508 status_l1 = appl_readl(pcie, APPL_INTR_STATUS_L1_0_0);
509 appl_writel(pcie, status_l1, APPL_INTR_STATUS_L1_0_0);
511 if (status_l1 & APPL_INTR_STATUS_L1_0_0_HOT_RESET_DONE)
512 pex_ep_event_hot_rst_done(pcie);
514 if (status_l1 & APPL_INTR_STATUS_L1_0_0_RDLH_LINK_UP_CHGED) {
515 link_status = appl_readl(pcie, APPL_LINK_STATUS);
516 if (link_status & APPL_LINK_STATUS_RDLH_LINK_UP) {
517 dev_dbg(pcie->dev, "Link is up with Host\n");
518 dw_pcie_ep_linkup(ep);
525 if (status_l0 & APPL_INTR_STATUS_L0_PCI_CMD_EN_INT) {
526 status_l1 = appl_readl(pcie, APPL_INTR_STATUS_L1_15);
527 appl_writel(pcie, status_l1, APPL_INTR_STATUS_L1_15);
529 if (status_l1 & APPL_INTR_STATUS_L1_15_CFG_BME_CHGED)
530 return IRQ_WAKE_THREAD;
536 dev_warn(pcie->dev, "Random interrupt (STATUS = 0x%08X)\n",
538 appl_writel(pcie, status_l0, APPL_INTR_STATUS_L0);
544 static int tegra_pcie_dw_rd_own_conf(struct pci_bus *bus, u32 devfn, int where,
547 struct dw_pcie_rp *pp = bus->sysdata;
548 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
549 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci);
552 * This is an endpoint mode specific register happen to appear even
553 * when controller is operating in root port mode and system hangs
554 * when it is accessed with link being in ASPM-L1 state.
555 * So skip accessing it altogether
557 if (!pcie->of_data->has_msix_doorbell_access_fix &&
558 !PCI_SLOT(devfn) && where == PORT_LOGIC_MSIX_DOORBELL) {
560 return PCIBIOS_SUCCESSFUL;
563 return pci_generic_config_read(bus, devfn, where, size, val);
566 static int tegra_pcie_dw_wr_own_conf(struct pci_bus *bus, u32 devfn, int where,
569 struct dw_pcie_rp *pp = bus->sysdata;
570 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
571 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci);
574 * This is an endpoint mode specific register happen to appear even
575 * when controller is operating in root port mode and system hangs
576 * when it is accessed with link being in ASPM-L1 state.
577 * So skip accessing it altogether
579 if (!pcie->of_data->has_msix_doorbell_access_fix &&
580 !PCI_SLOT(devfn) && where == PORT_LOGIC_MSIX_DOORBELL)
581 return PCIBIOS_SUCCESSFUL;
583 return pci_generic_config_write(bus, devfn, where, size, val);
586 static struct pci_ops tegra_pci_ops = {
587 .map_bus = dw_pcie_own_conf_map_bus,
588 .read = tegra_pcie_dw_rd_own_conf,
589 .write = tegra_pcie_dw_wr_own_conf,
592 #if defined(CONFIG_PCIEASPM)
593 static void disable_aspm_l11(struct tegra_pcie_dw *pcie)
597 val = dw_pcie_readl_dbi(&pcie->pci, pcie->cfg_link_cap_l1sub);
598 val &= ~PCI_L1SS_CAP_ASPM_L1_1;
599 dw_pcie_writel_dbi(&pcie->pci, pcie->cfg_link_cap_l1sub, val);
602 static void disable_aspm_l12(struct tegra_pcie_dw *pcie)
606 val = dw_pcie_readl_dbi(&pcie->pci, pcie->cfg_link_cap_l1sub);
607 val &= ~PCI_L1SS_CAP_ASPM_L1_2;
608 dw_pcie_writel_dbi(&pcie->pci, pcie->cfg_link_cap_l1sub, val);
611 static inline u32 event_counter_prog(struct tegra_pcie_dw *pcie, u32 event)
615 val = dw_pcie_readl_dbi(&pcie->pci, pcie->ras_des_cap +
616 PCIE_RAS_DES_EVENT_COUNTER_CONTROL);
617 val &= ~(EVENT_COUNTER_EVENT_SEL_MASK << EVENT_COUNTER_EVENT_SEL_SHIFT);
618 val |= EVENT_COUNTER_GROUP_5 << EVENT_COUNTER_GROUP_SEL_SHIFT;
619 val |= event << EVENT_COUNTER_EVENT_SEL_SHIFT;
620 val |= EVENT_COUNTER_ENABLE_ALL << EVENT_COUNTER_ENABLE_SHIFT;
621 dw_pcie_writel_dbi(&pcie->pci, pcie->ras_des_cap +
622 PCIE_RAS_DES_EVENT_COUNTER_CONTROL, val);
623 val = dw_pcie_readl_dbi(&pcie->pci, pcie->ras_des_cap +
624 PCIE_RAS_DES_EVENT_COUNTER_DATA);
629 static int aspm_state_cnt(struct seq_file *s, void *data)
631 struct tegra_pcie_dw *pcie = (struct tegra_pcie_dw *)
632 dev_get_drvdata(s->private);
635 seq_printf(s, "Tx L0s entry count : %u\n",
636 event_counter_prog(pcie, EVENT_COUNTER_EVENT_Tx_L0S));
638 seq_printf(s, "Rx L0s entry count : %u\n",
639 event_counter_prog(pcie, EVENT_COUNTER_EVENT_Rx_L0S));
641 seq_printf(s, "Link L1 entry count : %u\n",
642 event_counter_prog(pcie, EVENT_COUNTER_EVENT_L1));
644 seq_printf(s, "Link L1.1 entry count : %u\n",
645 event_counter_prog(pcie, EVENT_COUNTER_EVENT_L1_1));
647 seq_printf(s, "Link L1.2 entry count : %u\n",
648 event_counter_prog(pcie, EVENT_COUNTER_EVENT_L1_2));
650 /* Clear all counters */
651 dw_pcie_writel_dbi(&pcie->pci, pcie->ras_des_cap +
652 PCIE_RAS_DES_EVENT_COUNTER_CONTROL,
653 EVENT_COUNTER_ALL_CLEAR);
655 /* Re-enable counting */
656 val = EVENT_COUNTER_ENABLE_ALL << EVENT_COUNTER_ENABLE_SHIFT;
657 val |= EVENT_COUNTER_GROUP_5 << EVENT_COUNTER_GROUP_SEL_SHIFT;
658 dw_pcie_writel_dbi(&pcie->pci, pcie->ras_des_cap +
659 PCIE_RAS_DES_EVENT_COUNTER_CONTROL, val);
664 static void init_host_aspm(struct tegra_pcie_dw *pcie)
666 struct dw_pcie *pci = &pcie->pci;
669 val = dw_pcie_find_ext_capability(pci, PCI_EXT_CAP_ID_L1SS);
670 pcie->cfg_link_cap_l1sub = val + PCI_L1SS_CAP;
672 pcie->ras_des_cap = dw_pcie_find_ext_capability(&pcie->pci,
673 PCI_EXT_CAP_ID_VNDR);
675 /* Enable ASPM counters */
676 val = EVENT_COUNTER_ENABLE_ALL << EVENT_COUNTER_ENABLE_SHIFT;
677 val |= EVENT_COUNTER_GROUP_5 << EVENT_COUNTER_GROUP_SEL_SHIFT;
678 dw_pcie_writel_dbi(pci, pcie->ras_des_cap +
679 PCIE_RAS_DES_EVENT_COUNTER_CONTROL, val);
681 /* Program T_cmrt and T_pwr_on values */
682 val = dw_pcie_readl_dbi(pci, pcie->cfg_link_cap_l1sub);
683 val &= ~(PCI_L1SS_CAP_CM_RESTORE_TIME | PCI_L1SS_CAP_P_PWR_ON_VALUE);
684 val |= (pcie->aspm_cmrt << 8);
685 val |= (pcie->aspm_pwr_on_t << 19);
686 dw_pcie_writel_dbi(pci, pcie->cfg_link_cap_l1sub, val);
688 /* Program L0s and L1 entrance latencies */
689 val = dw_pcie_readl_dbi(pci, PCIE_PORT_AFR);
690 val &= ~PORT_AFR_L0S_ENTRANCE_LAT_MASK;
691 val |= (pcie->aspm_l0s_enter_lat << PORT_AFR_L0S_ENTRANCE_LAT_SHIFT);
692 val |= PORT_AFR_ENTER_ASPM;
693 dw_pcie_writel_dbi(pci, PCIE_PORT_AFR, val);
696 static void init_debugfs(struct tegra_pcie_dw *pcie)
698 debugfs_create_devm_seqfile(pcie->dev, "aspm_state_cnt", pcie->debugfs,
702 static inline void disable_aspm_l12(struct tegra_pcie_dw *pcie) { return; }
703 static inline void disable_aspm_l11(struct tegra_pcie_dw *pcie) { return; }
704 static inline void init_host_aspm(struct tegra_pcie_dw *pcie) { return; }
705 static inline void init_debugfs(struct tegra_pcie_dw *pcie) { return; }
708 static void tegra_pcie_enable_system_interrupts(struct dw_pcie_rp *pp)
710 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
711 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci);
715 val = appl_readl(pcie, APPL_INTR_EN_L0_0);
716 val |= APPL_INTR_EN_L0_0_LINK_STATE_INT_EN;
717 appl_writel(pcie, val, APPL_INTR_EN_L0_0);
719 if (!pcie->of_data->has_sbr_reset_fix) {
720 val = appl_readl(pcie, APPL_INTR_EN_L1_0_0);
721 val |= APPL_INTR_EN_L1_0_0_LINK_REQ_RST_NOT_INT_EN;
722 appl_writel(pcie, val, APPL_INTR_EN_L1_0_0);
725 if (pcie->enable_cdm_check) {
726 val = appl_readl(pcie, APPL_INTR_EN_L0_0);
727 val |= pcie->of_data->cdm_chk_int_en_bit;
728 appl_writel(pcie, val, APPL_INTR_EN_L0_0);
730 val = appl_readl(pcie, APPL_INTR_EN_L1_18);
731 val |= APPL_INTR_EN_L1_18_CDM_REG_CHK_CMP_ERR;
732 val |= APPL_INTR_EN_L1_18_CDM_REG_CHK_LOGIC_ERR;
733 appl_writel(pcie, val, APPL_INTR_EN_L1_18);
736 val_w = dw_pcie_readw_dbi(&pcie->pci, pcie->pcie_cap_base +
738 pcie->init_link_width = (val_w & PCI_EXP_LNKSTA_NLW) >>
739 PCI_EXP_LNKSTA_NLW_SHIFT;
741 val_w = dw_pcie_readw_dbi(&pcie->pci, pcie->pcie_cap_base +
743 val_w |= PCI_EXP_LNKCTL_LBMIE;
744 dw_pcie_writew_dbi(&pcie->pci, pcie->pcie_cap_base + PCI_EXP_LNKCTL,
748 static void tegra_pcie_enable_legacy_interrupts(struct dw_pcie_rp *pp)
750 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
751 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci);
754 /* Enable legacy interrupt generation */
755 val = appl_readl(pcie, APPL_INTR_EN_L0_0);
756 val |= APPL_INTR_EN_L0_0_SYS_INTR_EN;
757 val |= APPL_INTR_EN_L0_0_INT_INT_EN;
758 appl_writel(pcie, val, APPL_INTR_EN_L0_0);
760 val = appl_readl(pcie, APPL_INTR_EN_L1_8_0);
761 val |= APPL_INTR_EN_L1_8_INTX_EN;
762 val |= APPL_INTR_EN_L1_8_AUTO_BW_INT_EN;
763 val |= APPL_INTR_EN_L1_8_BW_MGT_INT_EN;
764 if (IS_ENABLED(CONFIG_PCIEAER))
765 val |= APPL_INTR_EN_L1_8_AER_INT_EN;
766 appl_writel(pcie, val, APPL_INTR_EN_L1_8_0);
769 static void tegra_pcie_enable_msi_interrupts(struct dw_pcie_rp *pp)
771 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
772 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci);
775 /* Enable MSI interrupt generation */
776 val = appl_readl(pcie, APPL_INTR_EN_L0_0);
777 val |= APPL_INTR_EN_L0_0_SYS_MSI_INTR_EN;
778 val |= APPL_INTR_EN_L0_0_MSI_RCV_INT_EN;
779 appl_writel(pcie, val, APPL_INTR_EN_L0_0);
782 static void tegra_pcie_enable_interrupts(struct dw_pcie_rp *pp)
784 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
785 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci);
787 /* Clear interrupt statuses before enabling interrupts */
788 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L0);
789 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_0_0);
790 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_1);
791 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_2);
792 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_3);
793 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_6);
794 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_7);
795 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_8_0);
796 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_9);
797 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_10);
798 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_11);
799 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_13);
800 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_14);
801 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_15);
802 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_17);
804 tegra_pcie_enable_system_interrupts(pp);
805 tegra_pcie_enable_legacy_interrupts(pp);
806 if (IS_ENABLED(CONFIG_PCI_MSI))
807 tegra_pcie_enable_msi_interrupts(pp);
810 static void config_gen3_gen4_eq_presets(struct tegra_pcie_dw *pcie)
812 struct dw_pcie *pci = &pcie->pci;
815 /* Program init preset */
816 for (i = 0; i < pcie->num_lanes; i++) {
817 val = dw_pcie_readw_dbi(pci, CAP_SPCIE_CAP_OFF + (i * 2));
818 val &= ~CAP_SPCIE_CAP_OFF_DSP_TX_PRESET0_MASK;
819 val |= GEN3_GEN4_EQ_PRESET_INIT;
820 val &= ~CAP_SPCIE_CAP_OFF_USP_TX_PRESET0_MASK;
821 val |= (GEN3_GEN4_EQ_PRESET_INIT <<
822 CAP_SPCIE_CAP_OFF_USP_TX_PRESET0_SHIFT);
823 dw_pcie_writew_dbi(pci, CAP_SPCIE_CAP_OFF + (i * 2), val);
825 offset = dw_pcie_find_ext_capability(pci,
826 PCI_EXT_CAP_ID_PL_16GT) +
828 val = dw_pcie_readb_dbi(pci, offset + i);
829 val &= ~PCI_PL_16GT_LE_CTRL_DSP_TX_PRESET_MASK;
830 val |= GEN3_GEN4_EQ_PRESET_INIT;
831 val &= ~PCI_PL_16GT_LE_CTRL_USP_TX_PRESET_MASK;
832 val |= (GEN3_GEN4_EQ_PRESET_INIT <<
833 PCI_PL_16GT_LE_CTRL_USP_TX_PRESET_SHIFT);
834 dw_pcie_writeb_dbi(pci, offset + i, val);
837 val = dw_pcie_readl_dbi(pci, GEN3_RELATED_OFF);
838 val &= ~GEN3_RELATED_OFF_RATE_SHADOW_SEL_MASK;
839 dw_pcie_writel_dbi(pci, GEN3_RELATED_OFF, val);
841 val = dw_pcie_readl_dbi(pci, GEN3_EQ_CONTROL_OFF);
842 val &= ~GEN3_EQ_CONTROL_OFF_PSET_REQ_VEC_MASK;
843 val |= (0x3ff << GEN3_EQ_CONTROL_OFF_PSET_REQ_VEC_SHIFT);
844 val &= ~GEN3_EQ_CONTROL_OFF_FB_MODE_MASK;
845 dw_pcie_writel_dbi(pci, GEN3_EQ_CONTROL_OFF, val);
847 val = dw_pcie_readl_dbi(pci, GEN3_RELATED_OFF);
848 val &= ~GEN3_RELATED_OFF_RATE_SHADOW_SEL_MASK;
849 val |= (0x1 << GEN3_RELATED_OFF_RATE_SHADOW_SEL_SHIFT);
850 dw_pcie_writel_dbi(pci, GEN3_RELATED_OFF, val);
852 val = dw_pcie_readl_dbi(pci, GEN3_EQ_CONTROL_OFF);
853 val &= ~GEN3_EQ_CONTROL_OFF_PSET_REQ_VEC_MASK;
854 val |= (pcie->of_data->gen4_preset_vec <<
855 GEN3_EQ_CONTROL_OFF_PSET_REQ_VEC_SHIFT);
856 val &= ~GEN3_EQ_CONTROL_OFF_FB_MODE_MASK;
857 dw_pcie_writel_dbi(pci, GEN3_EQ_CONTROL_OFF, val);
859 val = dw_pcie_readl_dbi(pci, GEN3_RELATED_OFF);
860 val &= ~GEN3_RELATED_OFF_RATE_SHADOW_SEL_MASK;
861 dw_pcie_writel_dbi(pci, GEN3_RELATED_OFF, val);
864 static int tegra_pcie_dw_host_init(struct dw_pcie_rp *pp)
866 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
867 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci);
871 pp->bridge->ops = &tegra_pci_ops;
873 if (!pcie->pcie_cap_base)
874 pcie->pcie_cap_base = dw_pcie_find_capability(&pcie->pci,
877 val_16 = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + PCI_EXP_DEVCTL);
878 val_16 &= ~PCI_EXP_DEVCTL_PAYLOAD;
879 val_16 |= PCI_EXP_DEVCTL_PAYLOAD_256B;
880 dw_pcie_writew_dbi(pci, pcie->pcie_cap_base + PCI_EXP_DEVCTL, val_16);
882 val = dw_pcie_readl_dbi(pci, PCI_IO_BASE);
883 val &= ~(IO_BASE_IO_DECODE | IO_BASE_IO_DECODE_BIT8);
884 dw_pcie_writel_dbi(pci, PCI_IO_BASE, val);
886 val = dw_pcie_readl_dbi(pci, PCI_PREF_MEMORY_BASE);
887 val |= CFG_PREF_MEM_LIMIT_BASE_MEM_DECODE;
888 val |= CFG_PREF_MEM_LIMIT_BASE_MEM_LIMIT_DECODE;
889 dw_pcie_writel_dbi(pci, PCI_PREF_MEMORY_BASE, val);
891 dw_pcie_writel_dbi(pci, PCI_BASE_ADDRESS_0, 0);
893 /* Enable as 0xFFFF0001 response for CRS */
894 val = dw_pcie_readl_dbi(pci, PORT_LOGIC_AMBA_ERROR_RESPONSE_DEFAULT);
895 val &= ~(AMBA_ERROR_RESPONSE_CRS_MASK << AMBA_ERROR_RESPONSE_CRS_SHIFT);
896 val |= (AMBA_ERROR_RESPONSE_CRS_OKAY_FFFF0001 <<
897 AMBA_ERROR_RESPONSE_CRS_SHIFT);
898 dw_pcie_writel_dbi(pci, PORT_LOGIC_AMBA_ERROR_RESPONSE_DEFAULT, val);
900 /* Configure Max lane width from DT */
901 val = dw_pcie_readl_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKCAP);
902 val &= ~PCI_EXP_LNKCAP_MLW;
903 val |= (pcie->num_lanes << PCI_EXP_LNKSTA_NLW_SHIFT);
904 dw_pcie_writel_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKCAP, val);
906 /* Clear Slot Clock Configuration bit if SRNS configuration */
907 if (pcie->enable_srns) {
908 val_16 = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base +
910 val_16 &= ~PCI_EXP_LNKSTA_SLC;
911 dw_pcie_writew_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKSTA,
915 config_gen3_gen4_eq_presets(pcie);
917 init_host_aspm(pcie);
919 /* Disable ASPM-L1SS advertisement if there is no CLKREQ routing */
920 if (!pcie->supports_clkreq) {
921 disable_aspm_l11(pcie);
922 disable_aspm_l12(pcie);
925 if (!pcie->of_data->has_l1ss_exit_fix) {
926 val = dw_pcie_readl_dbi(pci, GEN3_RELATED_OFF);
927 val &= ~GEN3_RELATED_OFF_GEN3_ZRXDC_NONCOMPL;
928 dw_pcie_writel_dbi(pci, GEN3_RELATED_OFF, val);
931 if (pcie->update_fc_fixup) {
932 val = dw_pcie_readl_dbi(pci, CFG_TIMER_CTRL_MAX_FUNC_NUM_OFF);
933 val |= 0x1 << CFG_TIMER_CTRL_ACK_NAK_SHIFT;
934 dw_pcie_writel_dbi(pci, CFG_TIMER_CTRL_MAX_FUNC_NUM_OFF, val);
937 clk_set_rate(pcie->core_clk, GEN4_CORE_CLK_FREQ);
942 static int tegra_pcie_dw_start_link(struct dw_pcie *pci)
944 u32 val, offset, speed, tmp;
945 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci);
946 struct dw_pcie_rp *pp = &pci->pp;
949 if (pcie->of_data->mode == DW_PCIE_EP_TYPE) {
950 enable_irq(pcie->pex_rst_irq);
956 val = appl_readl(pcie, APPL_PINMUX);
957 val &= ~APPL_PINMUX_PEX_RST;
958 appl_writel(pcie, val, APPL_PINMUX);
960 usleep_range(100, 200);
963 val = appl_readl(pcie, APPL_CTRL);
964 val |= APPL_CTRL_LTSSM_EN;
965 appl_writel(pcie, val, APPL_CTRL);
968 val = appl_readl(pcie, APPL_PINMUX);
969 val |= APPL_PINMUX_PEX_RST;
970 appl_writel(pcie, val, APPL_PINMUX);
974 if (dw_pcie_wait_for_link(pci)) {
978 * There are some endpoints which can't get the link up if
979 * root port has Data Link Feature (DLF) enabled.
980 * Refer Spec rev 4.0 ver 1.0 sec 3.4.2 & 7.7.4 for more info
981 * on Scaled Flow Control and DLF.
982 * So, need to confirm that is indeed the case here and attempt
983 * link up once again with DLF disabled.
985 val = appl_readl(pcie, APPL_DEBUG);
986 val &= APPL_DEBUG_LTSSM_STATE_MASK;
987 val >>= APPL_DEBUG_LTSSM_STATE_SHIFT;
988 tmp = appl_readl(pcie, APPL_LINK_STATUS);
989 tmp &= APPL_LINK_STATUS_RDLH_LINK_UP;
990 if (!(val == 0x11 && !tmp)) {
991 /* Link is down for all good reasons */
995 dev_info(pci->dev, "Link is down in DLL");
996 dev_info(pci->dev, "Trying again with DLFE disabled\n");
998 val = appl_readl(pcie, APPL_CTRL);
999 val &= ~APPL_CTRL_LTSSM_EN;
1000 appl_writel(pcie, val, APPL_CTRL);
1002 reset_control_assert(pcie->core_rst);
1003 reset_control_deassert(pcie->core_rst);
1005 offset = dw_pcie_find_ext_capability(pci, PCI_EXT_CAP_ID_DLF);
1006 val = dw_pcie_readl_dbi(pci, offset + PCI_DLF_CAP);
1007 val &= ~PCI_DLF_EXCHANGE_ENABLE;
1008 dw_pcie_writel_dbi(pci, offset + PCI_DLF_CAP, val);
1010 tegra_pcie_dw_host_init(pp);
1011 dw_pcie_setup_rc(pp);
1017 speed = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKSTA) &
1019 clk_set_rate(pcie->core_clk, pcie_gen_freq[speed - 1]);
1021 tegra_pcie_enable_interrupts(pp);
1026 static int tegra_pcie_dw_link_up(struct dw_pcie *pci)
1028 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci);
1029 u32 val = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKSTA);
1031 return !!(val & PCI_EXP_LNKSTA_DLLLA);
1034 static void tegra_pcie_dw_stop_link(struct dw_pcie *pci)
1036 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci);
1038 disable_irq(pcie->pex_rst_irq);
1041 static const struct dw_pcie_ops tegra_dw_pcie_ops = {
1042 .link_up = tegra_pcie_dw_link_up,
1043 .start_link = tegra_pcie_dw_start_link,
1044 .stop_link = tegra_pcie_dw_stop_link,
1047 static const struct dw_pcie_host_ops tegra_pcie_dw_host_ops = {
1048 .host_init = tegra_pcie_dw_host_init,
1051 static void tegra_pcie_disable_phy(struct tegra_pcie_dw *pcie)
1053 unsigned int phy_count = pcie->phy_count;
1055 while (phy_count--) {
1056 phy_power_off(pcie->phys[phy_count]);
1057 phy_exit(pcie->phys[phy_count]);
1061 static int tegra_pcie_enable_phy(struct tegra_pcie_dw *pcie)
1066 for (i = 0; i < pcie->phy_count; i++) {
1067 ret = phy_init(pcie->phys[i]);
1071 ret = phy_power_on(pcie->phys[i]);
1080 phy_power_off(pcie->phys[i]);
1082 phy_exit(pcie->phys[i]);
1088 static int tegra_pcie_dw_parse_dt(struct tegra_pcie_dw *pcie)
1090 struct platform_device *pdev = to_platform_device(pcie->dev);
1091 struct device_node *np = pcie->dev->of_node;
1094 pcie->dbi_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dbi");
1095 if (!pcie->dbi_res) {
1096 dev_err(pcie->dev, "Failed to find \"dbi\" region\n");
1100 ret = of_property_read_u32(np, "nvidia,aspm-cmrt-us", &pcie->aspm_cmrt);
1102 dev_info(pcie->dev, "Failed to read ASPM T_cmrt: %d\n", ret);
1106 ret = of_property_read_u32(np, "nvidia,aspm-pwr-on-t-us",
1107 &pcie->aspm_pwr_on_t);
1109 dev_info(pcie->dev, "Failed to read ASPM Power On time: %d\n",
1112 ret = of_property_read_u32(np, "nvidia,aspm-l0s-entrance-latency-us",
1113 &pcie->aspm_l0s_enter_lat);
1116 "Failed to read ASPM L0s Entrance latency: %d\n", ret);
1118 ret = of_property_read_u32(np, "num-lanes", &pcie->num_lanes);
1120 dev_err(pcie->dev, "Failed to read num-lanes: %d\n", ret);
1124 ret = of_property_read_u32_index(np, "nvidia,bpmp", 1, &pcie->cid);
1126 dev_err(pcie->dev, "Failed to read Controller-ID: %d\n", ret);
1130 ret = of_property_count_strings(np, "phy-names");
1132 dev_err(pcie->dev, "Failed to find PHY entries: %d\n",
1136 pcie->phy_count = ret;
1138 if (of_property_read_bool(np, "nvidia,update-fc-fixup"))
1139 pcie->update_fc_fixup = true;
1141 /* RP using an external REFCLK is supported only in Tegra234 */
1142 if (pcie->of_data->version == TEGRA194_DWC_IP_VER) {
1143 if (pcie->of_data->mode == DW_PCIE_EP_TYPE)
1144 pcie->enable_ext_refclk = true;
1146 pcie->enable_ext_refclk =
1147 of_property_read_bool(pcie->dev->of_node,
1148 "nvidia,enable-ext-refclk");
1151 pcie->supports_clkreq =
1152 of_property_read_bool(pcie->dev->of_node, "supports-clkreq");
1154 pcie->enable_cdm_check =
1155 of_property_read_bool(np, "snps,enable-cdm-check");
1157 if (pcie->of_data->version == TEGRA234_DWC_IP_VER)
1159 of_property_read_bool(np, "nvidia,enable-srns");
1161 if (pcie->of_data->mode == DW_PCIE_RC_TYPE)
1164 /* Endpoint mode specific DT entries */
1165 pcie->pex_rst_gpiod = devm_gpiod_get(pcie->dev, "reset", GPIOD_IN);
1166 if (IS_ERR(pcie->pex_rst_gpiod)) {
1167 int err = PTR_ERR(pcie->pex_rst_gpiod);
1168 const char *level = KERN_ERR;
1170 if (err == -EPROBE_DEFER)
1173 dev_printk(level, pcie->dev,
1174 dev_fmt("Failed to get PERST GPIO: %d\n"),
1179 pcie->pex_refclk_sel_gpiod = devm_gpiod_get(pcie->dev,
1180 "nvidia,refclk-select",
1182 if (IS_ERR(pcie->pex_refclk_sel_gpiod)) {
1183 int err = PTR_ERR(pcie->pex_refclk_sel_gpiod);
1184 const char *level = KERN_ERR;
1186 if (err == -EPROBE_DEFER)
1189 dev_printk(level, pcie->dev,
1190 dev_fmt("Failed to get REFCLK select GPIOs: %d\n"),
1192 pcie->pex_refclk_sel_gpiod = NULL;
1198 static int tegra_pcie_bpmp_set_ctrl_state(struct tegra_pcie_dw *pcie,
1201 struct mrq_uphy_response resp;
1202 struct tegra_bpmp_message msg;
1203 struct mrq_uphy_request req;
1206 * Controller-5 doesn't need to have its state set by BPMP-FW in
1209 if (pcie->of_data->version == TEGRA194_DWC_IP_VER && pcie->cid == 5)
1212 memset(&req, 0, sizeof(req));
1213 memset(&resp, 0, sizeof(resp));
1215 req.cmd = CMD_UPHY_PCIE_CONTROLLER_STATE;
1216 req.controller_state.pcie_controller = pcie->cid;
1217 req.controller_state.enable = enable;
1219 memset(&msg, 0, sizeof(msg));
1222 msg.tx.size = sizeof(req);
1223 msg.rx.data = &resp;
1224 msg.rx.size = sizeof(resp);
1226 return tegra_bpmp_transfer(pcie->bpmp, &msg);
1229 static int tegra_pcie_bpmp_set_pll_state(struct tegra_pcie_dw *pcie,
1232 struct mrq_uphy_response resp;
1233 struct tegra_bpmp_message msg;
1234 struct mrq_uphy_request req;
1236 memset(&req, 0, sizeof(req));
1237 memset(&resp, 0, sizeof(resp));
1240 req.cmd = CMD_UPHY_PCIE_EP_CONTROLLER_PLL_INIT;
1241 req.ep_ctrlr_pll_init.ep_controller = pcie->cid;
1243 req.cmd = CMD_UPHY_PCIE_EP_CONTROLLER_PLL_OFF;
1244 req.ep_ctrlr_pll_off.ep_controller = pcie->cid;
1247 memset(&msg, 0, sizeof(msg));
1250 msg.tx.size = sizeof(req);
1251 msg.rx.data = &resp;
1252 msg.rx.size = sizeof(resp);
1254 return tegra_bpmp_transfer(pcie->bpmp, &msg);
1257 static void tegra_pcie_downstream_dev_to_D0(struct tegra_pcie_dw *pcie)
1259 struct dw_pcie_rp *pp = &pcie->pci.pp;
1260 struct pci_bus *child, *root_bus = NULL;
1261 struct pci_dev *pdev;
1264 * link doesn't go into L2 state with some of the endpoints with Tegra
1265 * if they are not in D0 state. So, need to make sure that immediate
1266 * downstream devices are in D0 state before sending PME_TurnOff to put
1267 * link into L2 state.
1268 * This is as per PCI Express Base r4.0 v1.0 September 27-2017,
1269 * 5.2 Link State Power Management (Page #428).
1272 list_for_each_entry(child, &pp->bridge->bus->children, node) {
1273 /* Bring downstream devices to D0 if they are not already in */
1274 if (child->parent == pp->bridge->bus) {
1281 dev_err(pcie->dev, "Failed to find downstream devices\n");
1285 list_for_each_entry(pdev, &root_bus->devices, bus_list) {
1286 if (PCI_SLOT(pdev->devfn) == 0) {
1287 if (pci_set_power_state(pdev, PCI_D0))
1289 "Failed to transition %s to D0 state\n",
1290 dev_name(&pdev->dev));
1295 static int tegra_pcie_get_slot_regulators(struct tegra_pcie_dw *pcie)
1297 pcie->slot_ctl_3v3 = devm_regulator_get_optional(pcie->dev, "vpcie3v3");
1298 if (IS_ERR(pcie->slot_ctl_3v3)) {
1299 if (PTR_ERR(pcie->slot_ctl_3v3) != -ENODEV)
1300 return PTR_ERR(pcie->slot_ctl_3v3);
1302 pcie->slot_ctl_3v3 = NULL;
1305 pcie->slot_ctl_12v = devm_regulator_get_optional(pcie->dev, "vpcie12v");
1306 if (IS_ERR(pcie->slot_ctl_12v)) {
1307 if (PTR_ERR(pcie->slot_ctl_12v) != -ENODEV)
1308 return PTR_ERR(pcie->slot_ctl_12v);
1310 pcie->slot_ctl_12v = NULL;
1316 static int tegra_pcie_enable_slot_regulators(struct tegra_pcie_dw *pcie)
1320 if (pcie->slot_ctl_3v3) {
1321 ret = regulator_enable(pcie->slot_ctl_3v3);
1324 "Failed to enable 3.3V slot supply: %d\n", ret);
1329 if (pcie->slot_ctl_12v) {
1330 ret = regulator_enable(pcie->slot_ctl_12v);
1333 "Failed to enable 12V slot supply: %d\n", ret);
1334 goto fail_12v_enable;
1339 * According to PCI Express Card Electromechanical Specification
1340 * Revision 1.1, Table-2.4, T_PVPERL (Power stable to PERST# inactive)
1341 * should be a minimum of 100ms.
1343 if (pcie->slot_ctl_3v3 || pcie->slot_ctl_12v)
1349 if (pcie->slot_ctl_3v3)
1350 regulator_disable(pcie->slot_ctl_3v3);
1354 static void tegra_pcie_disable_slot_regulators(struct tegra_pcie_dw *pcie)
1356 if (pcie->slot_ctl_12v)
1357 regulator_disable(pcie->slot_ctl_12v);
1358 if (pcie->slot_ctl_3v3)
1359 regulator_disable(pcie->slot_ctl_3v3);
1362 static int tegra_pcie_config_controller(struct tegra_pcie_dw *pcie,
1368 ret = tegra_pcie_bpmp_set_ctrl_state(pcie, true);
1371 "Failed to enable controller %u: %d\n", pcie->cid, ret);
1375 if (pcie->enable_ext_refclk) {
1376 ret = tegra_pcie_bpmp_set_pll_state(pcie, true);
1378 dev_err(pcie->dev, "Failed to init UPHY: %d\n", ret);
1383 ret = tegra_pcie_enable_slot_regulators(pcie);
1385 goto fail_slot_reg_en;
1387 ret = regulator_enable(pcie->pex_ctl_supply);
1389 dev_err(pcie->dev, "Failed to enable regulator: %d\n", ret);
1393 ret = clk_prepare_enable(pcie->core_clk);
1395 dev_err(pcie->dev, "Failed to enable core clock: %d\n", ret);
1399 ret = reset_control_deassert(pcie->core_apb_rst);
1401 dev_err(pcie->dev, "Failed to deassert core APB reset: %d\n",
1403 goto fail_core_apb_rst;
1406 if (en_hw_hot_rst || pcie->of_data->has_sbr_reset_fix) {
1407 /* Enable HW_HOT_RST mode */
1408 val = appl_readl(pcie, APPL_CTRL);
1409 val &= ~(APPL_CTRL_HW_HOT_RST_MODE_MASK <<
1410 APPL_CTRL_HW_HOT_RST_MODE_SHIFT);
1411 val |= (APPL_CTRL_HW_HOT_RST_MODE_IMDT_RST_LTSSM_EN <<
1412 APPL_CTRL_HW_HOT_RST_MODE_SHIFT);
1413 val |= APPL_CTRL_HW_HOT_RST_EN;
1414 appl_writel(pcie, val, APPL_CTRL);
1417 ret = tegra_pcie_enable_phy(pcie);
1419 dev_err(pcie->dev, "Failed to enable PHY: %d\n", ret);
1423 /* Update CFG base address */
1424 appl_writel(pcie, pcie->dbi_res->start & APPL_CFG_BASE_ADDR_MASK,
1425 APPL_CFG_BASE_ADDR);
1427 /* Configure this core for RP mode operation */
1428 appl_writel(pcie, APPL_DM_TYPE_RP, APPL_DM_TYPE);
1430 appl_writel(pcie, 0x0, APPL_CFG_SLCG_OVERRIDE);
1432 val = appl_readl(pcie, APPL_CTRL);
1433 appl_writel(pcie, val | APPL_CTRL_SYS_PRE_DET_STATE, APPL_CTRL);
1435 val = appl_readl(pcie, APPL_CFG_MISC);
1436 val |= (APPL_CFG_MISC_ARCACHE_VAL << APPL_CFG_MISC_ARCACHE_SHIFT);
1437 appl_writel(pcie, val, APPL_CFG_MISC);
1439 if (pcie->enable_srns || pcie->enable_ext_refclk) {
1441 * When Tegra PCIe RP is using external clock, it cannot supply
1442 * same clock to its downstream hierarchy. Hence, gate PCIe RP
1443 * REFCLK out pads when RP & EP are using separate clocks or RP
1444 * is using an external REFCLK.
1446 val = appl_readl(pcie, APPL_PINMUX);
1447 val |= APPL_PINMUX_CLK_OUTPUT_IN_OVERRIDE_EN;
1448 val &= ~APPL_PINMUX_CLK_OUTPUT_IN_OVERRIDE;
1449 appl_writel(pcie, val, APPL_PINMUX);
1452 if (!pcie->supports_clkreq) {
1453 val = appl_readl(pcie, APPL_PINMUX);
1454 val |= APPL_PINMUX_CLKREQ_OVERRIDE_EN;
1455 val &= ~APPL_PINMUX_CLKREQ_OVERRIDE;
1456 appl_writel(pcie, val, APPL_PINMUX);
1459 /* Update iATU_DMA base address */
1461 pcie->atu_dma_res->start & APPL_CFG_IATU_DMA_BASE_ADDR_MASK,
1462 APPL_CFG_IATU_DMA_BASE_ADDR);
1464 reset_control_deassert(pcie->core_rst);
1469 reset_control_assert(pcie->core_apb_rst);
1471 clk_disable_unprepare(pcie->core_clk);
1473 regulator_disable(pcie->pex_ctl_supply);
1475 tegra_pcie_disable_slot_regulators(pcie);
1477 if (pcie->enable_ext_refclk)
1478 tegra_pcie_bpmp_set_pll_state(pcie, false);
1480 tegra_pcie_bpmp_set_ctrl_state(pcie, false);
1485 static void tegra_pcie_unconfig_controller(struct tegra_pcie_dw *pcie)
1489 ret = reset_control_assert(pcie->core_rst);
1491 dev_err(pcie->dev, "Failed to assert \"core\" reset: %d\n", ret);
1493 tegra_pcie_disable_phy(pcie);
1495 ret = reset_control_assert(pcie->core_apb_rst);
1497 dev_err(pcie->dev, "Failed to assert APB reset: %d\n", ret);
1499 clk_disable_unprepare(pcie->core_clk);
1501 ret = regulator_disable(pcie->pex_ctl_supply);
1503 dev_err(pcie->dev, "Failed to disable regulator: %d\n", ret);
1505 tegra_pcie_disable_slot_regulators(pcie);
1507 if (pcie->enable_ext_refclk) {
1508 ret = tegra_pcie_bpmp_set_pll_state(pcie, false);
1510 dev_err(pcie->dev, "Failed to deinit UPHY: %d\n", ret);
1513 ret = tegra_pcie_bpmp_set_ctrl_state(pcie, false);
1515 dev_err(pcie->dev, "Failed to disable controller %d: %d\n",
1519 static int tegra_pcie_init_controller(struct tegra_pcie_dw *pcie)
1521 struct dw_pcie *pci = &pcie->pci;
1522 struct dw_pcie_rp *pp = &pci->pp;
1525 ret = tegra_pcie_config_controller(pcie, false);
1529 pp->ops = &tegra_pcie_dw_host_ops;
1531 ret = dw_pcie_host_init(pp);
1533 dev_err(pcie->dev, "Failed to add PCIe port: %d\n", ret);
1534 goto fail_host_init;
1540 tegra_pcie_unconfig_controller(pcie);
1544 static int tegra_pcie_try_link_l2(struct tegra_pcie_dw *pcie)
1548 if (!tegra_pcie_dw_link_up(&pcie->pci))
1551 val = appl_readl(pcie, APPL_RADM_STATUS);
1552 val |= APPL_PM_XMT_TURNOFF_STATE;
1553 appl_writel(pcie, val, APPL_RADM_STATUS);
1555 return readl_poll_timeout_atomic(pcie->appl_base + APPL_DEBUG, val,
1556 val & APPL_DEBUG_PM_LINKST_IN_L2_LAT,
1557 1, PME_ACK_TIMEOUT);
1560 static void tegra_pcie_dw_pme_turnoff(struct tegra_pcie_dw *pcie)
1565 if (!tegra_pcie_dw_link_up(&pcie->pci)) {
1566 dev_dbg(pcie->dev, "PCIe link is not up...!\n");
1571 * PCIe controller exits from L2 only if reset is applied, so
1572 * controller doesn't handle interrupts. But in cases where
1573 * L2 entry fails, PERST# is asserted which can trigger surprise
1574 * link down AER. However this function call happens in
1575 * suspend_noirq(), so AER interrupt will not be processed.
1576 * Disable all interrupts to avoid such a scenario.
1578 appl_writel(pcie, 0x0, APPL_INTR_EN_L0_0);
1580 if (tegra_pcie_try_link_l2(pcie)) {
1581 dev_info(pcie->dev, "Link didn't transition to L2 state\n");
1583 * TX lane clock freq will reset to Gen1 only if link is in L2
1585 * So apply pex_rst to end point to force RP to go into detect
1588 data = appl_readl(pcie, APPL_PINMUX);
1589 data &= ~APPL_PINMUX_PEX_RST;
1590 appl_writel(pcie, data, APPL_PINMUX);
1593 * Some cards do not go to detect state even after de-asserting
1594 * PERST#. So, de-assert LTSSM to bring link to detect state.
1596 data = readl(pcie->appl_base + APPL_CTRL);
1597 data &= ~APPL_CTRL_LTSSM_EN;
1598 writel(data, pcie->appl_base + APPL_CTRL);
1600 err = readl_poll_timeout_atomic(pcie->appl_base + APPL_DEBUG,
1603 APPL_DEBUG_LTSSM_STATE_MASK) >>
1604 APPL_DEBUG_LTSSM_STATE_SHIFT) ==
1605 LTSSM_STATE_PRE_DETECT,
1608 dev_info(pcie->dev, "Link didn't go to detect state\n");
1611 * DBI registers may not be accessible after this as PLL-E would be
1612 * down depending on how CLKREQ is pulled by end point
1614 data = appl_readl(pcie, APPL_PINMUX);
1615 data |= (APPL_PINMUX_CLKREQ_OVERRIDE_EN | APPL_PINMUX_CLKREQ_OVERRIDE);
1616 /* Cut REFCLK to slot */
1617 data |= APPL_PINMUX_CLK_OUTPUT_IN_OVERRIDE_EN;
1618 data &= ~APPL_PINMUX_CLK_OUTPUT_IN_OVERRIDE;
1619 appl_writel(pcie, data, APPL_PINMUX);
1622 static void tegra_pcie_deinit_controller(struct tegra_pcie_dw *pcie)
1624 tegra_pcie_downstream_dev_to_D0(pcie);
1625 dw_pcie_host_deinit(&pcie->pci.pp);
1626 tegra_pcie_dw_pme_turnoff(pcie);
1627 tegra_pcie_unconfig_controller(pcie);
1630 static int tegra_pcie_config_rp(struct tegra_pcie_dw *pcie)
1632 struct device *dev = pcie->dev;
1636 pm_runtime_enable(dev);
1638 ret = pm_runtime_get_sync(dev);
1640 dev_err(dev, "Failed to get runtime sync for PCIe dev: %d\n",
1642 goto fail_pm_get_sync;
1645 ret = pinctrl_pm_select_default_state(dev);
1647 dev_err(dev, "Failed to configure sideband pins: %d\n", ret);
1648 goto fail_pm_get_sync;
1651 ret = tegra_pcie_init_controller(pcie);
1653 dev_err(dev, "Failed to initialize controller: %d\n", ret);
1654 goto fail_pm_get_sync;
1657 pcie->link_state = tegra_pcie_dw_link_up(&pcie->pci);
1658 if (!pcie->link_state) {
1660 goto fail_host_init;
1663 name = devm_kasprintf(dev, GFP_KERNEL, "%pOFP", dev->of_node);
1666 goto fail_host_init;
1669 pcie->debugfs = debugfs_create_dir(name, NULL);
1675 tegra_pcie_deinit_controller(pcie);
1677 pm_runtime_put_sync(dev);
1678 pm_runtime_disable(dev);
1682 static void pex_ep_event_pex_rst_assert(struct tegra_pcie_dw *pcie)
1687 if (pcie->ep_state == EP_STATE_DISABLED)
1691 val = appl_readl(pcie, APPL_CTRL);
1692 val &= ~APPL_CTRL_LTSSM_EN;
1693 appl_writel(pcie, val, APPL_CTRL);
1695 ret = readl_poll_timeout(pcie->appl_base + APPL_DEBUG, val,
1696 ((val & APPL_DEBUG_LTSSM_STATE_MASK) >>
1697 APPL_DEBUG_LTSSM_STATE_SHIFT) ==
1698 LTSSM_STATE_PRE_DETECT,
1701 dev_err(pcie->dev, "Failed to go Detect state: %d\n", ret);
1703 reset_control_assert(pcie->core_rst);
1705 tegra_pcie_disable_phy(pcie);
1707 reset_control_assert(pcie->core_apb_rst);
1709 clk_disable_unprepare(pcie->core_clk);
1711 pm_runtime_put_sync(pcie->dev);
1713 if (pcie->enable_ext_refclk) {
1714 ret = tegra_pcie_bpmp_set_pll_state(pcie, false);
1716 dev_err(pcie->dev, "Failed to turn off UPHY: %d\n",
1720 ret = tegra_pcie_bpmp_set_pll_state(pcie, false);
1722 dev_err(pcie->dev, "Failed to turn off UPHY: %d\n", ret);
1724 pcie->ep_state = EP_STATE_DISABLED;
1725 dev_dbg(pcie->dev, "Uninitialization of endpoint is completed\n");
1728 static void pex_ep_event_pex_rst_deassert(struct tegra_pcie_dw *pcie)
1730 struct dw_pcie *pci = &pcie->pci;
1731 struct dw_pcie_ep *ep = &pci->ep;
1732 struct device *dev = pcie->dev;
1737 if (pcie->ep_state == EP_STATE_ENABLED)
1740 ret = pm_runtime_resume_and_get(dev);
1742 dev_err(dev, "Failed to get runtime sync for PCIe dev: %d\n",
1747 ret = tegra_pcie_bpmp_set_ctrl_state(pcie, true);
1749 dev_err(pcie->dev, "Failed to enable controller %u: %d\n",
1751 goto fail_set_ctrl_state;
1754 if (pcie->enable_ext_refclk) {
1755 ret = tegra_pcie_bpmp_set_pll_state(pcie, true);
1757 dev_err(dev, "Failed to init UPHY for PCIe EP: %d\n",
1763 ret = clk_prepare_enable(pcie->core_clk);
1765 dev_err(dev, "Failed to enable core clock: %d\n", ret);
1766 goto fail_core_clk_enable;
1769 ret = reset_control_deassert(pcie->core_apb_rst);
1771 dev_err(dev, "Failed to deassert core APB reset: %d\n", ret);
1772 goto fail_core_apb_rst;
1775 ret = tegra_pcie_enable_phy(pcie);
1777 dev_err(dev, "Failed to enable PHY: %d\n", ret);
1781 /* Clear any stale interrupt statuses */
1782 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L0);
1783 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_0_0);
1784 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_1);
1785 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_2);
1786 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_3);
1787 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_6);
1788 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_7);
1789 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_8_0);
1790 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_9);
1791 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_10);
1792 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_11);
1793 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_13);
1794 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_14);
1795 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_15);
1796 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_17);
1798 /* configure this core for EP mode operation */
1799 val = appl_readl(pcie, APPL_DM_TYPE);
1800 val &= ~APPL_DM_TYPE_MASK;
1801 val |= APPL_DM_TYPE_EP;
1802 appl_writel(pcie, val, APPL_DM_TYPE);
1804 appl_writel(pcie, 0x0, APPL_CFG_SLCG_OVERRIDE);
1806 val = appl_readl(pcie, APPL_CTRL);
1807 val |= APPL_CTRL_SYS_PRE_DET_STATE;
1808 val |= APPL_CTRL_HW_HOT_RST_EN;
1809 appl_writel(pcie, val, APPL_CTRL);
1811 val = appl_readl(pcie, APPL_CFG_MISC);
1812 val |= APPL_CFG_MISC_SLV_EP_MODE;
1813 val |= (APPL_CFG_MISC_ARCACHE_VAL << APPL_CFG_MISC_ARCACHE_SHIFT);
1814 appl_writel(pcie, val, APPL_CFG_MISC);
1816 val = appl_readl(pcie, APPL_PINMUX);
1817 val |= APPL_PINMUX_CLK_OUTPUT_IN_OVERRIDE_EN;
1818 val |= APPL_PINMUX_CLK_OUTPUT_IN_OVERRIDE;
1819 appl_writel(pcie, val, APPL_PINMUX);
1821 appl_writel(pcie, pcie->dbi_res->start & APPL_CFG_BASE_ADDR_MASK,
1822 APPL_CFG_BASE_ADDR);
1824 appl_writel(pcie, pcie->atu_dma_res->start &
1825 APPL_CFG_IATU_DMA_BASE_ADDR_MASK,
1826 APPL_CFG_IATU_DMA_BASE_ADDR);
1828 val = appl_readl(pcie, APPL_INTR_EN_L0_0);
1829 val |= APPL_INTR_EN_L0_0_SYS_INTR_EN;
1830 val |= APPL_INTR_EN_L0_0_LINK_STATE_INT_EN;
1831 val |= APPL_INTR_EN_L0_0_PCI_CMD_EN_INT_EN;
1832 appl_writel(pcie, val, APPL_INTR_EN_L0_0);
1834 val = appl_readl(pcie, APPL_INTR_EN_L1_0_0);
1835 val |= APPL_INTR_EN_L1_0_0_HOT_RESET_DONE_INT_EN;
1836 val |= APPL_INTR_EN_L1_0_0_RDLH_LINK_UP_INT_EN;
1837 appl_writel(pcie, val, APPL_INTR_EN_L1_0_0);
1839 reset_control_deassert(pcie->core_rst);
1841 if (pcie->update_fc_fixup) {
1842 val = dw_pcie_readl_dbi(pci, CFG_TIMER_CTRL_MAX_FUNC_NUM_OFF);
1843 val |= 0x1 << CFG_TIMER_CTRL_ACK_NAK_SHIFT;
1844 dw_pcie_writel_dbi(pci, CFG_TIMER_CTRL_MAX_FUNC_NUM_OFF, val);
1847 config_gen3_gen4_eq_presets(pcie);
1849 init_host_aspm(pcie);
1851 /* Disable ASPM-L1SS advertisement if there is no CLKREQ routing */
1852 if (!pcie->supports_clkreq) {
1853 disable_aspm_l11(pcie);
1854 disable_aspm_l12(pcie);
1857 if (!pcie->of_data->has_l1ss_exit_fix) {
1858 val = dw_pcie_readl_dbi(pci, GEN3_RELATED_OFF);
1859 val &= ~GEN3_RELATED_OFF_GEN3_ZRXDC_NONCOMPL;
1860 dw_pcie_writel_dbi(pci, GEN3_RELATED_OFF, val);
1863 pcie->pcie_cap_base = dw_pcie_find_capability(&pcie->pci,
1866 val_16 = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + PCI_EXP_DEVCTL);
1867 val_16 &= ~PCI_EXP_DEVCTL_PAYLOAD;
1868 val_16 |= PCI_EXP_DEVCTL_PAYLOAD_256B;
1869 dw_pcie_writew_dbi(pci, pcie->pcie_cap_base + PCI_EXP_DEVCTL, val_16);
1871 /* Clear Slot Clock Configuration bit if SRNS configuration */
1872 if (pcie->enable_srns) {
1873 val_16 = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base +
1875 val_16 &= ~PCI_EXP_LNKSTA_SLC;
1876 dw_pcie_writew_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKSTA,
1880 clk_set_rate(pcie->core_clk, GEN4_CORE_CLK_FREQ);
1882 val = (ep->msi_mem_phys & MSIX_ADDR_MATCH_LOW_OFF_MASK);
1883 val |= MSIX_ADDR_MATCH_LOW_OFF_EN;
1884 dw_pcie_writel_dbi(pci, MSIX_ADDR_MATCH_LOW_OFF, val);
1885 val = (upper_32_bits(ep->msi_mem_phys) & MSIX_ADDR_MATCH_HIGH_OFF_MASK);
1886 dw_pcie_writel_dbi(pci, MSIX_ADDR_MATCH_HIGH_OFF, val);
1888 ret = dw_pcie_ep_init_complete(ep);
1890 dev_err(dev, "Failed to complete initialization: %d\n", ret);
1891 goto fail_init_complete;
1894 dw_pcie_ep_init_notify(ep);
1896 /* Program the private control to allow sending LTR upstream */
1897 if (pcie->of_data->has_ltr_req_fix) {
1898 val = appl_readl(pcie, APPL_LTR_MSG_2);
1899 val |= APPL_LTR_MSG_2_LTR_MSG_REQ_STATE;
1900 appl_writel(pcie, val, APPL_LTR_MSG_2);
1904 val = appl_readl(pcie, APPL_CTRL);
1905 val |= APPL_CTRL_LTSSM_EN;
1906 appl_writel(pcie, val, APPL_CTRL);
1908 pcie->ep_state = EP_STATE_ENABLED;
1909 dev_dbg(dev, "Initialization of endpoint is completed\n");
1914 reset_control_assert(pcie->core_rst);
1915 tegra_pcie_disable_phy(pcie);
1917 reset_control_assert(pcie->core_apb_rst);
1919 clk_disable_unprepare(pcie->core_clk);
1920 fail_core_clk_enable:
1921 tegra_pcie_bpmp_set_pll_state(pcie, false);
1923 tegra_pcie_bpmp_set_ctrl_state(pcie, false);
1924 fail_set_ctrl_state:
1925 pm_runtime_put_sync(dev);
1928 static irqreturn_t tegra_pcie_ep_pex_rst_irq(int irq, void *arg)
1930 struct tegra_pcie_dw *pcie = arg;
1932 if (gpiod_get_value(pcie->pex_rst_gpiod))
1933 pex_ep_event_pex_rst_assert(pcie);
1935 pex_ep_event_pex_rst_deassert(pcie);
1940 static int tegra_pcie_ep_raise_legacy_irq(struct tegra_pcie_dw *pcie, u16 irq)
1942 /* Tegra194 supports only INTA */
1946 appl_writel(pcie, 1, APPL_LEGACY_INTX);
1947 usleep_range(1000, 2000);
1948 appl_writel(pcie, 0, APPL_LEGACY_INTX);
1952 static int tegra_pcie_ep_raise_msi_irq(struct tegra_pcie_dw *pcie, u16 irq)
1954 if (unlikely(irq > 31))
1957 appl_writel(pcie, BIT(irq), APPL_MSI_CTRL_1);
1962 static int tegra_pcie_ep_raise_msix_irq(struct tegra_pcie_dw *pcie, u16 irq)
1964 struct dw_pcie_ep *ep = &pcie->pci.ep;
1966 writel(irq, ep->msi_mem);
1971 static int tegra_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no,
1972 enum pci_epc_irq_type type,
1975 struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
1976 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci);
1979 case PCI_EPC_IRQ_LEGACY:
1980 return tegra_pcie_ep_raise_legacy_irq(pcie, interrupt_num);
1982 case PCI_EPC_IRQ_MSI:
1983 return tegra_pcie_ep_raise_msi_irq(pcie, interrupt_num);
1985 case PCI_EPC_IRQ_MSIX:
1986 return tegra_pcie_ep_raise_msix_irq(pcie, interrupt_num);
1989 dev_err(pci->dev, "Unknown IRQ type\n");
1996 static const struct pci_epc_features tegra_pcie_epc_features = {
1997 .linkup_notifier = true,
1998 .core_init_notifier = true,
1999 .msi_capable = false,
2000 .msix_capable = false,
2001 .reserved_bar = 1 << BAR_2 | 1 << BAR_3 | 1 << BAR_4 | 1 << BAR_5,
2002 .bar_fixed_64bit = 1 << BAR_0,
2003 .bar_fixed_size[0] = SZ_1M,
2006 static const struct pci_epc_features*
2007 tegra_pcie_ep_get_features(struct dw_pcie_ep *ep)
2009 return &tegra_pcie_epc_features;
2012 static const struct dw_pcie_ep_ops pcie_ep_ops = {
2013 .raise_irq = tegra_pcie_ep_raise_irq,
2014 .get_features = tegra_pcie_ep_get_features,
2017 static int tegra_pcie_config_ep(struct tegra_pcie_dw *pcie,
2018 struct platform_device *pdev)
2020 struct dw_pcie *pci = &pcie->pci;
2021 struct device *dev = pcie->dev;
2022 struct dw_pcie_ep *ep;
2027 ep->ops = &pcie_ep_ops;
2029 ep->page_size = SZ_64K;
2031 ret = gpiod_set_debounce(pcie->pex_rst_gpiod, PERST_DEBOUNCE_TIME);
2033 dev_err(dev, "Failed to set PERST GPIO debounce time: %d\n",
2038 ret = gpiod_to_irq(pcie->pex_rst_gpiod);
2040 dev_err(dev, "Failed to get IRQ for PERST GPIO: %d\n", ret);
2043 pcie->pex_rst_irq = (unsigned int)ret;
2045 name = devm_kasprintf(dev, GFP_KERNEL, "tegra_pcie_%u_pex_rst_irq",
2048 dev_err(dev, "Failed to create PERST IRQ string\n");
2052 irq_set_status_flags(pcie->pex_rst_irq, IRQ_NOAUTOEN);
2054 pcie->ep_state = EP_STATE_DISABLED;
2056 ret = devm_request_threaded_irq(dev, pcie->pex_rst_irq, NULL,
2057 tegra_pcie_ep_pex_rst_irq,
2058 IRQF_TRIGGER_RISING |
2059 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
2060 name, (void *)pcie);
2062 dev_err(dev, "Failed to request IRQ for PERST: %d\n", ret);
2066 pm_runtime_enable(dev);
2068 ret = dw_pcie_ep_init(ep);
2070 dev_err(dev, "Failed to initialize DWC Endpoint subsystem: %d\n",
2072 pm_runtime_disable(dev);
2079 static int tegra_pcie_dw_probe(struct platform_device *pdev)
2081 const struct tegra_pcie_dw_of_data *data;
2082 struct device *dev = &pdev->dev;
2083 struct resource *atu_dma_res;
2084 struct tegra_pcie_dw *pcie;
2085 struct dw_pcie_rp *pp;
2086 struct dw_pcie *pci;
2092 data = of_device_get_match_data(dev);
2094 pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL);
2099 pci->dev = &pdev->dev;
2100 pci->ops = &tegra_dw_pcie_ops;
2101 pcie->dev = &pdev->dev;
2102 pcie->of_data = (struct tegra_pcie_dw_of_data *)data;
2103 pci->n_fts[0] = pcie->of_data->n_fts[0];
2104 pci->n_fts[1] = pcie->of_data->n_fts[1];
2106 pp->num_vectors = MAX_MSI_IRQS;
2108 ret = tegra_pcie_dw_parse_dt(pcie);
2110 const char *level = KERN_ERR;
2112 if (ret == -EPROBE_DEFER)
2115 dev_printk(level, dev,
2116 dev_fmt("Failed to parse device tree: %d\n"),
2121 ret = tegra_pcie_get_slot_regulators(pcie);
2123 const char *level = KERN_ERR;
2125 if (ret == -EPROBE_DEFER)
2128 dev_printk(level, dev,
2129 dev_fmt("Failed to get slot regulators: %d\n"),
2134 if (pcie->pex_refclk_sel_gpiod)
2135 gpiod_set_value(pcie->pex_refclk_sel_gpiod, 1);
2137 pcie->pex_ctl_supply = devm_regulator_get(dev, "vddio-pex-ctl");
2138 if (IS_ERR(pcie->pex_ctl_supply)) {
2139 ret = PTR_ERR(pcie->pex_ctl_supply);
2140 if (ret != -EPROBE_DEFER)
2141 dev_err(dev, "Failed to get regulator: %ld\n",
2142 PTR_ERR(pcie->pex_ctl_supply));
2146 pcie->core_clk = devm_clk_get(dev, "core");
2147 if (IS_ERR(pcie->core_clk)) {
2148 dev_err(dev, "Failed to get core clock: %ld\n",
2149 PTR_ERR(pcie->core_clk));
2150 return PTR_ERR(pcie->core_clk);
2153 pcie->appl_res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
2155 if (!pcie->appl_res) {
2156 dev_err(dev, "Failed to find \"appl\" region\n");
2160 pcie->appl_base = devm_ioremap_resource(dev, pcie->appl_res);
2161 if (IS_ERR(pcie->appl_base))
2162 return PTR_ERR(pcie->appl_base);
2164 pcie->core_apb_rst = devm_reset_control_get(dev, "apb");
2165 if (IS_ERR(pcie->core_apb_rst)) {
2166 dev_err(dev, "Failed to get APB reset: %ld\n",
2167 PTR_ERR(pcie->core_apb_rst));
2168 return PTR_ERR(pcie->core_apb_rst);
2171 phys = devm_kcalloc(dev, pcie->phy_count, sizeof(*phys), GFP_KERNEL);
2175 for (i = 0; i < pcie->phy_count; i++) {
2176 name = kasprintf(GFP_KERNEL, "p2u-%u", i);
2178 dev_err(dev, "Failed to create P2U string\n");
2181 phys[i] = devm_phy_get(dev, name);
2183 if (IS_ERR(phys[i])) {
2184 ret = PTR_ERR(phys[i]);
2185 if (ret != -EPROBE_DEFER)
2186 dev_err(dev, "Failed to get PHY: %d\n", ret);
2193 atu_dma_res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
2196 dev_err(dev, "Failed to find \"atu_dma\" region\n");
2199 pcie->atu_dma_res = atu_dma_res;
2201 pci->atu_size = resource_size(atu_dma_res);
2202 pci->atu_base = devm_ioremap_resource(dev, atu_dma_res);
2203 if (IS_ERR(pci->atu_base))
2204 return PTR_ERR(pci->atu_base);
2206 pcie->core_rst = devm_reset_control_get(dev, "core");
2207 if (IS_ERR(pcie->core_rst)) {
2208 dev_err(dev, "Failed to get core reset: %ld\n",
2209 PTR_ERR(pcie->core_rst));
2210 return PTR_ERR(pcie->core_rst);
2213 pp->irq = platform_get_irq_byname(pdev, "intr");
2217 pcie->bpmp = tegra_bpmp_get(dev);
2218 if (IS_ERR(pcie->bpmp))
2219 return PTR_ERR(pcie->bpmp);
2221 platform_set_drvdata(pdev, pcie);
2223 switch (pcie->of_data->mode) {
2224 case DW_PCIE_RC_TYPE:
2225 ret = devm_request_irq(dev, pp->irq, tegra_pcie_rp_irq_handler,
2226 IRQF_SHARED, "tegra-pcie-intr", pcie);
2228 dev_err(dev, "Failed to request IRQ %d: %d\n", pp->irq,
2233 ret = tegra_pcie_config_rp(pcie);
2234 if (ret && ret != -ENOMEDIUM)
2240 case DW_PCIE_EP_TYPE:
2241 ret = devm_request_threaded_irq(dev, pp->irq,
2242 tegra_pcie_ep_hard_irq,
2243 tegra_pcie_ep_irq_thread,
2244 IRQF_SHARED | IRQF_ONESHOT,
2245 "tegra-pcie-ep-intr", pcie);
2247 dev_err(dev, "Failed to request IRQ %d: %d\n", pp->irq,
2252 ret = tegra_pcie_config_ep(pcie, pdev);
2258 dev_err(dev, "Invalid PCIe device type %d\n",
2259 pcie->of_data->mode);
2263 tegra_bpmp_put(pcie->bpmp);
2267 static int tegra_pcie_dw_remove(struct platform_device *pdev)
2269 struct tegra_pcie_dw *pcie = platform_get_drvdata(pdev);
2271 if (pcie->of_data->mode == DW_PCIE_RC_TYPE) {
2272 if (!pcie->link_state)
2275 debugfs_remove_recursive(pcie->debugfs);
2276 tegra_pcie_deinit_controller(pcie);
2277 pm_runtime_put_sync(pcie->dev);
2279 disable_irq(pcie->pex_rst_irq);
2280 pex_ep_event_pex_rst_assert(pcie);
2283 pm_runtime_disable(pcie->dev);
2284 tegra_bpmp_put(pcie->bpmp);
2285 if (pcie->pex_refclk_sel_gpiod)
2286 gpiod_set_value(pcie->pex_refclk_sel_gpiod, 0);
2291 static int tegra_pcie_dw_suspend_late(struct device *dev)
2293 struct tegra_pcie_dw *pcie = dev_get_drvdata(dev);
2296 if (pcie->of_data->mode == DW_PCIE_EP_TYPE) {
2297 dev_err(dev, "Failed to Suspend as Tegra PCIe is in EP mode\n");
2301 if (!pcie->link_state)
2304 /* Enable HW_HOT_RST mode */
2305 if (!pcie->of_data->has_sbr_reset_fix) {
2306 val = appl_readl(pcie, APPL_CTRL);
2307 val &= ~(APPL_CTRL_HW_HOT_RST_MODE_MASK <<
2308 APPL_CTRL_HW_HOT_RST_MODE_SHIFT);
2309 val |= APPL_CTRL_HW_HOT_RST_EN;
2310 appl_writel(pcie, val, APPL_CTRL);
2316 static int tegra_pcie_dw_suspend_noirq(struct device *dev)
2318 struct tegra_pcie_dw *pcie = dev_get_drvdata(dev);
2320 if (!pcie->link_state)
2323 tegra_pcie_downstream_dev_to_D0(pcie);
2324 tegra_pcie_dw_pme_turnoff(pcie);
2325 tegra_pcie_unconfig_controller(pcie);
2330 static int tegra_pcie_dw_resume_noirq(struct device *dev)
2332 struct tegra_pcie_dw *pcie = dev_get_drvdata(dev);
2335 if (!pcie->link_state)
2338 ret = tegra_pcie_config_controller(pcie, true);
2342 ret = tegra_pcie_dw_host_init(&pcie->pci.pp);
2344 dev_err(dev, "Failed to init host: %d\n", ret);
2345 goto fail_host_init;
2348 dw_pcie_setup_rc(&pcie->pci.pp);
2350 ret = tegra_pcie_dw_start_link(&pcie->pci);
2352 goto fail_host_init;
2357 tegra_pcie_unconfig_controller(pcie);
2361 static int tegra_pcie_dw_resume_early(struct device *dev)
2363 struct tegra_pcie_dw *pcie = dev_get_drvdata(dev);
2366 if (pcie->of_data->mode == DW_PCIE_EP_TYPE) {
2367 dev_err(dev, "Suspend is not supported in EP mode");
2371 if (!pcie->link_state)
2374 /* Disable HW_HOT_RST mode */
2375 if (!pcie->of_data->has_sbr_reset_fix) {
2376 val = appl_readl(pcie, APPL_CTRL);
2377 val &= ~(APPL_CTRL_HW_HOT_RST_MODE_MASK <<
2378 APPL_CTRL_HW_HOT_RST_MODE_SHIFT);
2379 val |= APPL_CTRL_HW_HOT_RST_MODE_IMDT_RST <<
2380 APPL_CTRL_HW_HOT_RST_MODE_SHIFT;
2381 val &= ~APPL_CTRL_HW_HOT_RST_EN;
2382 appl_writel(pcie, val, APPL_CTRL);
2388 static void tegra_pcie_dw_shutdown(struct platform_device *pdev)
2390 struct tegra_pcie_dw *pcie = platform_get_drvdata(pdev);
2392 if (pcie->of_data->mode == DW_PCIE_RC_TYPE) {
2393 if (!pcie->link_state)
2396 debugfs_remove_recursive(pcie->debugfs);
2397 tegra_pcie_downstream_dev_to_D0(pcie);
2399 disable_irq(pcie->pci.pp.irq);
2400 if (IS_ENABLED(CONFIG_PCI_MSI))
2401 disable_irq(pcie->pci.pp.msi_irq[0]);
2403 tegra_pcie_dw_pme_turnoff(pcie);
2404 tegra_pcie_unconfig_controller(pcie);
2405 pm_runtime_put_sync(pcie->dev);
2407 disable_irq(pcie->pex_rst_irq);
2408 pex_ep_event_pex_rst_assert(pcie);
2412 static const struct tegra_pcie_dw_of_data tegra194_pcie_dw_rc_of_data = {
2413 .version = TEGRA194_DWC_IP_VER,
2414 .mode = DW_PCIE_RC_TYPE,
2415 .cdm_chk_int_en_bit = BIT(19),
2416 /* Gen4 - 5, 6, 8 and 9 presets enabled */
2417 .gen4_preset_vec = 0x360,
2418 .n_fts = { 52, 52 },
2421 static const struct tegra_pcie_dw_of_data tegra194_pcie_dw_ep_of_data = {
2422 .version = TEGRA194_DWC_IP_VER,
2423 .mode = DW_PCIE_EP_TYPE,
2424 .cdm_chk_int_en_bit = BIT(19),
2425 /* Gen4 - 5, 6, 8 and 9 presets enabled */
2426 .gen4_preset_vec = 0x360,
2427 .n_fts = { 52, 52 },
2430 static const struct tegra_pcie_dw_of_data tegra234_pcie_dw_rc_of_data = {
2431 .version = TEGRA234_DWC_IP_VER,
2432 .mode = DW_PCIE_RC_TYPE,
2433 .has_msix_doorbell_access_fix = true,
2434 .has_sbr_reset_fix = true,
2435 .has_l1ss_exit_fix = true,
2436 .cdm_chk_int_en_bit = BIT(18),
2437 /* Gen4 - 6, 8 and 9 presets enabled */
2438 .gen4_preset_vec = 0x340,
2439 .n_fts = { 52, 80 },
2442 static const struct tegra_pcie_dw_of_data tegra234_pcie_dw_ep_of_data = {
2443 .version = TEGRA234_DWC_IP_VER,
2444 .mode = DW_PCIE_EP_TYPE,
2445 .has_l1ss_exit_fix = true,
2446 .has_ltr_req_fix = true,
2447 .cdm_chk_int_en_bit = BIT(18),
2448 /* Gen4 - 6, 8 and 9 presets enabled */
2449 .gen4_preset_vec = 0x340,
2450 .n_fts = { 52, 80 },
2453 static const struct of_device_id tegra_pcie_dw_of_match[] = {
2455 .compatible = "nvidia,tegra194-pcie",
2456 .data = &tegra194_pcie_dw_rc_of_data,
2459 .compatible = "nvidia,tegra194-pcie-ep",
2460 .data = &tegra194_pcie_dw_ep_of_data,
2463 .compatible = "nvidia,tegra234-pcie",
2464 .data = &tegra234_pcie_dw_rc_of_data,
2467 .compatible = "nvidia,tegra234-pcie-ep",
2468 .data = &tegra234_pcie_dw_ep_of_data,
2473 static const struct dev_pm_ops tegra_pcie_dw_pm_ops = {
2474 .suspend_late = tegra_pcie_dw_suspend_late,
2475 .suspend_noirq = tegra_pcie_dw_suspend_noirq,
2476 .resume_noirq = tegra_pcie_dw_resume_noirq,
2477 .resume_early = tegra_pcie_dw_resume_early,
2480 static struct platform_driver tegra_pcie_dw_driver = {
2481 .probe = tegra_pcie_dw_probe,
2482 .remove = tegra_pcie_dw_remove,
2483 .shutdown = tegra_pcie_dw_shutdown,
2485 .name = "tegra194-pcie",
2486 .pm = &tegra_pcie_dw_pm_ops,
2487 .of_match_table = tegra_pcie_dw_of_match,
2490 module_platform_driver(tegra_pcie_dw_driver);
2492 MODULE_DEVICE_TABLE(of, tegra_pcie_dw_of_match);
2495 MODULE_DESCRIPTION("NVIDIA PCIe host controller driver");
2496 MODULE_LICENSE("GPL v2");