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/bitfield.h>
13 #include <linux/clk.h>
14 #include <linux/debugfs.h>
15 #include <linux/delay.h>
16 #include <linux/gpio/consumer.h>
17 #include <linux/interconnect.h>
18 #include <linux/interrupt.h>
19 #include <linux/iopoll.h>
20 #include <linux/kernel.h>
21 #include <linux/module.h>
23 #include <linux/of_pci.h>
24 #include <linux/pci.h>
25 #include <linux/phy/phy.h>
26 #include <linux/pinctrl/consumer.h>
27 #include <linux/platform_device.h>
28 #include <linux/pm_runtime.h>
29 #include <linux/random.h>
30 #include <linux/reset.h>
31 #include <linux/resource.h>
32 #include <linux/types.h>
33 #include "pcie-designware.h"
34 #include <soc/tegra/bpmp.h>
35 #include <soc/tegra/bpmp-abi.h>
36 #include "../../pci.h"
38 #define TEGRA194_DWC_IP_VER 0x490A
39 #define TEGRA234_DWC_IP_VER 0x562A
41 #define APPL_PINMUX 0x0
42 #define APPL_PINMUX_PEX_RST BIT(0)
43 #define APPL_PINMUX_CLKREQ_OVERRIDE_EN BIT(2)
44 #define APPL_PINMUX_CLKREQ_OVERRIDE BIT(3)
45 #define APPL_PINMUX_CLK_OUTPUT_IN_OVERRIDE_EN BIT(4)
46 #define APPL_PINMUX_CLK_OUTPUT_IN_OVERRIDE BIT(5)
49 #define APPL_CTRL_SYS_PRE_DET_STATE BIT(6)
50 #define APPL_CTRL_LTSSM_EN BIT(7)
51 #define APPL_CTRL_HW_HOT_RST_EN BIT(20)
52 #define APPL_CTRL_HW_HOT_RST_MODE_MASK GENMASK(1, 0)
53 #define APPL_CTRL_HW_HOT_RST_MODE_SHIFT 22
54 #define APPL_CTRL_HW_HOT_RST_MODE_IMDT_RST 0x1
55 #define APPL_CTRL_HW_HOT_RST_MODE_IMDT_RST_LTSSM_EN 0x2
57 #define APPL_INTR_EN_L0_0 0x8
58 #define APPL_INTR_EN_L0_0_LINK_STATE_INT_EN BIT(0)
59 #define APPL_INTR_EN_L0_0_MSI_RCV_INT_EN BIT(4)
60 #define APPL_INTR_EN_L0_0_INT_INT_EN BIT(8)
61 #define APPL_INTR_EN_L0_0_PCI_CMD_EN_INT_EN BIT(15)
62 #define APPL_INTR_EN_L0_0_CDM_REG_CHK_INT_EN BIT(19)
63 #define APPL_INTR_EN_L0_0_SYS_INTR_EN BIT(30)
64 #define APPL_INTR_EN_L0_0_SYS_MSI_INTR_EN BIT(31)
66 #define APPL_INTR_STATUS_L0 0xC
67 #define APPL_INTR_STATUS_L0_LINK_STATE_INT BIT(0)
68 #define APPL_INTR_STATUS_L0_INT_INT BIT(8)
69 #define APPL_INTR_STATUS_L0_PCI_CMD_EN_INT BIT(15)
70 #define APPL_INTR_STATUS_L0_PEX_RST_INT BIT(16)
71 #define APPL_INTR_STATUS_L0_CDM_REG_CHK_INT BIT(18)
73 #define APPL_INTR_EN_L1_0_0 0x1C
74 #define APPL_INTR_EN_L1_0_0_LINK_REQ_RST_NOT_INT_EN BIT(1)
75 #define APPL_INTR_EN_L1_0_0_RDLH_LINK_UP_INT_EN BIT(3)
76 #define APPL_INTR_EN_L1_0_0_HOT_RESET_DONE_INT_EN BIT(30)
78 #define APPL_INTR_STATUS_L1_0_0 0x20
79 #define APPL_INTR_STATUS_L1_0_0_LINK_REQ_RST_NOT_CHGED BIT(1)
80 #define APPL_INTR_STATUS_L1_0_0_RDLH_LINK_UP_CHGED BIT(3)
81 #define APPL_INTR_STATUS_L1_0_0_HOT_RESET_DONE BIT(30)
83 #define APPL_INTR_STATUS_L1_1 0x2C
84 #define APPL_INTR_STATUS_L1_2 0x30
85 #define APPL_INTR_STATUS_L1_3 0x34
86 #define APPL_INTR_STATUS_L1_6 0x3C
87 #define APPL_INTR_STATUS_L1_7 0x40
88 #define APPL_INTR_STATUS_L1_15_CFG_BME_CHGED BIT(1)
90 #define APPL_INTR_EN_L1_8_0 0x44
91 #define APPL_INTR_EN_L1_8_BW_MGT_INT_EN BIT(2)
92 #define APPL_INTR_EN_L1_8_AUTO_BW_INT_EN BIT(3)
93 #define APPL_INTR_EN_L1_8_INTX_EN BIT(11)
94 #define APPL_INTR_EN_L1_8_AER_INT_EN BIT(15)
96 #define APPL_INTR_STATUS_L1_8_0 0x4C
97 #define APPL_INTR_STATUS_L1_8_0_EDMA_INT_MASK GENMASK(11, 6)
98 #define APPL_INTR_STATUS_L1_8_0_BW_MGT_INT_STS BIT(2)
99 #define APPL_INTR_STATUS_L1_8_0_AUTO_BW_INT_STS BIT(3)
101 #define APPL_INTR_STATUS_L1_9 0x54
102 #define APPL_INTR_STATUS_L1_10 0x58
103 #define APPL_INTR_STATUS_L1_11 0x64
104 #define APPL_INTR_STATUS_L1_13 0x74
105 #define APPL_INTR_STATUS_L1_14 0x78
106 #define APPL_INTR_STATUS_L1_15 0x7C
107 #define APPL_INTR_STATUS_L1_17 0x88
109 #define APPL_INTR_EN_L1_18 0x90
110 #define APPL_INTR_EN_L1_18_CDM_REG_CHK_CMPLT BIT(2)
111 #define APPL_INTR_EN_L1_18_CDM_REG_CHK_CMP_ERR BIT(1)
112 #define APPL_INTR_EN_L1_18_CDM_REG_CHK_LOGIC_ERR BIT(0)
114 #define APPL_INTR_STATUS_L1_18 0x94
115 #define APPL_INTR_STATUS_L1_18_CDM_REG_CHK_CMPLT BIT(2)
116 #define APPL_INTR_STATUS_L1_18_CDM_REG_CHK_CMP_ERR BIT(1)
117 #define APPL_INTR_STATUS_L1_18_CDM_REG_CHK_LOGIC_ERR BIT(0)
119 #define APPL_MSI_CTRL_1 0xAC
121 #define APPL_MSI_CTRL_2 0xB0
123 #define APPL_LEGACY_INTX 0xB8
125 #define APPL_LTR_MSG_1 0xC4
126 #define LTR_MSG_REQ BIT(15)
127 #define LTR_NOSNOOP_MSG_REQ BIT(31)
129 #define APPL_LTR_MSG_2 0xC8
130 #define APPL_LTR_MSG_2_LTR_MSG_REQ_STATE BIT(3)
132 #define APPL_LINK_STATUS 0xCC
133 #define APPL_LINK_STATUS_RDLH_LINK_UP BIT(0)
135 #define APPL_DEBUG 0xD0
136 #define APPL_DEBUG_PM_LINKST_IN_L2_LAT BIT(21)
137 #define APPL_DEBUG_PM_LINKST_IN_L0 0x11
138 #define APPL_DEBUG_LTSSM_STATE_MASK GENMASK(8, 3)
139 #define APPL_DEBUG_LTSSM_STATE_SHIFT 3
140 #define LTSSM_STATE_PRE_DETECT 5
142 #define APPL_RADM_STATUS 0xE4
143 #define APPL_PM_XMT_TURNOFF_STATE BIT(0)
145 #define APPL_DM_TYPE 0x100
146 #define APPL_DM_TYPE_MASK GENMASK(3, 0)
147 #define APPL_DM_TYPE_RP 0x4
148 #define APPL_DM_TYPE_EP 0x0
150 #define APPL_CFG_BASE_ADDR 0x104
151 #define APPL_CFG_BASE_ADDR_MASK GENMASK(31, 12)
153 #define APPL_CFG_IATU_DMA_BASE_ADDR 0x108
154 #define APPL_CFG_IATU_DMA_BASE_ADDR_MASK GENMASK(31, 18)
156 #define APPL_CFG_MISC 0x110
157 #define APPL_CFG_MISC_SLV_EP_MODE BIT(14)
158 #define APPL_CFG_MISC_ARCACHE_MASK GENMASK(13, 10)
159 #define APPL_CFG_MISC_ARCACHE_SHIFT 10
160 #define APPL_CFG_MISC_ARCACHE_VAL 3
162 #define APPL_CFG_SLCG_OVERRIDE 0x114
163 #define APPL_CFG_SLCG_OVERRIDE_SLCG_EN_MASTER BIT(0)
165 #define APPL_CAR_RESET_OVRD 0x12C
166 #define APPL_CAR_RESET_OVRD_CYA_OVERRIDE_CORE_RST_N BIT(0)
168 #define IO_BASE_IO_DECODE BIT(0)
169 #define IO_BASE_IO_DECODE_BIT8 BIT(8)
171 #define CFG_PREF_MEM_LIMIT_BASE_MEM_DECODE BIT(0)
172 #define CFG_PREF_MEM_LIMIT_BASE_MEM_LIMIT_DECODE BIT(16)
174 #define CFG_TIMER_CTRL_MAX_FUNC_NUM_OFF 0x718
175 #define CFG_TIMER_CTRL_ACK_NAK_SHIFT (19)
180 #define GEN3_EQ_CONTROL_OFF 0x8a8
181 #define GEN3_EQ_CONTROL_OFF_PSET_REQ_VEC_SHIFT 8
182 #define GEN3_EQ_CONTROL_OFF_PSET_REQ_VEC_MASK GENMASK(23, 8)
183 #define GEN3_EQ_CONTROL_OFF_FB_MODE_MASK GENMASK(3, 0)
185 #define PORT_LOGIC_AMBA_ERROR_RESPONSE_DEFAULT 0x8D0
186 #define AMBA_ERROR_RESPONSE_CRS_SHIFT 3
187 #define AMBA_ERROR_RESPONSE_CRS_MASK GENMASK(1, 0)
188 #define AMBA_ERROR_RESPONSE_CRS_OKAY 0
189 #define AMBA_ERROR_RESPONSE_CRS_OKAY_FFFFFFFF 1
190 #define AMBA_ERROR_RESPONSE_CRS_OKAY_FFFF0001 2
192 #define MSIX_ADDR_MATCH_LOW_OFF 0x940
193 #define MSIX_ADDR_MATCH_LOW_OFF_EN BIT(0)
194 #define MSIX_ADDR_MATCH_LOW_OFF_MASK GENMASK(31, 2)
196 #define MSIX_ADDR_MATCH_HIGH_OFF 0x944
197 #define MSIX_ADDR_MATCH_HIGH_OFF_MASK GENMASK(31, 0)
199 #define PORT_LOGIC_MSIX_DOORBELL 0x948
201 #define CAP_SPCIE_CAP_OFF 0x154
202 #define CAP_SPCIE_CAP_OFF_DSP_TX_PRESET0_MASK GENMASK(3, 0)
203 #define CAP_SPCIE_CAP_OFF_USP_TX_PRESET0_MASK GENMASK(11, 8)
204 #define CAP_SPCIE_CAP_OFF_USP_TX_PRESET0_SHIFT 8
206 #define PME_ACK_TIMEOUT 10000
208 #define LTSSM_TIMEOUT 50000 /* 50ms */
210 #define GEN3_GEN4_EQ_PRESET_INIT 5
212 #define GEN1_CORE_CLK_FREQ 62500000
213 #define GEN2_CORE_CLK_FREQ 125000000
214 #define GEN3_CORE_CLK_FREQ 250000000
215 #define GEN4_CORE_CLK_FREQ 500000000
217 #define LTR_MSG_TIMEOUT (100 * 1000)
219 #define PERST_DEBOUNCE_TIME (5 * 1000)
221 #define EP_STATE_DISABLED 0
222 #define EP_STATE_ENABLED 1
224 static const unsigned int pcie_gen_freq[] = {
225 GEN1_CORE_CLK_FREQ, /* PCI_EXP_LNKSTA_CLS == 0; undefined */
232 struct tegra_pcie_dw_of_data {
234 enum dw_pcie_device_mode mode;
235 bool has_msix_doorbell_access_fix;
236 bool has_sbr_reset_fix;
237 bool has_l1ss_exit_fix;
238 bool has_ltr_req_fix;
239 u32 cdm_chk_int_en_bit;
244 struct tegra_pcie_dw {
246 struct resource *appl_res;
247 struct resource *dbi_res;
248 struct resource *atu_dma_res;
249 void __iomem *appl_base;
250 struct clk *core_clk;
251 struct reset_control *core_apb_rst;
252 struct reset_control *core_rst;
254 struct tegra_bpmp *bpmp;
256 struct tegra_pcie_dw_of_data *of_data;
258 bool supports_clkreq;
259 bool enable_cdm_check;
262 bool update_fc_fixup;
263 bool enable_ext_refclk;
268 u32 cfg_link_cap_l1sub;
273 u32 aspm_l0s_enter_lat;
275 struct regulator *pex_ctl_supply;
276 struct regulator *slot_ctl_3v3;
277 struct regulator *slot_ctl_12v;
279 unsigned int phy_count;
282 struct dentry *debugfs;
284 /* Endpoint mode specific */
285 struct gpio_desc *pex_rst_gpiod;
286 struct gpio_desc *pex_refclk_sel_gpiod;
287 unsigned int pex_rst_irq;
290 struct icc_path *icc_path;
293 static inline struct tegra_pcie_dw *to_tegra_pcie(struct dw_pcie *pci)
295 return container_of(pci, struct tegra_pcie_dw, pci);
298 static inline void appl_writel(struct tegra_pcie_dw *pcie, const u32 value,
301 writel_relaxed(value, pcie->appl_base + reg);
304 static inline u32 appl_readl(struct tegra_pcie_dw *pcie, const u32 reg)
306 return readl_relaxed(pcie->appl_base + reg);
309 static void tegra_pcie_icc_set(struct tegra_pcie_dw *pcie)
311 struct dw_pcie *pci = &pcie->pci;
312 u32 val, speed, width;
314 val = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKSTA);
316 speed = FIELD_GET(PCI_EXP_LNKSTA_CLS, val);
317 width = FIELD_GET(PCI_EXP_LNKSTA_NLW, val);
319 val = width * PCIE_SPEED2MBS_ENC(pcie_link_speed[speed]);
321 if (icc_set_bw(pcie->icc_path, Mbps_to_icc(val), 0))
322 dev_err(pcie->dev, "can't set bw[%u]\n", val);
324 if (speed >= ARRAY_SIZE(pcie_gen_freq))
327 clk_set_rate(pcie->core_clk, pcie_gen_freq[speed]);
330 static void apply_bad_link_workaround(struct dw_pcie_rp *pp)
332 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
333 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci);
334 u32 current_link_width;
338 * NOTE:- Since this scenario is uncommon and link as such is not
339 * stable anyway, not waiting to confirm if link is really
340 * transitioning to Gen-2 speed
342 val = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKSTA);
343 if (val & PCI_EXP_LNKSTA_LBMS) {
344 current_link_width = FIELD_GET(PCI_EXP_LNKSTA_NLW, val);
345 if (pcie->init_link_width > current_link_width) {
346 dev_warn(pci->dev, "PCIe link is bad, width reduced\n");
347 val = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base +
349 val &= ~PCI_EXP_LNKCTL2_TLS;
350 val |= PCI_EXP_LNKCTL2_TLS_2_5GT;
351 dw_pcie_writew_dbi(pci, pcie->pcie_cap_base +
352 PCI_EXP_LNKCTL2, val);
354 val = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base +
356 val |= PCI_EXP_LNKCTL_RL;
357 dw_pcie_writew_dbi(pci, pcie->pcie_cap_base +
358 PCI_EXP_LNKCTL, val);
363 static irqreturn_t tegra_pcie_rp_irq_handler(int irq, void *arg)
365 struct tegra_pcie_dw *pcie = arg;
366 struct dw_pcie *pci = &pcie->pci;
367 struct dw_pcie_rp *pp = &pci->pp;
368 u32 val, status_l0, status_l1;
371 status_l0 = appl_readl(pcie, APPL_INTR_STATUS_L0);
372 if (status_l0 & APPL_INTR_STATUS_L0_LINK_STATE_INT) {
373 status_l1 = appl_readl(pcie, APPL_INTR_STATUS_L1_0_0);
374 appl_writel(pcie, status_l1, APPL_INTR_STATUS_L1_0_0);
375 if (!pcie->of_data->has_sbr_reset_fix &&
376 status_l1 & APPL_INTR_STATUS_L1_0_0_LINK_REQ_RST_NOT_CHGED) {
377 /* SBR & Surprise Link Down WAR */
378 val = appl_readl(pcie, APPL_CAR_RESET_OVRD);
379 val &= ~APPL_CAR_RESET_OVRD_CYA_OVERRIDE_CORE_RST_N;
380 appl_writel(pcie, val, APPL_CAR_RESET_OVRD);
382 val = appl_readl(pcie, APPL_CAR_RESET_OVRD);
383 val |= APPL_CAR_RESET_OVRD_CYA_OVERRIDE_CORE_RST_N;
384 appl_writel(pcie, val, APPL_CAR_RESET_OVRD);
386 val = dw_pcie_readl_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL);
387 val |= PORT_LOGIC_SPEED_CHANGE;
388 dw_pcie_writel_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL, val);
392 if (status_l0 & APPL_INTR_STATUS_L0_INT_INT) {
393 status_l1 = appl_readl(pcie, APPL_INTR_STATUS_L1_8_0);
394 if (status_l1 & APPL_INTR_STATUS_L1_8_0_AUTO_BW_INT_STS) {
396 APPL_INTR_STATUS_L1_8_0_AUTO_BW_INT_STS,
397 APPL_INTR_STATUS_L1_8_0);
398 apply_bad_link_workaround(pp);
400 if (status_l1 & APPL_INTR_STATUS_L1_8_0_BW_MGT_INT_STS) {
401 val_w = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base +
403 val_w |= PCI_EXP_LNKSTA_LBMS;
404 dw_pcie_writew_dbi(pci, pcie->pcie_cap_base +
405 PCI_EXP_LNKSTA, val_w);
408 APPL_INTR_STATUS_L1_8_0_BW_MGT_INT_STS,
409 APPL_INTR_STATUS_L1_8_0);
411 val_w = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base +
413 dev_dbg(pci->dev, "Link Speed : Gen-%u\n", val_w &
418 if (status_l0 & APPL_INTR_STATUS_L0_CDM_REG_CHK_INT) {
419 status_l1 = appl_readl(pcie, APPL_INTR_STATUS_L1_18);
420 val = dw_pcie_readl_dbi(pci, PCIE_PL_CHK_REG_CONTROL_STATUS);
421 if (status_l1 & APPL_INTR_STATUS_L1_18_CDM_REG_CHK_CMPLT) {
422 dev_info(pci->dev, "CDM check complete\n");
423 val |= PCIE_PL_CHK_REG_CHK_REG_COMPLETE;
425 if (status_l1 & APPL_INTR_STATUS_L1_18_CDM_REG_CHK_CMP_ERR) {
426 dev_err(pci->dev, "CDM comparison mismatch\n");
427 val |= PCIE_PL_CHK_REG_CHK_REG_COMPARISON_ERROR;
429 if (status_l1 & APPL_INTR_STATUS_L1_18_CDM_REG_CHK_LOGIC_ERR) {
430 dev_err(pci->dev, "CDM Logic error\n");
431 val |= PCIE_PL_CHK_REG_CHK_REG_LOGIC_ERROR;
433 dw_pcie_writel_dbi(pci, PCIE_PL_CHK_REG_CONTROL_STATUS, val);
434 val = dw_pcie_readl_dbi(pci, PCIE_PL_CHK_REG_ERR_ADDR);
435 dev_err(pci->dev, "CDM Error Address Offset = 0x%08X\n", val);
441 static void pex_ep_event_hot_rst_done(struct tegra_pcie_dw *pcie)
445 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L0);
446 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_0_0);
447 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_1);
448 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_2);
449 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_3);
450 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_6);
451 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_7);
452 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_8_0);
453 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_9);
454 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_10);
455 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_11);
456 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_13);
457 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_14);
458 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_15);
459 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_17);
460 appl_writel(pcie, 0xFFFFFFFF, APPL_MSI_CTRL_2);
462 val = appl_readl(pcie, APPL_CTRL);
463 val |= APPL_CTRL_LTSSM_EN;
464 appl_writel(pcie, val, APPL_CTRL);
467 static irqreturn_t tegra_pcie_ep_irq_thread(int irq, void *arg)
469 struct tegra_pcie_dw *pcie = arg;
470 struct dw_pcie_ep *ep = &pcie->pci.ep;
471 struct dw_pcie *pci = &pcie->pci;
474 if (test_and_clear_bit(0, &pcie->link_status))
475 dw_pcie_ep_linkup(ep);
477 tegra_pcie_icc_set(pcie);
479 if (pcie->of_data->has_ltr_req_fix)
482 /* If EP doesn't advertise L1SS, just return */
483 val = dw_pcie_readl_dbi(pci, pcie->cfg_link_cap_l1sub);
484 if (!(val & (PCI_L1SS_CAP_ASPM_L1_1 | PCI_L1SS_CAP_ASPM_L1_2)))
487 /* Check if BME is set to '1' */
488 val = dw_pcie_readl_dbi(pci, PCI_COMMAND);
489 if (val & PCI_COMMAND_MASTER) {
492 /* 110us for both snoop and no-snoop */
493 val = FIELD_PREP(PCI_LTR_VALUE_MASK, 110) |
494 FIELD_PREP(PCI_LTR_SCALE_MASK, 2) |
496 FIELD_PREP(PCI_LTR_NOSNOOP_VALUE, 110) |
497 FIELD_PREP(PCI_LTR_NOSNOOP_SCALE, 2) |
499 appl_writel(pcie, val, APPL_LTR_MSG_1);
501 /* Send LTR upstream */
502 val = appl_readl(pcie, APPL_LTR_MSG_2);
503 val |= APPL_LTR_MSG_2_LTR_MSG_REQ_STATE;
504 appl_writel(pcie, val, APPL_LTR_MSG_2);
506 timeout = ktime_add_us(ktime_get(), LTR_MSG_TIMEOUT);
508 val = appl_readl(pcie, APPL_LTR_MSG_2);
509 if (!(val & APPL_LTR_MSG_2_LTR_MSG_REQ_STATE))
511 if (ktime_after(ktime_get(), timeout))
513 usleep_range(1000, 1100);
515 if (val & APPL_LTR_MSG_2_LTR_MSG_REQ_STATE)
516 dev_err(pcie->dev, "Failed to send LTR message\n");
522 static irqreturn_t tegra_pcie_ep_hard_irq(int irq, void *arg)
524 struct tegra_pcie_dw *pcie = arg;
526 u32 status_l0, status_l1, link_status;
528 status_l0 = appl_readl(pcie, APPL_INTR_STATUS_L0);
529 if (status_l0 & APPL_INTR_STATUS_L0_LINK_STATE_INT) {
530 status_l1 = appl_readl(pcie, APPL_INTR_STATUS_L1_0_0);
531 appl_writel(pcie, status_l1, APPL_INTR_STATUS_L1_0_0);
533 if (status_l1 & APPL_INTR_STATUS_L1_0_0_HOT_RESET_DONE)
534 pex_ep_event_hot_rst_done(pcie);
536 if (status_l1 & APPL_INTR_STATUS_L1_0_0_RDLH_LINK_UP_CHGED) {
537 link_status = appl_readl(pcie, APPL_LINK_STATUS);
538 if (link_status & APPL_LINK_STATUS_RDLH_LINK_UP) {
539 dev_dbg(pcie->dev, "Link is up with Host\n");
540 set_bit(0, &pcie->link_status);
541 return IRQ_WAKE_THREAD;
548 if (status_l0 & APPL_INTR_STATUS_L0_PCI_CMD_EN_INT) {
549 status_l1 = appl_readl(pcie, APPL_INTR_STATUS_L1_15);
550 appl_writel(pcie, status_l1, APPL_INTR_STATUS_L1_15);
552 if (status_l1 & APPL_INTR_STATUS_L1_15_CFG_BME_CHGED)
553 return IRQ_WAKE_THREAD;
559 dev_warn(pcie->dev, "Random interrupt (STATUS = 0x%08X)\n",
561 appl_writel(pcie, status_l0, APPL_INTR_STATUS_L0);
567 static int tegra_pcie_dw_rd_own_conf(struct pci_bus *bus, u32 devfn, int where,
570 struct dw_pcie_rp *pp = bus->sysdata;
571 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
572 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci);
575 * This is an endpoint mode specific register happen to appear even
576 * when controller is operating in root port mode and system hangs
577 * when it is accessed with link being in ASPM-L1 state.
578 * So skip accessing it altogether
580 if (!pcie->of_data->has_msix_doorbell_access_fix &&
581 !PCI_SLOT(devfn) && where == PORT_LOGIC_MSIX_DOORBELL) {
583 return PCIBIOS_SUCCESSFUL;
586 return pci_generic_config_read(bus, devfn, where, size, val);
589 static int tegra_pcie_dw_wr_own_conf(struct pci_bus *bus, u32 devfn, int where,
592 struct dw_pcie_rp *pp = bus->sysdata;
593 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
594 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci);
597 * This is an endpoint mode specific register happen to appear even
598 * when controller is operating in root port mode and system hangs
599 * when it is accessed with link being in ASPM-L1 state.
600 * So skip accessing it altogether
602 if (!pcie->of_data->has_msix_doorbell_access_fix &&
603 !PCI_SLOT(devfn) && where == PORT_LOGIC_MSIX_DOORBELL)
604 return PCIBIOS_SUCCESSFUL;
606 return pci_generic_config_write(bus, devfn, where, size, val);
609 static struct pci_ops tegra_pci_ops = {
610 .map_bus = dw_pcie_own_conf_map_bus,
611 .read = tegra_pcie_dw_rd_own_conf,
612 .write = tegra_pcie_dw_wr_own_conf,
615 #if defined(CONFIG_PCIEASPM)
616 static void disable_aspm_l11(struct tegra_pcie_dw *pcie)
620 val = dw_pcie_readl_dbi(&pcie->pci, pcie->cfg_link_cap_l1sub);
621 val &= ~PCI_L1SS_CAP_ASPM_L1_1;
622 dw_pcie_writel_dbi(&pcie->pci, pcie->cfg_link_cap_l1sub, val);
625 static void disable_aspm_l12(struct tegra_pcie_dw *pcie)
629 val = dw_pcie_readl_dbi(&pcie->pci, pcie->cfg_link_cap_l1sub);
630 val &= ~PCI_L1SS_CAP_ASPM_L1_2;
631 dw_pcie_writel_dbi(&pcie->pci, pcie->cfg_link_cap_l1sub, val);
634 static inline u32 event_counter_prog(struct tegra_pcie_dw *pcie, u32 event)
638 val = dw_pcie_readl_dbi(&pcie->pci, pcie->ras_des_cap +
639 PCIE_RAS_DES_EVENT_COUNTER_CONTROL);
640 val &= ~(EVENT_COUNTER_EVENT_SEL_MASK << EVENT_COUNTER_EVENT_SEL_SHIFT);
641 val |= EVENT_COUNTER_GROUP_5 << EVENT_COUNTER_GROUP_SEL_SHIFT;
642 val |= event << EVENT_COUNTER_EVENT_SEL_SHIFT;
643 val |= EVENT_COUNTER_ENABLE_ALL << EVENT_COUNTER_ENABLE_SHIFT;
644 dw_pcie_writel_dbi(&pcie->pci, pcie->ras_des_cap +
645 PCIE_RAS_DES_EVENT_COUNTER_CONTROL, val);
646 val = dw_pcie_readl_dbi(&pcie->pci, pcie->ras_des_cap +
647 PCIE_RAS_DES_EVENT_COUNTER_DATA);
652 static int aspm_state_cnt(struct seq_file *s, void *data)
654 struct tegra_pcie_dw *pcie = (struct tegra_pcie_dw *)
655 dev_get_drvdata(s->private);
658 seq_printf(s, "Tx L0s entry count : %u\n",
659 event_counter_prog(pcie, EVENT_COUNTER_EVENT_Tx_L0S));
661 seq_printf(s, "Rx L0s entry count : %u\n",
662 event_counter_prog(pcie, EVENT_COUNTER_EVENT_Rx_L0S));
664 seq_printf(s, "Link L1 entry count : %u\n",
665 event_counter_prog(pcie, EVENT_COUNTER_EVENT_L1));
667 seq_printf(s, "Link L1.1 entry count : %u\n",
668 event_counter_prog(pcie, EVENT_COUNTER_EVENT_L1_1));
670 seq_printf(s, "Link L1.2 entry count : %u\n",
671 event_counter_prog(pcie, EVENT_COUNTER_EVENT_L1_2));
673 /* Clear all counters */
674 dw_pcie_writel_dbi(&pcie->pci, pcie->ras_des_cap +
675 PCIE_RAS_DES_EVENT_COUNTER_CONTROL,
676 EVENT_COUNTER_ALL_CLEAR);
678 /* Re-enable counting */
679 val = EVENT_COUNTER_ENABLE_ALL << EVENT_COUNTER_ENABLE_SHIFT;
680 val |= EVENT_COUNTER_GROUP_5 << EVENT_COUNTER_GROUP_SEL_SHIFT;
681 dw_pcie_writel_dbi(&pcie->pci, pcie->ras_des_cap +
682 PCIE_RAS_DES_EVENT_COUNTER_CONTROL, val);
687 static void init_host_aspm(struct tegra_pcie_dw *pcie)
689 struct dw_pcie *pci = &pcie->pci;
692 val = dw_pcie_find_ext_capability(pci, PCI_EXT_CAP_ID_L1SS);
693 pcie->cfg_link_cap_l1sub = val + PCI_L1SS_CAP;
695 pcie->ras_des_cap = dw_pcie_find_ext_capability(&pcie->pci,
696 PCI_EXT_CAP_ID_VNDR);
698 /* Enable ASPM counters */
699 val = EVENT_COUNTER_ENABLE_ALL << EVENT_COUNTER_ENABLE_SHIFT;
700 val |= EVENT_COUNTER_GROUP_5 << EVENT_COUNTER_GROUP_SEL_SHIFT;
701 dw_pcie_writel_dbi(pci, pcie->ras_des_cap +
702 PCIE_RAS_DES_EVENT_COUNTER_CONTROL, val);
704 /* Program T_cmrt and T_pwr_on values */
705 val = dw_pcie_readl_dbi(pci, pcie->cfg_link_cap_l1sub);
706 val &= ~(PCI_L1SS_CAP_CM_RESTORE_TIME | PCI_L1SS_CAP_P_PWR_ON_VALUE);
707 val |= (pcie->aspm_cmrt << 8);
708 val |= (pcie->aspm_pwr_on_t << 19);
709 dw_pcie_writel_dbi(pci, pcie->cfg_link_cap_l1sub, val);
711 /* Program L0s and L1 entrance latencies */
712 val = dw_pcie_readl_dbi(pci, PCIE_PORT_AFR);
713 val &= ~PORT_AFR_L0S_ENTRANCE_LAT_MASK;
714 val |= (pcie->aspm_l0s_enter_lat << PORT_AFR_L0S_ENTRANCE_LAT_SHIFT);
715 val |= PORT_AFR_ENTER_ASPM;
716 dw_pcie_writel_dbi(pci, PCIE_PORT_AFR, val);
719 static void init_debugfs(struct tegra_pcie_dw *pcie)
721 debugfs_create_devm_seqfile(pcie->dev, "aspm_state_cnt", pcie->debugfs,
725 static inline void disable_aspm_l12(struct tegra_pcie_dw *pcie) { return; }
726 static inline void disable_aspm_l11(struct tegra_pcie_dw *pcie) { return; }
727 static inline void init_host_aspm(struct tegra_pcie_dw *pcie) { return; }
728 static inline void init_debugfs(struct tegra_pcie_dw *pcie) { return; }
731 static void tegra_pcie_enable_system_interrupts(struct dw_pcie_rp *pp)
733 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
734 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci);
738 val = appl_readl(pcie, APPL_INTR_EN_L0_0);
739 val |= APPL_INTR_EN_L0_0_LINK_STATE_INT_EN;
740 appl_writel(pcie, val, APPL_INTR_EN_L0_0);
742 if (!pcie->of_data->has_sbr_reset_fix) {
743 val = appl_readl(pcie, APPL_INTR_EN_L1_0_0);
744 val |= APPL_INTR_EN_L1_0_0_LINK_REQ_RST_NOT_INT_EN;
745 appl_writel(pcie, val, APPL_INTR_EN_L1_0_0);
748 if (pcie->enable_cdm_check) {
749 val = appl_readl(pcie, APPL_INTR_EN_L0_0);
750 val |= pcie->of_data->cdm_chk_int_en_bit;
751 appl_writel(pcie, val, APPL_INTR_EN_L0_0);
753 val = appl_readl(pcie, APPL_INTR_EN_L1_18);
754 val |= APPL_INTR_EN_L1_18_CDM_REG_CHK_CMP_ERR;
755 val |= APPL_INTR_EN_L1_18_CDM_REG_CHK_LOGIC_ERR;
756 appl_writel(pcie, val, APPL_INTR_EN_L1_18);
759 val_w = dw_pcie_readw_dbi(&pcie->pci, pcie->pcie_cap_base +
761 pcie->init_link_width = FIELD_GET(PCI_EXP_LNKSTA_NLW, val_w);
763 val_w = dw_pcie_readw_dbi(&pcie->pci, pcie->pcie_cap_base +
765 val_w |= PCI_EXP_LNKCTL_LBMIE;
766 dw_pcie_writew_dbi(&pcie->pci, pcie->pcie_cap_base + PCI_EXP_LNKCTL,
770 static void tegra_pcie_enable_intx_interrupts(struct dw_pcie_rp *pp)
772 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
773 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci);
776 /* Enable INTX interrupt generation */
777 val = appl_readl(pcie, APPL_INTR_EN_L0_0);
778 val |= APPL_INTR_EN_L0_0_SYS_INTR_EN;
779 val |= APPL_INTR_EN_L0_0_INT_INT_EN;
780 appl_writel(pcie, val, APPL_INTR_EN_L0_0);
782 val = appl_readl(pcie, APPL_INTR_EN_L1_8_0);
783 val |= APPL_INTR_EN_L1_8_INTX_EN;
784 val |= APPL_INTR_EN_L1_8_AUTO_BW_INT_EN;
785 val |= APPL_INTR_EN_L1_8_BW_MGT_INT_EN;
786 if (IS_ENABLED(CONFIG_PCIEAER))
787 val |= APPL_INTR_EN_L1_8_AER_INT_EN;
788 appl_writel(pcie, val, APPL_INTR_EN_L1_8_0);
791 static void tegra_pcie_enable_msi_interrupts(struct dw_pcie_rp *pp)
793 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
794 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci);
797 /* Enable MSI interrupt generation */
798 val = appl_readl(pcie, APPL_INTR_EN_L0_0);
799 val |= APPL_INTR_EN_L0_0_SYS_MSI_INTR_EN;
800 val |= APPL_INTR_EN_L0_0_MSI_RCV_INT_EN;
801 appl_writel(pcie, val, APPL_INTR_EN_L0_0);
804 static void tegra_pcie_enable_interrupts(struct dw_pcie_rp *pp)
806 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
807 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci);
809 /* Clear interrupt statuses before enabling interrupts */
810 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L0);
811 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_0_0);
812 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_1);
813 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_2);
814 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_3);
815 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_6);
816 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_7);
817 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_8_0);
818 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_9);
819 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_10);
820 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_11);
821 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_13);
822 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_14);
823 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_15);
824 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_17);
826 tegra_pcie_enable_system_interrupts(pp);
827 tegra_pcie_enable_intx_interrupts(pp);
828 if (IS_ENABLED(CONFIG_PCI_MSI))
829 tegra_pcie_enable_msi_interrupts(pp);
832 static void config_gen3_gen4_eq_presets(struct tegra_pcie_dw *pcie)
834 struct dw_pcie *pci = &pcie->pci;
837 /* Program init preset */
838 for (i = 0; i < pcie->num_lanes; i++) {
839 val = dw_pcie_readw_dbi(pci, CAP_SPCIE_CAP_OFF + (i * 2));
840 val &= ~CAP_SPCIE_CAP_OFF_DSP_TX_PRESET0_MASK;
841 val |= GEN3_GEN4_EQ_PRESET_INIT;
842 val &= ~CAP_SPCIE_CAP_OFF_USP_TX_PRESET0_MASK;
843 val |= (GEN3_GEN4_EQ_PRESET_INIT <<
844 CAP_SPCIE_CAP_OFF_USP_TX_PRESET0_SHIFT);
845 dw_pcie_writew_dbi(pci, CAP_SPCIE_CAP_OFF + (i * 2), val);
847 offset = dw_pcie_find_ext_capability(pci,
848 PCI_EXT_CAP_ID_PL_16GT) +
850 val = dw_pcie_readb_dbi(pci, offset + i);
851 val &= ~PCI_PL_16GT_LE_CTRL_DSP_TX_PRESET_MASK;
852 val |= GEN3_GEN4_EQ_PRESET_INIT;
853 val &= ~PCI_PL_16GT_LE_CTRL_USP_TX_PRESET_MASK;
854 val |= (GEN3_GEN4_EQ_PRESET_INIT <<
855 PCI_PL_16GT_LE_CTRL_USP_TX_PRESET_SHIFT);
856 dw_pcie_writeb_dbi(pci, offset + i, 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);
863 val = dw_pcie_readl_dbi(pci, GEN3_EQ_CONTROL_OFF);
864 val &= ~GEN3_EQ_CONTROL_OFF_PSET_REQ_VEC_MASK;
865 val |= (0x3ff << GEN3_EQ_CONTROL_OFF_PSET_REQ_VEC_SHIFT);
866 val &= ~GEN3_EQ_CONTROL_OFF_FB_MODE_MASK;
867 dw_pcie_writel_dbi(pci, GEN3_EQ_CONTROL_OFF, val);
869 val = dw_pcie_readl_dbi(pci, GEN3_RELATED_OFF);
870 val &= ~GEN3_RELATED_OFF_RATE_SHADOW_SEL_MASK;
871 val |= (0x1 << GEN3_RELATED_OFF_RATE_SHADOW_SEL_SHIFT);
872 dw_pcie_writel_dbi(pci, GEN3_RELATED_OFF, val);
874 val = dw_pcie_readl_dbi(pci, GEN3_EQ_CONTROL_OFF);
875 val &= ~GEN3_EQ_CONTROL_OFF_PSET_REQ_VEC_MASK;
876 val |= (pcie->of_data->gen4_preset_vec <<
877 GEN3_EQ_CONTROL_OFF_PSET_REQ_VEC_SHIFT);
878 val &= ~GEN3_EQ_CONTROL_OFF_FB_MODE_MASK;
879 dw_pcie_writel_dbi(pci, GEN3_EQ_CONTROL_OFF, val);
881 val = dw_pcie_readl_dbi(pci, GEN3_RELATED_OFF);
882 val &= ~GEN3_RELATED_OFF_RATE_SHADOW_SEL_MASK;
883 dw_pcie_writel_dbi(pci, GEN3_RELATED_OFF, val);
886 static int tegra_pcie_dw_host_init(struct dw_pcie_rp *pp)
888 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
889 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci);
893 pp->bridge->ops = &tegra_pci_ops;
895 if (!pcie->pcie_cap_base)
896 pcie->pcie_cap_base = dw_pcie_find_capability(&pcie->pci,
899 val = dw_pcie_readl_dbi(pci, PCI_IO_BASE);
900 val &= ~(IO_BASE_IO_DECODE | IO_BASE_IO_DECODE_BIT8);
901 dw_pcie_writel_dbi(pci, PCI_IO_BASE, val);
903 val = dw_pcie_readl_dbi(pci, PCI_PREF_MEMORY_BASE);
904 val |= CFG_PREF_MEM_LIMIT_BASE_MEM_DECODE;
905 val |= CFG_PREF_MEM_LIMIT_BASE_MEM_LIMIT_DECODE;
906 dw_pcie_writel_dbi(pci, PCI_PREF_MEMORY_BASE, val);
908 dw_pcie_writel_dbi(pci, PCI_BASE_ADDRESS_0, 0);
910 /* Enable as 0xFFFF0001 response for CRS */
911 val = dw_pcie_readl_dbi(pci, PORT_LOGIC_AMBA_ERROR_RESPONSE_DEFAULT);
912 val &= ~(AMBA_ERROR_RESPONSE_CRS_MASK << AMBA_ERROR_RESPONSE_CRS_SHIFT);
913 val |= (AMBA_ERROR_RESPONSE_CRS_OKAY_FFFF0001 <<
914 AMBA_ERROR_RESPONSE_CRS_SHIFT);
915 dw_pcie_writel_dbi(pci, PORT_LOGIC_AMBA_ERROR_RESPONSE_DEFAULT, val);
917 /* Clear Slot Clock Configuration bit if SRNS configuration */
918 if (pcie->enable_srns) {
919 val_16 = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base +
921 val_16 &= ~PCI_EXP_LNKSTA_SLC;
922 dw_pcie_writew_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKSTA,
926 config_gen3_gen4_eq_presets(pcie);
928 init_host_aspm(pcie);
930 /* Disable ASPM-L1SS advertisement if there is no CLKREQ routing */
931 if (!pcie->supports_clkreq) {
932 disable_aspm_l11(pcie);
933 disable_aspm_l12(pcie);
936 if (!pcie->of_data->has_l1ss_exit_fix) {
937 val = dw_pcie_readl_dbi(pci, GEN3_RELATED_OFF);
938 val &= ~GEN3_RELATED_OFF_GEN3_ZRXDC_NONCOMPL;
939 dw_pcie_writel_dbi(pci, GEN3_RELATED_OFF, val);
942 if (pcie->update_fc_fixup) {
943 val = dw_pcie_readl_dbi(pci, CFG_TIMER_CTRL_MAX_FUNC_NUM_OFF);
944 val |= 0x1 << CFG_TIMER_CTRL_ACK_NAK_SHIFT;
945 dw_pcie_writel_dbi(pci, CFG_TIMER_CTRL_MAX_FUNC_NUM_OFF, val);
948 clk_set_rate(pcie->core_clk, GEN4_CORE_CLK_FREQ);
953 static int tegra_pcie_dw_start_link(struct dw_pcie *pci)
955 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci);
956 struct dw_pcie_rp *pp = &pci->pp;
957 u32 val, offset, tmp;
960 if (pcie->of_data->mode == DW_PCIE_EP_TYPE) {
961 enable_irq(pcie->pex_rst_irq);
967 val = appl_readl(pcie, APPL_PINMUX);
968 val &= ~APPL_PINMUX_PEX_RST;
969 appl_writel(pcie, val, APPL_PINMUX);
971 usleep_range(100, 200);
974 val = appl_readl(pcie, APPL_CTRL);
975 val |= APPL_CTRL_LTSSM_EN;
976 appl_writel(pcie, val, APPL_CTRL);
979 val = appl_readl(pcie, APPL_PINMUX);
980 val |= APPL_PINMUX_PEX_RST;
981 appl_writel(pcie, val, APPL_PINMUX);
985 if (dw_pcie_wait_for_link(pci)) {
989 * There are some endpoints which can't get the link up if
990 * root port has Data Link Feature (DLF) enabled.
991 * Refer Spec rev 4.0 ver 1.0 sec 3.4.2 & 7.7.4 for more info
992 * on Scaled Flow Control and DLF.
993 * So, need to confirm that is indeed the case here and attempt
994 * link up once again with DLF disabled.
996 val = appl_readl(pcie, APPL_DEBUG);
997 val &= APPL_DEBUG_LTSSM_STATE_MASK;
998 val >>= APPL_DEBUG_LTSSM_STATE_SHIFT;
999 tmp = appl_readl(pcie, APPL_LINK_STATUS);
1000 tmp &= APPL_LINK_STATUS_RDLH_LINK_UP;
1001 if (!(val == 0x11 && !tmp)) {
1002 /* Link is down for all good reasons */
1006 dev_info(pci->dev, "Link is down in DLL");
1007 dev_info(pci->dev, "Trying again with DLFE disabled\n");
1009 val = appl_readl(pcie, APPL_CTRL);
1010 val &= ~APPL_CTRL_LTSSM_EN;
1011 appl_writel(pcie, val, APPL_CTRL);
1013 reset_control_assert(pcie->core_rst);
1014 reset_control_deassert(pcie->core_rst);
1016 offset = dw_pcie_find_ext_capability(pci, PCI_EXT_CAP_ID_DLF);
1017 val = dw_pcie_readl_dbi(pci, offset + PCI_DLF_CAP);
1018 val &= ~PCI_DLF_EXCHANGE_ENABLE;
1019 dw_pcie_writel_dbi(pci, offset + PCI_DLF_CAP, val);
1021 tegra_pcie_dw_host_init(pp);
1022 dw_pcie_setup_rc(pp);
1028 tegra_pcie_icc_set(pcie);
1030 tegra_pcie_enable_interrupts(pp);
1035 static int tegra_pcie_dw_link_up(struct dw_pcie *pci)
1037 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci);
1038 u32 val = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKSTA);
1040 return !!(val & PCI_EXP_LNKSTA_DLLLA);
1043 static void tegra_pcie_dw_stop_link(struct dw_pcie *pci)
1045 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci);
1047 disable_irq(pcie->pex_rst_irq);
1050 static const struct dw_pcie_ops tegra_dw_pcie_ops = {
1051 .link_up = tegra_pcie_dw_link_up,
1052 .start_link = tegra_pcie_dw_start_link,
1053 .stop_link = tegra_pcie_dw_stop_link,
1056 static const struct dw_pcie_host_ops tegra_pcie_dw_host_ops = {
1057 .init = tegra_pcie_dw_host_init,
1060 static void tegra_pcie_disable_phy(struct tegra_pcie_dw *pcie)
1062 unsigned int phy_count = pcie->phy_count;
1064 while (phy_count--) {
1065 phy_power_off(pcie->phys[phy_count]);
1066 phy_exit(pcie->phys[phy_count]);
1070 static int tegra_pcie_enable_phy(struct tegra_pcie_dw *pcie)
1075 for (i = 0; i < pcie->phy_count; i++) {
1076 ret = phy_init(pcie->phys[i]);
1080 ret = phy_power_on(pcie->phys[i]);
1089 phy_power_off(pcie->phys[i]);
1091 phy_exit(pcie->phys[i]);
1097 static int tegra_pcie_dw_parse_dt(struct tegra_pcie_dw *pcie)
1099 struct platform_device *pdev = to_platform_device(pcie->dev);
1100 struct device_node *np = pcie->dev->of_node;
1103 pcie->dbi_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dbi");
1104 if (!pcie->dbi_res) {
1105 dev_err(pcie->dev, "Failed to find \"dbi\" region\n");
1109 ret = of_property_read_u32(np, "nvidia,aspm-cmrt-us", &pcie->aspm_cmrt);
1111 dev_info(pcie->dev, "Failed to read ASPM T_cmrt: %d\n", ret);
1115 ret = of_property_read_u32(np, "nvidia,aspm-pwr-on-t-us",
1116 &pcie->aspm_pwr_on_t);
1118 dev_info(pcie->dev, "Failed to read ASPM Power On time: %d\n",
1121 ret = of_property_read_u32(np, "nvidia,aspm-l0s-entrance-latency-us",
1122 &pcie->aspm_l0s_enter_lat);
1125 "Failed to read ASPM L0s Entrance latency: %d\n", ret);
1127 ret = of_property_read_u32(np, "num-lanes", &pcie->num_lanes);
1129 dev_err(pcie->dev, "Failed to read num-lanes: %d\n", ret);
1133 ret = of_property_read_u32_index(np, "nvidia,bpmp", 1, &pcie->cid);
1135 dev_err(pcie->dev, "Failed to read Controller-ID: %d\n", ret);
1139 ret = of_property_count_strings(np, "phy-names");
1141 dev_err(pcie->dev, "Failed to find PHY entries: %d\n",
1145 pcie->phy_count = ret;
1147 if (of_property_read_bool(np, "nvidia,update-fc-fixup"))
1148 pcie->update_fc_fixup = true;
1150 /* RP using an external REFCLK is supported only in Tegra234 */
1151 if (pcie->of_data->version == TEGRA194_DWC_IP_VER) {
1152 if (pcie->of_data->mode == DW_PCIE_EP_TYPE)
1153 pcie->enable_ext_refclk = true;
1155 pcie->enable_ext_refclk =
1156 of_property_read_bool(pcie->dev->of_node,
1157 "nvidia,enable-ext-refclk");
1160 pcie->supports_clkreq =
1161 of_property_read_bool(pcie->dev->of_node, "supports-clkreq");
1163 pcie->enable_cdm_check =
1164 of_property_read_bool(np, "snps,enable-cdm-check");
1166 if (pcie->of_data->version == TEGRA234_DWC_IP_VER)
1168 of_property_read_bool(np, "nvidia,enable-srns");
1170 if (pcie->of_data->mode == DW_PCIE_RC_TYPE)
1173 /* Endpoint mode specific DT entries */
1174 pcie->pex_rst_gpiod = devm_gpiod_get(pcie->dev, "reset", GPIOD_IN);
1175 if (IS_ERR(pcie->pex_rst_gpiod)) {
1176 int err = PTR_ERR(pcie->pex_rst_gpiod);
1177 const char *level = KERN_ERR;
1179 if (err == -EPROBE_DEFER)
1182 dev_printk(level, pcie->dev,
1183 dev_fmt("Failed to get PERST GPIO: %d\n"),
1188 pcie->pex_refclk_sel_gpiod = devm_gpiod_get(pcie->dev,
1189 "nvidia,refclk-select",
1191 if (IS_ERR(pcie->pex_refclk_sel_gpiod)) {
1192 int err = PTR_ERR(pcie->pex_refclk_sel_gpiod);
1193 const char *level = KERN_ERR;
1195 if (err == -EPROBE_DEFER)
1198 dev_printk(level, pcie->dev,
1199 dev_fmt("Failed to get REFCLK select GPIOs: %d\n"),
1201 pcie->pex_refclk_sel_gpiod = NULL;
1207 static int tegra_pcie_bpmp_set_ctrl_state(struct tegra_pcie_dw *pcie,
1210 struct mrq_uphy_response resp;
1211 struct tegra_bpmp_message msg;
1212 struct mrq_uphy_request req;
1215 * Controller-5 doesn't need to have its state set by BPMP-FW in
1218 if (pcie->of_data->version == TEGRA194_DWC_IP_VER && pcie->cid == 5)
1221 memset(&req, 0, sizeof(req));
1222 memset(&resp, 0, sizeof(resp));
1224 req.cmd = CMD_UPHY_PCIE_CONTROLLER_STATE;
1225 req.controller_state.pcie_controller = pcie->cid;
1226 req.controller_state.enable = enable;
1228 memset(&msg, 0, sizeof(msg));
1231 msg.tx.size = sizeof(req);
1232 msg.rx.data = &resp;
1233 msg.rx.size = sizeof(resp);
1235 return tegra_bpmp_transfer(pcie->bpmp, &msg);
1238 static int tegra_pcie_bpmp_set_pll_state(struct tegra_pcie_dw *pcie,
1241 struct mrq_uphy_response resp;
1242 struct tegra_bpmp_message msg;
1243 struct mrq_uphy_request req;
1245 memset(&req, 0, sizeof(req));
1246 memset(&resp, 0, sizeof(resp));
1249 req.cmd = CMD_UPHY_PCIE_EP_CONTROLLER_PLL_INIT;
1250 req.ep_ctrlr_pll_init.ep_controller = pcie->cid;
1252 req.cmd = CMD_UPHY_PCIE_EP_CONTROLLER_PLL_OFF;
1253 req.ep_ctrlr_pll_off.ep_controller = pcie->cid;
1256 memset(&msg, 0, sizeof(msg));
1259 msg.tx.size = sizeof(req);
1260 msg.rx.data = &resp;
1261 msg.rx.size = sizeof(resp);
1263 return tegra_bpmp_transfer(pcie->bpmp, &msg);
1266 static void tegra_pcie_downstream_dev_to_D0(struct tegra_pcie_dw *pcie)
1268 struct dw_pcie_rp *pp = &pcie->pci.pp;
1269 struct pci_bus *child, *root_bus = NULL;
1270 struct pci_dev *pdev;
1273 * link doesn't go into L2 state with some of the endpoints with Tegra
1274 * if they are not in D0 state. So, need to make sure that immediate
1275 * downstream devices are in D0 state before sending PME_TurnOff to put
1276 * link into L2 state.
1277 * This is as per PCI Express Base r4.0 v1.0 September 27-2017,
1278 * 5.2 Link State Power Management (Page #428).
1281 list_for_each_entry(child, &pp->bridge->bus->children, node) {
1282 /* Bring downstream devices to D0 if they are not already in */
1283 if (child->parent == pp->bridge->bus) {
1290 dev_err(pcie->dev, "Failed to find downstream devices\n");
1294 list_for_each_entry(pdev, &root_bus->devices, bus_list) {
1295 if (PCI_SLOT(pdev->devfn) == 0) {
1296 if (pci_set_power_state(pdev, PCI_D0))
1298 "Failed to transition %s to D0 state\n",
1299 dev_name(&pdev->dev));
1304 static int tegra_pcie_get_slot_regulators(struct tegra_pcie_dw *pcie)
1306 pcie->slot_ctl_3v3 = devm_regulator_get_optional(pcie->dev, "vpcie3v3");
1307 if (IS_ERR(pcie->slot_ctl_3v3)) {
1308 if (PTR_ERR(pcie->slot_ctl_3v3) != -ENODEV)
1309 return PTR_ERR(pcie->slot_ctl_3v3);
1311 pcie->slot_ctl_3v3 = NULL;
1314 pcie->slot_ctl_12v = devm_regulator_get_optional(pcie->dev, "vpcie12v");
1315 if (IS_ERR(pcie->slot_ctl_12v)) {
1316 if (PTR_ERR(pcie->slot_ctl_12v) != -ENODEV)
1317 return PTR_ERR(pcie->slot_ctl_12v);
1319 pcie->slot_ctl_12v = NULL;
1325 static int tegra_pcie_enable_slot_regulators(struct tegra_pcie_dw *pcie)
1329 if (pcie->slot_ctl_3v3) {
1330 ret = regulator_enable(pcie->slot_ctl_3v3);
1333 "Failed to enable 3.3V slot supply: %d\n", ret);
1338 if (pcie->slot_ctl_12v) {
1339 ret = regulator_enable(pcie->slot_ctl_12v);
1342 "Failed to enable 12V slot supply: %d\n", ret);
1343 goto fail_12v_enable;
1348 * According to PCI Express Card Electromechanical Specification
1349 * Revision 1.1, Table-2.4, T_PVPERL (Power stable to PERST# inactive)
1350 * should be a minimum of 100ms.
1352 if (pcie->slot_ctl_3v3 || pcie->slot_ctl_12v)
1358 if (pcie->slot_ctl_3v3)
1359 regulator_disable(pcie->slot_ctl_3v3);
1363 static void tegra_pcie_disable_slot_regulators(struct tegra_pcie_dw *pcie)
1365 if (pcie->slot_ctl_12v)
1366 regulator_disable(pcie->slot_ctl_12v);
1367 if (pcie->slot_ctl_3v3)
1368 regulator_disable(pcie->slot_ctl_3v3);
1371 static int tegra_pcie_config_controller(struct tegra_pcie_dw *pcie,
1377 ret = tegra_pcie_bpmp_set_ctrl_state(pcie, true);
1380 "Failed to enable controller %u: %d\n", pcie->cid, ret);
1384 if (pcie->enable_ext_refclk) {
1385 ret = tegra_pcie_bpmp_set_pll_state(pcie, true);
1387 dev_err(pcie->dev, "Failed to init UPHY: %d\n", ret);
1392 ret = tegra_pcie_enable_slot_regulators(pcie);
1394 goto fail_slot_reg_en;
1396 ret = regulator_enable(pcie->pex_ctl_supply);
1398 dev_err(pcie->dev, "Failed to enable regulator: %d\n", ret);
1402 ret = clk_prepare_enable(pcie->core_clk);
1404 dev_err(pcie->dev, "Failed to enable core clock: %d\n", ret);
1408 ret = reset_control_deassert(pcie->core_apb_rst);
1410 dev_err(pcie->dev, "Failed to deassert core APB reset: %d\n",
1412 goto fail_core_apb_rst;
1415 if (en_hw_hot_rst || pcie->of_data->has_sbr_reset_fix) {
1416 /* Enable HW_HOT_RST mode */
1417 val = appl_readl(pcie, APPL_CTRL);
1418 val &= ~(APPL_CTRL_HW_HOT_RST_MODE_MASK <<
1419 APPL_CTRL_HW_HOT_RST_MODE_SHIFT);
1420 val |= (APPL_CTRL_HW_HOT_RST_MODE_IMDT_RST_LTSSM_EN <<
1421 APPL_CTRL_HW_HOT_RST_MODE_SHIFT);
1422 val |= APPL_CTRL_HW_HOT_RST_EN;
1423 appl_writel(pcie, val, APPL_CTRL);
1426 ret = tegra_pcie_enable_phy(pcie);
1428 dev_err(pcie->dev, "Failed to enable PHY: %d\n", ret);
1432 /* Update CFG base address */
1433 appl_writel(pcie, pcie->dbi_res->start & APPL_CFG_BASE_ADDR_MASK,
1434 APPL_CFG_BASE_ADDR);
1436 /* Configure this core for RP mode operation */
1437 appl_writel(pcie, APPL_DM_TYPE_RP, APPL_DM_TYPE);
1439 appl_writel(pcie, 0x0, APPL_CFG_SLCG_OVERRIDE);
1441 val = appl_readl(pcie, APPL_CTRL);
1442 appl_writel(pcie, val | APPL_CTRL_SYS_PRE_DET_STATE, APPL_CTRL);
1444 val = appl_readl(pcie, APPL_CFG_MISC);
1445 val |= (APPL_CFG_MISC_ARCACHE_VAL << APPL_CFG_MISC_ARCACHE_SHIFT);
1446 appl_writel(pcie, val, APPL_CFG_MISC);
1448 if (pcie->enable_srns || pcie->enable_ext_refclk) {
1450 * When Tegra PCIe RP is using external clock, it cannot supply
1451 * same clock to its downstream hierarchy. Hence, gate PCIe RP
1452 * REFCLK out pads when RP & EP are using separate clocks or RP
1453 * is using an external REFCLK.
1455 val = appl_readl(pcie, APPL_PINMUX);
1456 val |= APPL_PINMUX_CLK_OUTPUT_IN_OVERRIDE_EN;
1457 val &= ~APPL_PINMUX_CLK_OUTPUT_IN_OVERRIDE;
1458 appl_writel(pcie, val, APPL_PINMUX);
1461 if (!pcie->supports_clkreq) {
1462 val = appl_readl(pcie, APPL_PINMUX);
1463 val |= APPL_PINMUX_CLKREQ_OVERRIDE_EN;
1464 val &= ~APPL_PINMUX_CLKREQ_OVERRIDE;
1465 appl_writel(pcie, val, APPL_PINMUX);
1468 /* Update iATU_DMA base address */
1470 pcie->atu_dma_res->start & APPL_CFG_IATU_DMA_BASE_ADDR_MASK,
1471 APPL_CFG_IATU_DMA_BASE_ADDR);
1473 reset_control_deassert(pcie->core_rst);
1478 reset_control_assert(pcie->core_apb_rst);
1480 clk_disable_unprepare(pcie->core_clk);
1482 regulator_disable(pcie->pex_ctl_supply);
1484 tegra_pcie_disable_slot_regulators(pcie);
1486 if (pcie->enable_ext_refclk)
1487 tegra_pcie_bpmp_set_pll_state(pcie, false);
1489 tegra_pcie_bpmp_set_ctrl_state(pcie, false);
1494 static void tegra_pcie_unconfig_controller(struct tegra_pcie_dw *pcie)
1498 ret = reset_control_assert(pcie->core_rst);
1500 dev_err(pcie->dev, "Failed to assert \"core\" reset: %d\n", ret);
1502 tegra_pcie_disable_phy(pcie);
1504 ret = reset_control_assert(pcie->core_apb_rst);
1506 dev_err(pcie->dev, "Failed to assert APB reset: %d\n", ret);
1508 clk_disable_unprepare(pcie->core_clk);
1510 ret = regulator_disable(pcie->pex_ctl_supply);
1512 dev_err(pcie->dev, "Failed to disable regulator: %d\n", ret);
1514 tegra_pcie_disable_slot_regulators(pcie);
1516 if (pcie->enable_ext_refclk) {
1517 ret = tegra_pcie_bpmp_set_pll_state(pcie, false);
1519 dev_err(pcie->dev, "Failed to deinit UPHY: %d\n", ret);
1522 ret = tegra_pcie_bpmp_set_ctrl_state(pcie, false);
1524 dev_err(pcie->dev, "Failed to disable controller %d: %d\n",
1528 static int tegra_pcie_init_controller(struct tegra_pcie_dw *pcie)
1530 struct dw_pcie *pci = &pcie->pci;
1531 struct dw_pcie_rp *pp = &pci->pp;
1534 ret = tegra_pcie_config_controller(pcie, false);
1538 pp->ops = &tegra_pcie_dw_host_ops;
1540 ret = dw_pcie_host_init(pp);
1542 dev_err(pcie->dev, "Failed to add PCIe port: %d\n", ret);
1543 goto fail_host_init;
1549 tegra_pcie_unconfig_controller(pcie);
1553 static int tegra_pcie_try_link_l2(struct tegra_pcie_dw *pcie)
1557 if (!tegra_pcie_dw_link_up(&pcie->pci))
1560 val = appl_readl(pcie, APPL_RADM_STATUS);
1561 val |= APPL_PM_XMT_TURNOFF_STATE;
1562 appl_writel(pcie, val, APPL_RADM_STATUS);
1564 return readl_poll_timeout_atomic(pcie->appl_base + APPL_DEBUG, val,
1565 val & APPL_DEBUG_PM_LINKST_IN_L2_LAT,
1566 1, PME_ACK_TIMEOUT);
1569 static void tegra_pcie_dw_pme_turnoff(struct tegra_pcie_dw *pcie)
1574 if (!tegra_pcie_dw_link_up(&pcie->pci)) {
1575 dev_dbg(pcie->dev, "PCIe link is not up...!\n");
1580 * PCIe controller exits from L2 only if reset is applied, so
1581 * controller doesn't handle interrupts. But in cases where
1582 * L2 entry fails, PERST# is asserted which can trigger surprise
1583 * link down AER. However this function call happens in
1584 * suspend_noirq(), so AER interrupt will not be processed.
1585 * Disable all interrupts to avoid such a scenario.
1587 appl_writel(pcie, 0x0, APPL_INTR_EN_L0_0);
1589 if (tegra_pcie_try_link_l2(pcie)) {
1590 dev_info(pcie->dev, "Link didn't transition to L2 state\n");
1592 * TX lane clock freq will reset to Gen1 only if link is in L2
1594 * So apply pex_rst to end point to force RP to go into detect
1597 data = appl_readl(pcie, APPL_PINMUX);
1598 data &= ~APPL_PINMUX_PEX_RST;
1599 appl_writel(pcie, data, APPL_PINMUX);
1602 * Some cards do not go to detect state even after de-asserting
1603 * PERST#. So, de-assert LTSSM to bring link to detect state.
1605 data = readl(pcie->appl_base + APPL_CTRL);
1606 data &= ~APPL_CTRL_LTSSM_EN;
1607 writel(data, pcie->appl_base + APPL_CTRL);
1609 err = readl_poll_timeout_atomic(pcie->appl_base + APPL_DEBUG,
1612 APPL_DEBUG_LTSSM_STATE_MASK) >>
1613 APPL_DEBUG_LTSSM_STATE_SHIFT) ==
1614 LTSSM_STATE_PRE_DETECT,
1617 dev_info(pcie->dev, "Link didn't go to detect state\n");
1620 * DBI registers may not be accessible after this as PLL-E would be
1621 * down depending on how CLKREQ is pulled by end point
1623 data = appl_readl(pcie, APPL_PINMUX);
1624 data |= (APPL_PINMUX_CLKREQ_OVERRIDE_EN | APPL_PINMUX_CLKREQ_OVERRIDE);
1625 /* Cut REFCLK to slot */
1626 data |= APPL_PINMUX_CLK_OUTPUT_IN_OVERRIDE_EN;
1627 data &= ~APPL_PINMUX_CLK_OUTPUT_IN_OVERRIDE;
1628 appl_writel(pcie, data, APPL_PINMUX);
1631 static void tegra_pcie_deinit_controller(struct tegra_pcie_dw *pcie)
1633 tegra_pcie_downstream_dev_to_D0(pcie);
1634 dw_pcie_host_deinit(&pcie->pci.pp);
1635 tegra_pcie_dw_pme_turnoff(pcie);
1636 tegra_pcie_unconfig_controller(pcie);
1639 static int tegra_pcie_config_rp(struct tegra_pcie_dw *pcie)
1641 struct device *dev = pcie->dev;
1645 pm_runtime_enable(dev);
1647 ret = pm_runtime_get_sync(dev);
1649 dev_err(dev, "Failed to get runtime sync for PCIe dev: %d\n",
1651 goto fail_pm_get_sync;
1654 ret = pinctrl_pm_select_default_state(dev);
1656 dev_err(dev, "Failed to configure sideband pins: %d\n", ret);
1657 goto fail_pm_get_sync;
1660 ret = tegra_pcie_init_controller(pcie);
1662 dev_err(dev, "Failed to initialize controller: %d\n", ret);
1663 goto fail_pm_get_sync;
1666 pcie->link_state = tegra_pcie_dw_link_up(&pcie->pci);
1667 if (!pcie->link_state) {
1669 goto fail_host_init;
1672 name = devm_kasprintf(dev, GFP_KERNEL, "%pOFP", dev->of_node);
1675 goto fail_host_init;
1678 pcie->debugfs = debugfs_create_dir(name, NULL);
1684 tegra_pcie_deinit_controller(pcie);
1686 pm_runtime_put_sync(dev);
1687 pm_runtime_disable(dev);
1691 static void pex_ep_event_pex_rst_assert(struct tegra_pcie_dw *pcie)
1696 if (pcie->ep_state == EP_STATE_DISABLED)
1700 val = appl_readl(pcie, APPL_CTRL);
1701 val &= ~APPL_CTRL_LTSSM_EN;
1702 appl_writel(pcie, val, APPL_CTRL);
1704 ret = readl_poll_timeout(pcie->appl_base + APPL_DEBUG, val,
1705 ((val & APPL_DEBUG_LTSSM_STATE_MASK) >>
1706 APPL_DEBUG_LTSSM_STATE_SHIFT) ==
1707 LTSSM_STATE_PRE_DETECT,
1710 dev_err(pcie->dev, "Failed to go Detect state: %d\n", ret);
1712 pci_epc_deinit_notify(pcie->pci.ep.epc);
1713 dw_pcie_ep_cleanup(&pcie->pci.ep);
1715 reset_control_assert(pcie->core_rst);
1717 tegra_pcie_disable_phy(pcie);
1719 reset_control_assert(pcie->core_apb_rst);
1721 clk_disable_unprepare(pcie->core_clk);
1723 pm_runtime_put_sync(pcie->dev);
1725 if (pcie->enable_ext_refclk) {
1726 ret = tegra_pcie_bpmp_set_pll_state(pcie, false);
1728 dev_err(pcie->dev, "Failed to turn off UPHY: %d\n",
1732 ret = tegra_pcie_bpmp_set_pll_state(pcie, false);
1734 dev_err(pcie->dev, "Failed to turn off UPHY: %d\n", ret);
1736 pcie->ep_state = EP_STATE_DISABLED;
1737 dev_dbg(pcie->dev, "Uninitialization of endpoint is completed\n");
1740 static void pex_ep_event_pex_rst_deassert(struct tegra_pcie_dw *pcie)
1742 struct dw_pcie *pci = &pcie->pci;
1743 struct dw_pcie_ep *ep = &pci->ep;
1744 struct device *dev = pcie->dev;
1749 if (pcie->ep_state == EP_STATE_ENABLED)
1752 ret = pm_runtime_resume_and_get(dev);
1754 dev_err(dev, "Failed to get runtime sync for PCIe dev: %d\n",
1759 ret = tegra_pcie_bpmp_set_ctrl_state(pcie, true);
1761 dev_err(pcie->dev, "Failed to enable controller %u: %d\n",
1763 goto fail_set_ctrl_state;
1766 if (pcie->enable_ext_refclk) {
1767 ret = tegra_pcie_bpmp_set_pll_state(pcie, true);
1769 dev_err(dev, "Failed to init UPHY for PCIe EP: %d\n",
1775 ret = clk_prepare_enable(pcie->core_clk);
1777 dev_err(dev, "Failed to enable core clock: %d\n", ret);
1778 goto fail_core_clk_enable;
1781 ret = reset_control_deassert(pcie->core_apb_rst);
1783 dev_err(dev, "Failed to deassert core APB reset: %d\n", ret);
1784 goto fail_core_apb_rst;
1787 ret = tegra_pcie_enable_phy(pcie);
1789 dev_err(dev, "Failed to enable PHY: %d\n", ret);
1793 /* Clear any stale interrupt statuses */
1794 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L0);
1795 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_0_0);
1796 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_1);
1797 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_2);
1798 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_3);
1799 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_6);
1800 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_7);
1801 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_8_0);
1802 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_9);
1803 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_10);
1804 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_11);
1805 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_13);
1806 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_14);
1807 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_15);
1808 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_17);
1810 /* configure this core for EP mode operation */
1811 val = appl_readl(pcie, APPL_DM_TYPE);
1812 val &= ~APPL_DM_TYPE_MASK;
1813 val |= APPL_DM_TYPE_EP;
1814 appl_writel(pcie, val, APPL_DM_TYPE);
1816 appl_writel(pcie, 0x0, APPL_CFG_SLCG_OVERRIDE);
1818 val = appl_readl(pcie, APPL_CTRL);
1819 val |= APPL_CTRL_SYS_PRE_DET_STATE;
1820 val |= APPL_CTRL_HW_HOT_RST_EN;
1821 appl_writel(pcie, val, APPL_CTRL);
1823 val = appl_readl(pcie, APPL_CFG_MISC);
1824 val |= APPL_CFG_MISC_SLV_EP_MODE;
1825 val |= (APPL_CFG_MISC_ARCACHE_VAL << APPL_CFG_MISC_ARCACHE_SHIFT);
1826 appl_writel(pcie, val, APPL_CFG_MISC);
1828 val = appl_readl(pcie, APPL_PINMUX);
1829 val |= APPL_PINMUX_CLK_OUTPUT_IN_OVERRIDE_EN;
1830 val |= APPL_PINMUX_CLK_OUTPUT_IN_OVERRIDE;
1831 appl_writel(pcie, val, APPL_PINMUX);
1833 appl_writel(pcie, pcie->dbi_res->start & APPL_CFG_BASE_ADDR_MASK,
1834 APPL_CFG_BASE_ADDR);
1836 appl_writel(pcie, pcie->atu_dma_res->start &
1837 APPL_CFG_IATU_DMA_BASE_ADDR_MASK,
1838 APPL_CFG_IATU_DMA_BASE_ADDR);
1840 val = appl_readl(pcie, APPL_INTR_EN_L0_0);
1841 val |= APPL_INTR_EN_L0_0_SYS_INTR_EN;
1842 val |= APPL_INTR_EN_L0_0_LINK_STATE_INT_EN;
1843 val |= APPL_INTR_EN_L0_0_PCI_CMD_EN_INT_EN;
1844 appl_writel(pcie, val, APPL_INTR_EN_L0_0);
1846 val = appl_readl(pcie, APPL_INTR_EN_L1_0_0);
1847 val |= APPL_INTR_EN_L1_0_0_HOT_RESET_DONE_INT_EN;
1848 val |= APPL_INTR_EN_L1_0_0_RDLH_LINK_UP_INT_EN;
1849 appl_writel(pcie, val, APPL_INTR_EN_L1_0_0);
1851 reset_control_deassert(pcie->core_rst);
1853 if (pcie->update_fc_fixup) {
1854 val = dw_pcie_readl_dbi(pci, CFG_TIMER_CTRL_MAX_FUNC_NUM_OFF);
1855 val |= 0x1 << CFG_TIMER_CTRL_ACK_NAK_SHIFT;
1856 dw_pcie_writel_dbi(pci, CFG_TIMER_CTRL_MAX_FUNC_NUM_OFF, val);
1859 config_gen3_gen4_eq_presets(pcie);
1861 init_host_aspm(pcie);
1863 /* Disable ASPM-L1SS advertisement if there is no CLKREQ routing */
1864 if (!pcie->supports_clkreq) {
1865 disable_aspm_l11(pcie);
1866 disable_aspm_l12(pcie);
1869 if (!pcie->of_data->has_l1ss_exit_fix) {
1870 val = dw_pcie_readl_dbi(pci, GEN3_RELATED_OFF);
1871 val &= ~GEN3_RELATED_OFF_GEN3_ZRXDC_NONCOMPL;
1872 dw_pcie_writel_dbi(pci, GEN3_RELATED_OFF, val);
1875 pcie->pcie_cap_base = dw_pcie_find_capability(&pcie->pci,
1878 /* Clear Slot Clock Configuration bit if SRNS configuration */
1879 if (pcie->enable_srns) {
1880 val_16 = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base +
1882 val_16 &= ~PCI_EXP_LNKSTA_SLC;
1883 dw_pcie_writew_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKSTA,
1887 clk_set_rate(pcie->core_clk, GEN4_CORE_CLK_FREQ);
1889 val = (ep->msi_mem_phys & MSIX_ADDR_MATCH_LOW_OFF_MASK);
1890 val |= MSIX_ADDR_MATCH_LOW_OFF_EN;
1891 dw_pcie_writel_dbi(pci, MSIX_ADDR_MATCH_LOW_OFF, val);
1892 val = (upper_32_bits(ep->msi_mem_phys) & MSIX_ADDR_MATCH_HIGH_OFF_MASK);
1893 dw_pcie_writel_dbi(pci, MSIX_ADDR_MATCH_HIGH_OFF, val);
1895 ret = dw_pcie_ep_init_registers(ep);
1897 dev_err(dev, "Failed to complete initialization: %d\n", ret);
1898 goto fail_init_complete;
1901 pci_epc_init_notify(ep->epc);
1903 /* Program the private control to allow sending LTR upstream */
1904 if (pcie->of_data->has_ltr_req_fix) {
1905 val = appl_readl(pcie, APPL_LTR_MSG_2);
1906 val |= APPL_LTR_MSG_2_LTR_MSG_REQ_STATE;
1907 appl_writel(pcie, val, APPL_LTR_MSG_2);
1911 val = appl_readl(pcie, APPL_CTRL);
1912 val |= APPL_CTRL_LTSSM_EN;
1913 appl_writel(pcie, val, APPL_CTRL);
1915 pcie->ep_state = EP_STATE_ENABLED;
1916 dev_dbg(dev, "Initialization of endpoint is completed\n");
1921 reset_control_assert(pcie->core_rst);
1922 tegra_pcie_disable_phy(pcie);
1924 reset_control_assert(pcie->core_apb_rst);
1926 clk_disable_unprepare(pcie->core_clk);
1927 fail_core_clk_enable:
1928 tegra_pcie_bpmp_set_pll_state(pcie, false);
1930 tegra_pcie_bpmp_set_ctrl_state(pcie, false);
1931 fail_set_ctrl_state:
1932 pm_runtime_put_sync(dev);
1935 static irqreturn_t tegra_pcie_ep_pex_rst_irq(int irq, void *arg)
1937 struct tegra_pcie_dw *pcie = arg;
1939 if (gpiod_get_value(pcie->pex_rst_gpiod))
1940 pex_ep_event_pex_rst_assert(pcie);
1942 pex_ep_event_pex_rst_deassert(pcie);
1947 static int tegra_pcie_ep_raise_intx_irq(struct tegra_pcie_dw *pcie, u16 irq)
1949 /* Tegra194 supports only INTA */
1953 appl_writel(pcie, 1, APPL_LEGACY_INTX);
1954 usleep_range(1000, 2000);
1955 appl_writel(pcie, 0, APPL_LEGACY_INTX);
1959 static int tegra_pcie_ep_raise_msi_irq(struct tegra_pcie_dw *pcie, u16 irq)
1961 if (unlikely(irq > 31))
1964 appl_writel(pcie, BIT(irq), APPL_MSI_CTRL_1);
1969 static int tegra_pcie_ep_raise_msix_irq(struct tegra_pcie_dw *pcie, u16 irq)
1971 struct dw_pcie_ep *ep = &pcie->pci.ep;
1973 writel(irq, ep->msi_mem);
1978 static int tegra_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no,
1979 unsigned int type, u16 interrupt_num)
1981 struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
1982 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci);
1986 return tegra_pcie_ep_raise_intx_irq(pcie, interrupt_num);
1989 return tegra_pcie_ep_raise_msi_irq(pcie, interrupt_num);
1992 return tegra_pcie_ep_raise_msix_irq(pcie, interrupt_num);
1995 dev_err(pci->dev, "Unknown IRQ type\n");
2002 static const struct pci_epc_features tegra_pcie_epc_features = {
2003 .linkup_notifier = true,
2004 .msi_capable = false,
2005 .msix_capable = false,
2006 .bar[BAR_0] = { .type = BAR_FIXED, .fixed_size = SZ_1M,
2007 .only_64bit = true, },
2008 .bar[BAR_1] = { .type = BAR_RESERVED, },
2009 .bar[BAR_2] = { .type = BAR_RESERVED, },
2010 .bar[BAR_3] = { .type = BAR_RESERVED, },
2011 .bar[BAR_4] = { .type = BAR_RESERVED, },
2012 .bar[BAR_5] = { .type = BAR_RESERVED, },
2016 static const struct pci_epc_features*
2017 tegra_pcie_ep_get_features(struct dw_pcie_ep *ep)
2019 return &tegra_pcie_epc_features;
2022 static const struct dw_pcie_ep_ops pcie_ep_ops = {
2023 .raise_irq = tegra_pcie_ep_raise_irq,
2024 .get_features = tegra_pcie_ep_get_features,
2027 static int tegra_pcie_config_ep(struct tegra_pcie_dw *pcie,
2028 struct platform_device *pdev)
2030 struct dw_pcie *pci = &pcie->pci;
2031 struct device *dev = pcie->dev;
2032 struct dw_pcie_ep *ep;
2037 ep->ops = &pcie_ep_ops;
2039 ep->page_size = SZ_64K;
2041 ret = gpiod_set_debounce(pcie->pex_rst_gpiod, PERST_DEBOUNCE_TIME);
2043 dev_err(dev, "Failed to set PERST GPIO debounce time: %d\n",
2048 ret = gpiod_to_irq(pcie->pex_rst_gpiod);
2050 dev_err(dev, "Failed to get IRQ for PERST GPIO: %d\n", ret);
2053 pcie->pex_rst_irq = (unsigned int)ret;
2055 name = devm_kasprintf(dev, GFP_KERNEL, "tegra_pcie_%u_pex_rst_irq",
2058 dev_err(dev, "Failed to create PERST IRQ string\n");
2062 irq_set_status_flags(pcie->pex_rst_irq, IRQ_NOAUTOEN);
2064 pcie->ep_state = EP_STATE_DISABLED;
2066 ret = devm_request_threaded_irq(dev, pcie->pex_rst_irq, NULL,
2067 tegra_pcie_ep_pex_rst_irq,
2068 IRQF_TRIGGER_RISING |
2069 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
2070 name, (void *)pcie);
2072 dev_err(dev, "Failed to request IRQ for PERST: %d\n", ret);
2076 pm_runtime_enable(dev);
2078 ret = dw_pcie_ep_init(ep);
2080 dev_err(dev, "Failed to initialize DWC Endpoint subsystem: %d\n",
2082 pm_runtime_disable(dev);
2089 static int tegra_pcie_dw_probe(struct platform_device *pdev)
2091 const struct tegra_pcie_dw_of_data *data;
2092 struct device *dev = &pdev->dev;
2093 struct resource *atu_dma_res;
2094 struct tegra_pcie_dw *pcie;
2095 struct dw_pcie_rp *pp;
2096 struct dw_pcie *pci;
2102 data = of_device_get_match_data(dev);
2104 pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL);
2109 pci->dev = &pdev->dev;
2110 pci->ops = &tegra_dw_pcie_ops;
2111 pcie->dev = &pdev->dev;
2112 pcie->of_data = (struct tegra_pcie_dw_of_data *)data;
2113 pci->n_fts[0] = pcie->of_data->n_fts[0];
2114 pci->n_fts[1] = pcie->of_data->n_fts[1];
2116 pp->num_vectors = MAX_MSI_IRQS;
2118 ret = tegra_pcie_dw_parse_dt(pcie);
2120 const char *level = KERN_ERR;
2122 if (ret == -EPROBE_DEFER)
2125 dev_printk(level, dev,
2126 dev_fmt("Failed to parse device tree: %d\n"),
2131 ret = tegra_pcie_get_slot_regulators(pcie);
2133 const char *level = KERN_ERR;
2135 if (ret == -EPROBE_DEFER)
2138 dev_printk(level, dev,
2139 dev_fmt("Failed to get slot regulators: %d\n"),
2144 if (pcie->pex_refclk_sel_gpiod)
2145 gpiod_set_value(pcie->pex_refclk_sel_gpiod, 1);
2147 pcie->pex_ctl_supply = devm_regulator_get(dev, "vddio-pex-ctl");
2148 if (IS_ERR(pcie->pex_ctl_supply)) {
2149 ret = PTR_ERR(pcie->pex_ctl_supply);
2150 if (ret != -EPROBE_DEFER)
2151 dev_err(dev, "Failed to get regulator: %ld\n",
2152 PTR_ERR(pcie->pex_ctl_supply));
2156 pcie->core_clk = devm_clk_get(dev, "core");
2157 if (IS_ERR(pcie->core_clk)) {
2158 dev_err(dev, "Failed to get core clock: %ld\n",
2159 PTR_ERR(pcie->core_clk));
2160 return PTR_ERR(pcie->core_clk);
2163 pcie->appl_res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
2165 if (!pcie->appl_res) {
2166 dev_err(dev, "Failed to find \"appl\" region\n");
2170 pcie->appl_base = devm_ioremap_resource(dev, pcie->appl_res);
2171 if (IS_ERR(pcie->appl_base))
2172 return PTR_ERR(pcie->appl_base);
2174 pcie->core_apb_rst = devm_reset_control_get(dev, "apb");
2175 if (IS_ERR(pcie->core_apb_rst)) {
2176 dev_err(dev, "Failed to get APB reset: %ld\n",
2177 PTR_ERR(pcie->core_apb_rst));
2178 return PTR_ERR(pcie->core_apb_rst);
2181 phys = devm_kcalloc(dev, pcie->phy_count, sizeof(*phys), GFP_KERNEL);
2185 for (i = 0; i < pcie->phy_count; i++) {
2186 name = kasprintf(GFP_KERNEL, "p2u-%u", i);
2188 dev_err(dev, "Failed to create P2U string\n");
2191 phys[i] = devm_phy_get(dev, name);
2193 if (IS_ERR(phys[i])) {
2194 ret = PTR_ERR(phys[i]);
2195 if (ret != -EPROBE_DEFER)
2196 dev_err(dev, "Failed to get PHY: %d\n", ret);
2203 atu_dma_res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
2206 dev_err(dev, "Failed to find \"atu_dma\" region\n");
2209 pcie->atu_dma_res = atu_dma_res;
2211 pci->atu_size = resource_size(atu_dma_res);
2212 pci->atu_base = devm_ioremap_resource(dev, atu_dma_res);
2213 if (IS_ERR(pci->atu_base))
2214 return PTR_ERR(pci->atu_base);
2216 pcie->core_rst = devm_reset_control_get(dev, "core");
2217 if (IS_ERR(pcie->core_rst)) {
2218 dev_err(dev, "Failed to get core reset: %ld\n",
2219 PTR_ERR(pcie->core_rst));
2220 return PTR_ERR(pcie->core_rst);
2223 pp->irq = platform_get_irq_byname(pdev, "intr");
2227 pcie->bpmp = tegra_bpmp_get(dev);
2228 if (IS_ERR(pcie->bpmp))
2229 return PTR_ERR(pcie->bpmp);
2231 platform_set_drvdata(pdev, pcie);
2233 pcie->icc_path = devm_of_icc_get(&pdev->dev, "write");
2234 ret = PTR_ERR_OR_ZERO(pcie->icc_path);
2236 tegra_bpmp_put(pcie->bpmp);
2237 dev_err_probe(&pdev->dev, ret, "failed to get write interconnect\n");
2241 switch (pcie->of_data->mode) {
2242 case DW_PCIE_RC_TYPE:
2243 ret = devm_request_irq(dev, pp->irq, tegra_pcie_rp_irq_handler,
2244 IRQF_SHARED, "tegra-pcie-intr", pcie);
2246 dev_err(dev, "Failed to request IRQ %d: %d\n", pp->irq,
2251 ret = tegra_pcie_config_rp(pcie);
2252 if (ret && ret != -ENOMEDIUM)
2258 case DW_PCIE_EP_TYPE:
2259 ret = devm_request_threaded_irq(dev, pp->irq,
2260 tegra_pcie_ep_hard_irq,
2261 tegra_pcie_ep_irq_thread,
2262 IRQF_SHARED | IRQF_ONESHOT,
2263 "tegra-pcie-ep-intr", pcie);
2265 dev_err(dev, "Failed to request IRQ %d: %d\n", pp->irq,
2270 ret = tegra_pcie_config_ep(pcie, pdev);
2278 dev_err(dev, "Invalid PCIe device type %d\n",
2279 pcie->of_data->mode);
2284 tegra_bpmp_put(pcie->bpmp);
2288 static void tegra_pcie_dw_remove(struct platform_device *pdev)
2290 struct tegra_pcie_dw *pcie = platform_get_drvdata(pdev);
2292 if (pcie->of_data->mode == DW_PCIE_RC_TYPE) {
2293 if (!pcie->link_state)
2296 debugfs_remove_recursive(pcie->debugfs);
2297 tegra_pcie_deinit_controller(pcie);
2298 pm_runtime_put_sync(pcie->dev);
2300 disable_irq(pcie->pex_rst_irq);
2301 pex_ep_event_pex_rst_assert(pcie);
2304 pm_runtime_disable(pcie->dev);
2305 tegra_bpmp_put(pcie->bpmp);
2306 if (pcie->pex_refclk_sel_gpiod)
2307 gpiod_set_value(pcie->pex_refclk_sel_gpiod, 0);
2310 static int tegra_pcie_dw_suspend_late(struct device *dev)
2312 struct tegra_pcie_dw *pcie = dev_get_drvdata(dev);
2315 if (pcie->of_data->mode == DW_PCIE_EP_TYPE) {
2316 dev_err(dev, "Failed to Suspend as Tegra PCIe is in EP mode\n");
2320 if (!pcie->link_state)
2323 /* Enable HW_HOT_RST mode */
2324 if (!pcie->of_data->has_sbr_reset_fix) {
2325 val = appl_readl(pcie, APPL_CTRL);
2326 val &= ~(APPL_CTRL_HW_HOT_RST_MODE_MASK <<
2327 APPL_CTRL_HW_HOT_RST_MODE_SHIFT);
2328 val |= APPL_CTRL_HW_HOT_RST_EN;
2329 appl_writel(pcie, val, APPL_CTRL);
2335 static int tegra_pcie_dw_suspend_noirq(struct device *dev)
2337 struct tegra_pcie_dw *pcie = dev_get_drvdata(dev);
2339 if (!pcie->link_state)
2342 tegra_pcie_downstream_dev_to_D0(pcie);
2343 tegra_pcie_dw_pme_turnoff(pcie);
2344 tegra_pcie_unconfig_controller(pcie);
2349 static int tegra_pcie_dw_resume_noirq(struct device *dev)
2351 struct tegra_pcie_dw *pcie = dev_get_drvdata(dev);
2354 if (!pcie->link_state)
2357 ret = tegra_pcie_config_controller(pcie, true);
2361 ret = tegra_pcie_dw_host_init(&pcie->pci.pp);
2363 dev_err(dev, "Failed to init host: %d\n", ret);
2364 goto fail_host_init;
2367 dw_pcie_setup_rc(&pcie->pci.pp);
2369 ret = tegra_pcie_dw_start_link(&pcie->pci);
2371 goto fail_host_init;
2376 tegra_pcie_unconfig_controller(pcie);
2380 static int tegra_pcie_dw_resume_early(struct device *dev)
2382 struct tegra_pcie_dw *pcie = dev_get_drvdata(dev);
2385 if (pcie->of_data->mode == DW_PCIE_EP_TYPE) {
2386 dev_err(dev, "Suspend is not supported in EP mode");
2390 if (!pcie->link_state)
2393 /* Disable HW_HOT_RST mode */
2394 if (!pcie->of_data->has_sbr_reset_fix) {
2395 val = appl_readl(pcie, APPL_CTRL);
2396 val &= ~(APPL_CTRL_HW_HOT_RST_MODE_MASK <<
2397 APPL_CTRL_HW_HOT_RST_MODE_SHIFT);
2398 val |= APPL_CTRL_HW_HOT_RST_MODE_IMDT_RST <<
2399 APPL_CTRL_HW_HOT_RST_MODE_SHIFT;
2400 val &= ~APPL_CTRL_HW_HOT_RST_EN;
2401 appl_writel(pcie, val, APPL_CTRL);
2407 static void tegra_pcie_dw_shutdown(struct platform_device *pdev)
2409 struct tegra_pcie_dw *pcie = platform_get_drvdata(pdev);
2411 if (pcie->of_data->mode == DW_PCIE_RC_TYPE) {
2412 if (!pcie->link_state)
2415 debugfs_remove_recursive(pcie->debugfs);
2416 tegra_pcie_downstream_dev_to_D0(pcie);
2418 disable_irq(pcie->pci.pp.irq);
2419 if (IS_ENABLED(CONFIG_PCI_MSI))
2420 disable_irq(pcie->pci.pp.msi_irq[0]);
2422 tegra_pcie_dw_pme_turnoff(pcie);
2423 tegra_pcie_unconfig_controller(pcie);
2424 pm_runtime_put_sync(pcie->dev);
2426 disable_irq(pcie->pex_rst_irq);
2427 pex_ep_event_pex_rst_assert(pcie);
2431 static const struct tegra_pcie_dw_of_data tegra194_pcie_dw_rc_of_data = {
2432 .version = TEGRA194_DWC_IP_VER,
2433 .mode = DW_PCIE_RC_TYPE,
2434 .cdm_chk_int_en_bit = BIT(19),
2435 /* Gen4 - 5, 6, 8 and 9 presets enabled */
2436 .gen4_preset_vec = 0x360,
2437 .n_fts = { 52, 52 },
2440 static const struct tegra_pcie_dw_of_data tegra194_pcie_dw_ep_of_data = {
2441 .version = TEGRA194_DWC_IP_VER,
2442 .mode = DW_PCIE_EP_TYPE,
2443 .cdm_chk_int_en_bit = BIT(19),
2444 /* Gen4 - 5, 6, 8 and 9 presets enabled */
2445 .gen4_preset_vec = 0x360,
2446 .n_fts = { 52, 52 },
2449 static const struct tegra_pcie_dw_of_data tegra234_pcie_dw_rc_of_data = {
2450 .version = TEGRA234_DWC_IP_VER,
2451 .mode = DW_PCIE_RC_TYPE,
2452 .has_msix_doorbell_access_fix = true,
2453 .has_sbr_reset_fix = true,
2454 .has_l1ss_exit_fix = true,
2455 .cdm_chk_int_en_bit = BIT(18),
2456 /* Gen4 - 6, 8 and 9 presets enabled */
2457 .gen4_preset_vec = 0x340,
2458 .n_fts = { 52, 80 },
2461 static const struct tegra_pcie_dw_of_data tegra234_pcie_dw_ep_of_data = {
2462 .version = TEGRA234_DWC_IP_VER,
2463 .mode = DW_PCIE_EP_TYPE,
2464 .has_l1ss_exit_fix = true,
2465 .has_ltr_req_fix = true,
2466 .cdm_chk_int_en_bit = BIT(18),
2467 /* Gen4 - 6, 8 and 9 presets enabled */
2468 .gen4_preset_vec = 0x340,
2469 .n_fts = { 52, 80 },
2472 static const struct of_device_id tegra_pcie_dw_of_match[] = {
2474 .compatible = "nvidia,tegra194-pcie",
2475 .data = &tegra194_pcie_dw_rc_of_data,
2478 .compatible = "nvidia,tegra194-pcie-ep",
2479 .data = &tegra194_pcie_dw_ep_of_data,
2482 .compatible = "nvidia,tegra234-pcie",
2483 .data = &tegra234_pcie_dw_rc_of_data,
2486 .compatible = "nvidia,tegra234-pcie-ep",
2487 .data = &tegra234_pcie_dw_ep_of_data,
2492 static const struct dev_pm_ops tegra_pcie_dw_pm_ops = {
2493 .suspend_late = tegra_pcie_dw_suspend_late,
2494 .suspend_noirq = tegra_pcie_dw_suspend_noirq,
2495 .resume_noirq = tegra_pcie_dw_resume_noirq,
2496 .resume_early = tegra_pcie_dw_resume_early,
2499 static struct platform_driver tegra_pcie_dw_driver = {
2500 .probe = tegra_pcie_dw_probe,
2501 .remove_new = tegra_pcie_dw_remove,
2502 .shutdown = tegra_pcie_dw_shutdown,
2504 .name = "tegra194-pcie",
2505 .pm = &tegra_pcie_dw_pm_ops,
2506 .of_match_table = tegra_pcie_dw_of_match,
2509 module_platform_driver(tegra_pcie_dw_driver);
2511 MODULE_DEVICE_TABLE(of, tegra_pcie_dw_of_match);
2514 MODULE_DESCRIPTION("NVIDIA PCIe host controller driver");
2515 MODULE_LICENSE("GPL v2");