1 // SPDX-License-Identifier: GPL-2.0+
3 * PCIe host controller driver for Tegra SoCs
5 * Copyright (c) 2010, CompuLab, Ltd.
8 * Based on NVIDIA PCIe driver
9 * Copyright (c) 2008-2009, NVIDIA Corporation.
11 * Bits taken from arch/arm/mach-dove/pcie.c
16 #include <linux/clk.h>
17 #include <linux/debugfs.h>
18 #include <linux/delay.h>
19 #include <linux/export.h>
20 #include <linux/gpio/consumer.h>
21 #include <linux/interrupt.h>
22 #include <linux/iopoll.h>
23 #include <linux/irq.h>
24 #include <linux/irqdomain.h>
25 #include <linux/kernel.h>
26 #include <linux/init.h>
27 #include <linux/module.h>
28 #include <linux/msi.h>
29 #include <linux/of_address.h>
30 #include <linux/of_pci.h>
31 #include <linux/of_platform.h>
32 #include <linux/pci.h>
33 #include <linux/phy/phy.h>
34 #include <linux/pinctrl/consumer.h>
35 #include <linux/platform_device.h>
36 #include <linux/reset.h>
37 #include <linux/sizes.h>
38 #include <linux/slab.h>
39 #include <linux/vmalloc.h>
40 #include <linux/regulator/consumer.h>
42 #include <soc/tegra/cpuidle.h>
43 #include <soc/tegra/pmc.h>
47 #define INT_PCI_MSI_NR (8 * 32)
49 /* register definitions */
51 #define AFI_AXI_BAR0_SZ 0x00
52 #define AFI_AXI_BAR1_SZ 0x04
53 #define AFI_AXI_BAR2_SZ 0x08
54 #define AFI_AXI_BAR3_SZ 0x0c
55 #define AFI_AXI_BAR4_SZ 0x10
56 #define AFI_AXI_BAR5_SZ 0x14
58 #define AFI_AXI_BAR0_START 0x18
59 #define AFI_AXI_BAR1_START 0x1c
60 #define AFI_AXI_BAR2_START 0x20
61 #define AFI_AXI_BAR3_START 0x24
62 #define AFI_AXI_BAR4_START 0x28
63 #define AFI_AXI_BAR5_START 0x2c
65 #define AFI_FPCI_BAR0 0x30
66 #define AFI_FPCI_BAR1 0x34
67 #define AFI_FPCI_BAR2 0x38
68 #define AFI_FPCI_BAR3 0x3c
69 #define AFI_FPCI_BAR4 0x40
70 #define AFI_FPCI_BAR5 0x44
72 #define AFI_CACHE_BAR0_SZ 0x48
73 #define AFI_CACHE_BAR0_ST 0x4c
74 #define AFI_CACHE_BAR1_SZ 0x50
75 #define AFI_CACHE_BAR1_ST 0x54
77 #define AFI_MSI_BAR_SZ 0x60
78 #define AFI_MSI_FPCI_BAR_ST 0x64
79 #define AFI_MSI_AXI_BAR_ST 0x68
81 #define AFI_MSI_VEC0 0x6c
82 #define AFI_MSI_VEC1 0x70
83 #define AFI_MSI_VEC2 0x74
84 #define AFI_MSI_VEC3 0x78
85 #define AFI_MSI_VEC4 0x7c
86 #define AFI_MSI_VEC5 0x80
87 #define AFI_MSI_VEC6 0x84
88 #define AFI_MSI_VEC7 0x88
90 #define AFI_MSI_EN_VEC0 0x8c
91 #define AFI_MSI_EN_VEC1 0x90
92 #define AFI_MSI_EN_VEC2 0x94
93 #define AFI_MSI_EN_VEC3 0x98
94 #define AFI_MSI_EN_VEC4 0x9c
95 #define AFI_MSI_EN_VEC5 0xa0
96 #define AFI_MSI_EN_VEC6 0xa4
97 #define AFI_MSI_EN_VEC7 0xa8
99 #define AFI_CONFIGURATION 0xac
100 #define AFI_CONFIGURATION_EN_FPCI (1 << 0)
101 #define AFI_CONFIGURATION_CLKEN_OVERRIDE (1 << 31)
103 #define AFI_FPCI_ERROR_MASKS 0xb0
105 #define AFI_INTR_MASK 0xb4
106 #define AFI_INTR_MASK_INT_MASK (1 << 0)
107 #define AFI_INTR_MASK_MSI_MASK (1 << 8)
109 #define AFI_INTR_CODE 0xb8
110 #define AFI_INTR_CODE_MASK 0xf
111 #define AFI_INTR_INI_SLAVE_ERROR 1
112 #define AFI_INTR_INI_DECODE_ERROR 2
113 #define AFI_INTR_TARGET_ABORT 3
114 #define AFI_INTR_MASTER_ABORT 4
115 #define AFI_INTR_INVALID_WRITE 5
116 #define AFI_INTR_LEGACY 6
117 #define AFI_INTR_FPCI_DECODE_ERROR 7
118 #define AFI_INTR_AXI_DECODE_ERROR 8
119 #define AFI_INTR_FPCI_TIMEOUT 9
120 #define AFI_INTR_PE_PRSNT_SENSE 10
121 #define AFI_INTR_PE_CLKREQ_SENSE 11
122 #define AFI_INTR_CLKCLAMP_SENSE 12
123 #define AFI_INTR_RDY4PD_SENSE 13
124 #define AFI_INTR_P2P_ERROR 14
126 #define AFI_INTR_SIGNATURE 0xbc
127 #define AFI_UPPER_FPCI_ADDRESS 0xc0
128 #define AFI_SM_INTR_ENABLE 0xc4
129 #define AFI_SM_INTR_INTA_ASSERT (1 << 0)
130 #define AFI_SM_INTR_INTB_ASSERT (1 << 1)
131 #define AFI_SM_INTR_INTC_ASSERT (1 << 2)
132 #define AFI_SM_INTR_INTD_ASSERT (1 << 3)
133 #define AFI_SM_INTR_INTA_DEASSERT (1 << 4)
134 #define AFI_SM_INTR_INTB_DEASSERT (1 << 5)
135 #define AFI_SM_INTR_INTC_DEASSERT (1 << 6)
136 #define AFI_SM_INTR_INTD_DEASSERT (1 << 7)
138 #define AFI_AFI_INTR_ENABLE 0xc8
139 #define AFI_INTR_EN_INI_SLVERR (1 << 0)
140 #define AFI_INTR_EN_INI_DECERR (1 << 1)
141 #define AFI_INTR_EN_TGT_SLVERR (1 << 2)
142 #define AFI_INTR_EN_TGT_DECERR (1 << 3)
143 #define AFI_INTR_EN_TGT_WRERR (1 << 4)
144 #define AFI_INTR_EN_DFPCI_DECERR (1 << 5)
145 #define AFI_INTR_EN_AXI_DECERR (1 << 6)
146 #define AFI_INTR_EN_FPCI_TIMEOUT (1 << 7)
147 #define AFI_INTR_EN_PRSNT_SENSE (1 << 8)
149 #define AFI_PCIE_PME 0xf0
151 #define AFI_PCIE_CONFIG 0x0f8
152 #define AFI_PCIE_CONFIG_PCIE_DISABLE(x) (1 << ((x) + 1))
153 #define AFI_PCIE_CONFIG_PCIE_DISABLE_ALL 0xe
154 #define AFI_PCIE_CONFIG_SM2TMS0_XBAR_CONFIG_MASK (0xf << 20)
155 #define AFI_PCIE_CONFIG_SM2TMS0_XBAR_CONFIG_SINGLE (0x0 << 20)
156 #define AFI_PCIE_CONFIG_SM2TMS0_XBAR_CONFIG_420 (0x0 << 20)
157 #define AFI_PCIE_CONFIG_SM2TMS0_XBAR_CONFIG_X2_X1 (0x0 << 20)
158 #define AFI_PCIE_CONFIG_SM2TMS0_XBAR_CONFIG_401 (0x0 << 20)
159 #define AFI_PCIE_CONFIG_SM2TMS0_XBAR_CONFIG_DUAL (0x1 << 20)
160 #define AFI_PCIE_CONFIG_SM2TMS0_XBAR_CONFIG_222 (0x1 << 20)
161 #define AFI_PCIE_CONFIG_SM2TMS0_XBAR_CONFIG_X4_X1 (0x1 << 20)
162 #define AFI_PCIE_CONFIG_SM2TMS0_XBAR_CONFIG_211 (0x1 << 20)
163 #define AFI_PCIE_CONFIG_SM2TMS0_XBAR_CONFIG_411 (0x2 << 20)
164 #define AFI_PCIE_CONFIG_SM2TMS0_XBAR_CONFIG_111 (0x2 << 20)
165 #define AFI_PCIE_CONFIG_PCIE_CLKREQ_GPIO(x) (1 << ((x) + 29))
166 #define AFI_PCIE_CONFIG_PCIE_CLKREQ_GPIO_ALL (0x7 << 29)
168 #define AFI_FUSE 0x104
169 #define AFI_FUSE_PCIE_T0_GEN2_DIS (1 << 2)
171 #define AFI_PEX0_CTRL 0x110
172 #define AFI_PEX1_CTRL 0x118
173 #define AFI_PEX_CTRL_RST (1 << 0)
174 #define AFI_PEX_CTRL_CLKREQ_EN (1 << 1)
175 #define AFI_PEX_CTRL_REFCLK_EN (1 << 3)
176 #define AFI_PEX_CTRL_OVERRIDE_EN (1 << 4)
178 #define AFI_PLLE_CONTROL 0x160
179 #define AFI_PLLE_CONTROL_BYPASS_PADS2PLLE_CONTROL (1 << 9)
180 #define AFI_PLLE_CONTROL_PADS2PLLE_CONTROL_EN (1 << 1)
182 #define AFI_PEXBIAS_CTRL_0 0x168
184 #define RP_PRIV_XP_DL 0x00000494
185 #define RP_PRIV_XP_DL_GEN2_UPD_FC_TSHOLD (0x1ff << 1)
187 #define RP_RX_HDR_LIMIT 0x00000e00
188 #define RP_RX_HDR_LIMIT_PW_MASK (0xff << 8)
189 #define RP_RX_HDR_LIMIT_PW (0x0e << 8)
191 #define RP_ECTL_2_R1 0x00000e84
192 #define RP_ECTL_2_R1_RX_CTLE_1C_MASK 0xffff
194 #define RP_ECTL_4_R1 0x00000e8c
195 #define RP_ECTL_4_R1_RX_CDR_CTRL_1C_MASK (0xffff << 16)
196 #define RP_ECTL_4_R1_RX_CDR_CTRL_1C_SHIFT 16
198 #define RP_ECTL_5_R1 0x00000e90
199 #define RP_ECTL_5_R1_RX_EQ_CTRL_L_1C_MASK 0xffffffff
201 #define RP_ECTL_6_R1 0x00000e94
202 #define RP_ECTL_6_R1_RX_EQ_CTRL_H_1C_MASK 0xffffffff
204 #define RP_ECTL_2_R2 0x00000ea4
205 #define RP_ECTL_2_R2_RX_CTLE_1C_MASK 0xffff
207 #define RP_ECTL_4_R2 0x00000eac
208 #define RP_ECTL_4_R2_RX_CDR_CTRL_1C_MASK (0xffff << 16)
209 #define RP_ECTL_4_R2_RX_CDR_CTRL_1C_SHIFT 16
211 #define RP_ECTL_5_R2 0x00000eb0
212 #define RP_ECTL_5_R2_RX_EQ_CTRL_L_1C_MASK 0xffffffff
214 #define RP_ECTL_6_R2 0x00000eb4
215 #define RP_ECTL_6_R2_RX_EQ_CTRL_H_1C_MASK 0xffffffff
217 #define RP_VEND_XP 0x00000f00
218 #define RP_VEND_XP_DL_UP (1 << 30)
219 #define RP_VEND_XP_OPPORTUNISTIC_ACK (1 << 27)
220 #define RP_VEND_XP_OPPORTUNISTIC_UPDATEFC (1 << 28)
221 #define RP_VEND_XP_UPDATE_FC_THRESHOLD_MASK (0xff << 18)
223 #define RP_VEND_CTL0 0x00000f44
224 #define RP_VEND_CTL0_DSK_RST_PULSE_WIDTH_MASK (0xf << 12)
225 #define RP_VEND_CTL0_DSK_RST_PULSE_WIDTH (0x9 << 12)
227 #define RP_VEND_CTL1 0x00000f48
228 #define RP_VEND_CTL1_ERPT (1 << 13)
230 #define RP_VEND_XP_BIST 0x00000f4c
231 #define RP_VEND_XP_BIST_GOTO_L1_L2_AFTER_DLLP_DONE (1 << 28)
233 #define RP_VEND_CTL2 0x00000fa8
234 #define RP_VEND_CTL2_PCA_ENABLE (1 << 7)
236 #define RP_PRIV_MISC 0x00000fe0
237 #define RP_PRIV_MISC_PRSNT_MAP_EP_PRSNT (0xe << 0)
238 #define RP_PRIV_MISC_PRSNT_MAP_EP_ABSNT (0xf << 0)
239 #define RP_PRIV_MISC_CTLR_CLK_CLAMP_THRESHOLD_MASK (0x7f << 16)
240 #define RP_PRIV_MISC_CTLR_CLK_CLAMP_THRESHOLD (0xf << 16)
241 #define RP_PRIV_MISC_CTLR_CLK_CLAMP_ENABLE (1 << 23)
242 #define RP_PRIV_MISC_TMS_CLK_CLAMP_THRESHOLD_MASK (0x7f << 24)
243 #define RP_PRIV_MISC_TMS_CLK_CLAMP_THRESHOLD (0xf << 24)
244 #define RP_PRIV_MISC_TMS_CLK_CLAMP_ENABLE (1 << 31)
246 #define RP_LINK_CONTROL_STATUS 0x00000090
247 #define RP_LINK_CONTROL_STATUS_DL_LINK_ACTIVE 0x20000000
248 #define RP_LINK_CONTROL_STATUS_LINKSTAT_MASK 0x3fff0000
250 #define RP_LINK_CONTROL_STATUS_2 0x000000b0
252 #define PADS_CTL_SEL 0x0000009c
254 #define PADS_CTL 0x000000a0
255 #define PADS_CTL_IDDQ_1L (1 << 0)
256 #define PADS_CTL_TX_DATA_EN_1L (1 << 6)
257 #define PADS_CTL_RX_DATA_EN_1L (1 << 10)
259 #define PADS_PLL_CTL_TEGRA20 0x000000b8
260 #define PADS_PLL_CTL_TEGRA30 0x000000b4
261 #define PADS_PLL_CTL_RST_B4SM (1 << 1)
262 #define PADS_PLL_CTL_LOCKDET (1 << 8)
263 #define PADS_PLL_CTL_REFCLK_MASK (0x3 << 16)
264 #define PADS_PLL_CTL_REFCLK_INTERNAL_CML (0 << 16)
265 #define PADS_PLL_CTL_REFCLK_INTERNAL_CMOS (1 << 16)
266 #define PADS_PLL_CTL_REFCLK_EXTERNAL (2 << 16)
267 #define PADS_PLL_CTL_TXCLKREF_MASK (0x1 << 20)
268 #define PADS_PLL_CTL_TXCLKREF_DIV10 (0 << 20)
269 #define PADS_PLL_CTL_TXCLKREF_DIV5 (1 << 20)
270 #define PADS_PLL_CTL_TXCLKREF_BUF_EN (1 << 22)
272 #define PADS_REFCLK_CFG0 0x000000c8
273 #define PADS_REFCLK_CFG1 0x000000cc
274 #define PADS_REFCLK_BIAS 0x000000d0
277 * Fields in PADS_REFCLK_CFG*. Those registers form an array of 16-bit
278 * entries, one entry per PCIe port. These field definitions and desired
279 * values aren't in the TRM, but do come from NVIDIA.
281 #define PADS_REFCLK_CFG_TERM_SHIFT 2 /* 6:2 */
282 #define PADS_REFCLK_CFG_E_TERM_SHIFT 7
283 #define PADS_REFCLK_CFG_PREDI_SHIFT 8 /* 11:8 */
284 #define PADS_REFCLK_CFG_DRVI_SHIFT 12 /* 15:12 */
286 #define PME_ACK_TIMEOUT 10000
287 #define LINK_RETRAIN_TIMEOUT 100000 /* in usec */
290 struct msi_controller chip;
291 DECLARE_BITMAP(used, INT_PCI_MSI_NR);
292 struct irq_domain *domain;
299 /* used to differentiate between Tegra SoC generations */
300 struct tegra_pcie_port_soc {
307 struct tegra_pcie_soc {
308 unsigned int num_ports;
309 const struct tegra_pcie_port_soc *ports;
310 unsigned int msi_base_shift;
311 unsigned long afi_pex2_ctrl;
314 u32 pads_refclk_cfg0;
315 u32 pads_refclk_cfg1;
316 u32 update_fc_threshold;
317 bool has_pex_clkreq_en;
318 bool has_pex_bias_ctrl;
319 bool has_intr_prsnt_sense;
322 bool force_pca_enable;
324 bool update_clamp_threshold;
325 bool program_deskew_time;
326 bool raw_violation_fixup;
327 bool update_fc_timer;
344 static inline struct tegra_msi *to_tegra_msi(struct msi_controller *chip)
346 return container_of(chip, struct tegra_msi, chip);
364 struct reset_control *pex_rst;
365 struct reset_control *afi_rst;
366 struct reset_control *pcie_xrst;
371 struct tegra_msi msi;
373 struct list_head ports;
376 struct regulator_bulk_data *supplies;
377 unsigned int num_supplies;
379 const struct tegra_pcie_soc *soc;
380 struct dentry *debugfs;
383 struct tegra_pcie_port {
384 struct tegra_pcie *pcie;
385 struct device_node *np;
386 struct list_head list;
387 struct resource regs;
394 struct gpio_desc *reset_gpio;
397 struct tegra_pcie_bus {
398 struct list_head list;
402 static inline void afi_writel(struct tegra_pcie *pcie, u32 value,
403 unsigned long offset)
405 writel(value, pcie->afi + offset);
408 static inline u32 afi_readl(struct tegra_pcie *pcie, unsigned long offset)
410 return readl(pcie->afi + offset);
413 static inline void pads_writel(struct tegra_pcie *pcie, u32 value,
414 unsigned long offset)
416 writel(value, pcie->pads + offset);
419 static inline u32 pads_readl(struct tegra_pcie *pcie, unsigned long offset)
421 return readl(pcie->pads + offset);
425 * The configuration space mapping on Tegra is somewhat similar to the ECAM
426 * defined by PCIe. However it deviates a bit in how the 4 bits for extended
427 * register accesses are mapped:
429 * [27:24] extended register number
431 * [15:11] device number
432 * [10: 8] function number
433 * [ 7: 0] register number
435 * Mapping the whole extended configuration space would require 256 MiB of
436 * virtual address space, only a small part of which will actually be used.
438 * To work around this, a 4 KiB region is used to generate the required
439 * configuration transaction with relevant B:D:F and register offset values.
440 * This is achieved by dynamically programming base address and size of
441 * AFI_AXI_BAR used for end point config space mapping to make sure that the
442 * address (access to which generates correct config transaction) falls in
445 static unsigned int tegra_pcie_conf_offset(u8 bus, unsigned int devfn,
448 return ((where & 0xf00) << 16) | (bus << 16) | (PCI_SLOT(devfn) << 11) |
449 (PCI_FUNC(devfn) << 8) | (where & 0xff);
452 static void __iomem *tegra_pcie_map_bus(struct pci_bus *bus,
456 struct tegra_pcie *pcie = bus->sysdata;
457 void __iomem *addr = NULL;
459 if (bus->number == 0) {
460 unsigned int slot = PCI_SLOT(devfn);
461 struct tegra_pcie_port *port;
463 list_for_each_entry(port, &pcie->ports, list) {
464 if (port->index + 1 == slot) {
465 addr = port->base + (where & ~3);
473 offset = tegra_pcie_conf_offset(bus->number, devfn, where);
475 /* move 4 KiB window to offset within the FPCI region */
476 base = 0xfe100000 + ((offset & ~(SZ_4K - 1)) >> 8);
477 afi_writel(pcie, base, AFI_FPCI_BAR0);
479 /* move to correct offset within the 4 KiB page */
480 addr = pcie->cfg + (offset & (SZ_4K - 1));
486 static int tegra_pcie_config_read(struct pci_bus *bus, unsigned int devfn,
487 int where, int size, u32 *value)
489 if (bus->number == 0)
490 return pci_generic_config_read32(bus, devfn, where, size,
493 return pci_generic_config_read(bus, devfn, where, size, value);
496 static int tegra_pcie_config_write(struct pci_bus *bus, unsigned int devfn,
497 int where, int size, u32 value)
499 if (bus->number == 0)
500 return pci_generic_config_write32(bus, devfn, where, size,
503 return pci_generic_config_write(bus, devfn, where, size, value);
506 static struct pci_ops tegra_pcie_ops = {
507 .map_bus = tegra_pcie_map_bus,
508 .read = tegra_pcie_config_read,
509 .write = tegra_pcie_config_write,
512 static unsigned long tegra_pcie_port_get_pex_ctrl(struct tegra_pcie_port *port)
514 const struct tegra_pcie_soc *soc = port->pcie->soc;
515 unsigned long ret = 0;
517 switch (port->index) {
527 ret = soc->afi_pex2_ctrl;
534 static void tegra_pcie_port_reset(struct tegra_pcie_port *port)
536 unsigned long ctrl = tegra_pcie_port_get_pex_ctrl(port);
539 /* pulse reset signal */
540 if (port->reset_gpio) {
541 gpiod_set_value(port->reset_gpio, 1);
543 value = afi_readl(port->pcie, ctrl);
544 value &= ~AFI_PEX_CTRL_RST;
545 afi_writel(port->pcie, value, ctrl);
548 usleep_range(1000, 2000);
550 if (port->reset_gpio) {
551 gpiod_set_value(port->reset_gpio, 0);
553 value = afi_readl(port->pcie, ctrl);
554 value |= AFI_PEX_CTRL_RST;
555 afi_writel(port->pcie, value, ctrl);
559 static void tegra_pcie_enable_rp_features(struct tegra_pcie_port *port)
561 const struct tegra_pcie_soc *soc = port->pcie->soc;
564 /* Enable AER capability */
565 value = readl(port->base + RP_VEND_CTL1);
566 value |= RP_VEND_CTL1_ERPT;
567 writel(value, port->base + RP_VEND_CTL1);
569 /* Optimal settings to enhance bandwidth */
570 value = readl(port->base + RP_VEND_XP);
571 value |= RP_VEND_XP_OPPORTUNISTIC_ACK;
572 value |= RP_VEND_XP_OPPORTUNISTIC_UPDATEFC;
573 writel(value, port->base + RP_VEND_XP);
576 * LTSSM will wait for DLLP to finish before entering L1 or L2,
577 * to avoid truncation of PM messages which results in receiver errors
579 value = readl(port->base + RP_VEND_XP_BIST);
580 value |= RP_VEND_XP_BIST_GOTO_L1_L2_AFTER_DLLP_DONE;
581 writel(value, port->base + RP_VEND_XP_BIST);
583 value = readl(port->base + RP_PRIV_MISC);
584 value |= RP_PRIV_MISC_CTLR_CLK_CLAMP_ENABLE;
585 value |= RP_PRIV_MISC_TMS_CLK_CLAMP_ENABLE;
587 if (soc->update_clamp_threshold) {
588 value &= ~(RP_PRIV_MISC_CTLR_CLK_CLAMP_THRESHOLD_MASK |
589 RP_PRIV_MISC_TMS_CLK_CLAMP_THRESHOLD_MASK);
590 value |= RP_PRIV_MISC_CTLR_CLK_CLAMP_THRESHOLD |
591 RP_PRIV_MISC_TMS_CLK_CLAMP_THRESHOLD;
594 writel(value, port->base + RP_PRIV_MISC);
597 static void tegra_pcie_program_ectl_settings(struct tegra_pcie_port *port)
599 const struct tegra_pcie_soc *soc = port->pcie->soc;
602 value = readl(port->base + RP_ECTL_2_R1);
603 value &= ~RP_ECTL_2_R1_RX_CTLE_1C_MASK;
604 value |= soc->ectl.regs.rp_ectl_2_r1;
605 writel(value, port->base + RP_ECTL_2_R1);
607 value = readl(port->base + RP_ECTL_4_R1);
608 value &= ~RP_ECTL_4_R1_RX_CDR_CTRL_1C_MASK;
609 value |= soc->ectl.regs.rp_ectl_4_r1 <<
610 RP_ECTL_4_R1_RX_CDR_CTRL_1C_SHIFT;
611 writel(value, port->base + RP_ECTL_4_R1);
613 value = readl(port->base + RP_ECTL_5_R1);
614 value &= ~RP_ECTL_5_R1_RX_EQ_CTRL_L_1C_MASK;
615 value |= soc->ectl.regs.rp_ectl_5_r1;
616 writel(value, port->base + RP_ECTL_5_R1);
618 value = readl(port->base + RP_ECTL_6_R1);
619 value &= ~RP_ECTL_6_R1_RX_EQ_CTRL_H_1C_MASK;
620 value |= soc->ectl.regs.rp_ectl_6_r1;
621 writel(value, port->base + RP_ECTL_6_R1);
623 value = readl(port->base + RP_ECTL_2_R2);
624 value &= ~RP_ECTL_2_R2_RX_CTLE_1C_MASK;
625 value |= soc->ectl.regs.rp_ectl_2_r2;
626 writel(value, port->base + RP_ECTL_2_R2);
628 value = readl(port->base + RP_ECTL_4_R2);
629 value &= ~RP_ECTL_4_R2_RX_CDR_CTRL_1C_MASK;
630 value |= soc->ectl.regs.rp_ectl_4_r2 <<
631 RP_ECTL_4_R2_RX_CDR_CTRL_1C_SHIFT;
632 writel(value, port->base + RP_ECTL_4_R2);
634 value = readl(port->base + RP_ECTL_5_R2);
635 value &= ~RP_ECTL_5_R2_RX_EQ_CTRL_L_1C_MASK;
636 value |= soc->ectl.regs.rp_ectl_5_r2;
637 writel(value, port->base + RP_ECTL_5_R2);
639 value = readl(port->base + RP_ECTL_6_R2);
640 value &= ~RP_ECTL_6_R2_RX_EQ_CTRL_H_1C_MASK;
641 value |= soc->ectl.regs.rp_ectl_6_r2;
642 writel(value, port->base + RP_ECTL_6_R2);
645 static void tegra_pcie_apply_sw_fixup(struct tegra_pcie_port *port)
647 const struct tegra_pcie_soc *soc = port->pcie->soc;
651 * Sometimes link speed change from Gen2 to Gen1 fails due to
652 * instability in deskew logic on lane-0. Increase the deskew
653 * retry time to resolve this issue.
655 if (soc->program_deskew_time) {
656 value = readl(port->base + RP_VEND_CTL0);
657 value &= ~RP_VEND_CTL0_DSK_RST_PULSE_WIDTH_MASK;
658 value |= RP_VEND_CTL0_DSK_RST_PULSE_WIDTH;
659 writel(value, port->base + RP_VEND_CTL0);
662 /* Fixup for read after write violation. */
663 if (soc->raw_violation_fixup) {
664 value = readl(port->base + RP_RX_HDR_LIMIT);
665 value &= ~RP_RX_HDR_LIMIT_PW_MASK;
666 value |= RP_RX_HDR_LIMIT_PW;
667 writel(value, port->base + RP_RX_HDR_LIMIT);
669 value = readl(port->base + RP_PRIV_XP_DL);
670 value |= RP_PRIV_XP_DL_GEN2_UPD_FC_TSHOLD;
671 writel(value, port->base + RP_PRIV_XP_DL);
673 value = readl(port->base + RP_VEND_XP);
674 value &= ~RP_VEND_XP_UPDATE_FC_THRESHOLD_MASK;
675 value |= soc->update_fc_threshold;
676 writel(value, port->base + RP_VEND_XP);
679 if (soc->update_fc_timer) {
680 value = readl(port->base + RP_VEND_XP);
681 value &= ~RP_VEND_XP_UPDATE_FC_THRESHOLD_MASK;
682 value |= soc->update_fc_threshold;
683 writel(value, port->base + RP_VEND_XP);
687 * PCIe link doesn't come up with few legacy PCIe endpoints if
688 * root port advertises both Gen-1 and Gen-2 speeds in Tegra.
689 * Hence, the strategy followed here is to initially advertise
690 * only Gen-1 and after link is up, retrain link to Gen-2 speed
692 value = readl(port->base + RP_LINK_CONTROL_STATUS_2);
693 value &= ~PCI_EXP_LNKSTA_CLS;
694 value |= PCI_EXP_LNKSTA_CLS_2_5GB;
695 writel(value, port->base + RP_LINK_CONTROL_STATUS_2);
698 static void tegra_pcie_port_enable(struct tegra_pcie_port *port)
700 unsigned long ctrl = tegra_pcie_port_get_pex_ctrl(port);
701 const struct tegra_pcie_soc *soc = port->pcie->soc;
704 /* enable reference clock */
705 value = afi_readl(port->pcie, ctrl);
706 value |= AFI_PEX_CTRL_REFCLK_EN;
708 if (soc->has_pex_clkreq_en)
709 value |= AFI_PEX_CTRL_CLKREQ_EN;
711 value |= AFI_PEX_CTRL_OVERRIDE_EN;
713 afi_writel(port->pcie, value, ctrl);
715 tegra_pcie_port_reset(port);
717 if (soc->force_pca_enable) {
718 value = readl(port->base + RP_VEND_CTL2);
719 value |= RP_VEND_CTL2_PCA_ENABLE;
720 writel(value, port->base + RP_VEND_CTL2);
723 tegra_pcie_enable_rp_features(port);
725 if (soc->ectl.enable)
726 tegra_pcie_program_ectl_settings(port);
728 tegra_pcie_apply_sw_fixup(port);
731 static void tegra_pcie_port_disable(struct tegra_pcie_port *port)
733 unsigned long ctrl = tegra_pcie_port_get_pex_ctrl(port);
734 const struct tegra_pcie_soc *soc = port->pcie->soc;
737 /* assert port reset */
738 value = afi_readl(port->pcie, ctrl);
739 value &= ~AFI_PEX_CTRL_RST;
740 afi_writel(port->pcie, value, ctrl);
742 /* disable reference clock */
743 value = afi_readl(port->pcie, ctrl);
745 if (soc->has_pex_clkreq_en)
746 value &= ~AFI_PEX_CTRL_CLKREQ_EN;
748 value &= ~AFI_PEX_CTRL_REFCLK_EN;
749 afi_writel(port->pcie, value, ctrl);
751 /* disable PCIe port and set CLKREQ# as GPIO to allow PLLE power down */
752 value = afi_readl(port->pcie, AFI_PCIE_CONFIG);
753 value |= AFI_PCIE_CONFIG_PCIE_DISABLE(port->index);
754 value |= AFI_PCIE_CONFIG_PCIE_CLKREQ_GPIO(port->index);
755 afi_writel(port->pcie, value, AFI_PCIE_CONFIG);
758 static void tegra_pcie_port_free(struct tegra_pcie_port *port)
760 struct tegra_pcie *pcie = port->pcie;
761 struct device *dev = pcie->dev;
763 devm_iounmap(dev, port->base);
764 devm_release_mem_region(dev, port->regs.start,
765 resource_size(&port->regs));
766 list_del(&port->list);
767 devm_kfree(dev, port);
770 /* Tegra PCIE root complex wrongly reports device class */
771 static void tegra_pcie_fixup_class(struct pci_dev *dev)
773 dev->class = PCI_CLASS_BRIDGE_PCI << 8;
775 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_NVIDIA, 0x0bf0, tegra_pcie_fixup_class);
776 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_NVIDIA, 0x0bf1, tegra_pcie_fixup_class);
777 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_NVIDIA, 0x0e1c, tegra_pcie_fixup_class);
778 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_NVIDIA, 0x0e1d, tegra_pcie_fixup_class);
780 /* Tegra20 and Tegra30 PCIE requires relaxed ordering */
781 static void tegra_pcie_relax_enable(struct pci_dev *dev)
783 pcie_capability_set_word(dev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_RELAX_EN);
785 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NVIDIA, 0x0bf0, tegra_pcie_relax_enable);
786 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NVIDIA, 0x0bf1, tegra_pcie_relax_enable);
787 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NVIDIA, 0x0e1c, tegra_pcie_relax_enable);
788 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NVIDIA, 0x0e1d, tegra_pcie_relax_enable);
790 static int tegra_pcie_map_irq(const struct pci_dev *pdev, u8 slot, u8 pin)
792 struct tegra_pcie *pcie = pdev->bus->sysdata;
795 tegra_cpuidle_pcie_irqs_in_use();
797 irq = of_irq_parse_and_map_pci(pdev, slot, pin);
804 static irqreturn_t tegra_pcie_isr(int irq, void *arg)
806 const char *err_msg[] = {
814 "Response decoding error",
815 "AXI response decoding error",
816 "Transaction timeout",
817 "Slot present pin change",
818 "Slot clock request change",
819 "TMS clock ramp change",
820 "TMS ready for power down",
823 struct tegra_pcie *pcie = arg;
824 struct device *dev = pcie->dev;
827 code = afi_readl(pcie, AFI_INTR_CODE) & AFI_INTR_CODE_MASK;
828 signature = afi_readl(pcie, AFI_INTR_SIGNATURE);
829 afi_writel(pcie, 0, AFI_INTR_CODE);
831 if (code == AFI_INTR_LEGACY)
834 if (code >= ARRAY_SIZE(err_msg))
838 * do not pollute kernel log with master abort reports since they
839 * happen a lot during enumeration
841 if (code == AFI_INTR_MASTER_ABORT || code == AFI_INTR_PE_PRSNT_SENSE)
842 dev_dbg(dev, "%s, signature: %08x\n", err_msg[code], signature);
844 dev_err(dev, "%s, signature: %08x\n", err_msg[code], signature);
846 if (code == AFI_INTR_TARGET_ABORT || code == AFI_INTR_MASTER_ABORT ||
847 code == AFI_INTR_FPCI_DECODE_ERROR) {
848 u32 fpci = afi_readl(pcie, AFI_UPPER_FPCI_ADDRESS) & 0xff;
849 u64 address = (u64)fpci << 32 | (signature & 0xfffffffc);
851 if (code == AFI_INTR_MASTER_ABORT)
852 dev_dbg(dev, " FPCI address: %10llx\n", address);
854 dev_err(dev, " FPCI address: %10llx\n", address);
861 * FPCI map is as follows:
862 * - 0xfdfc000000: I/O space
863 * - 0xfdfe000000: type 0 configuration space
864 * - 0xfdff000000: type 1 configuration space
865 * - 0xfe00000000: type 0 extended configuration space
866 * - 0xfe10000000: type 1 extended configuration space
868 static void tegra_pcie_setup_translations(struct tegra_pcie *pcie)
871 struct resource_entry *entry;
872 struct pci_host_bridge *bridge = pci_host_bridge_from_priv(pcie);
874 /* Bar 0: type 1 extended configuration space */
875 size = resource_size(&pcie->cs);
876 afi_writel(pcie, pcie->cs.start, AFI_AXI_BAR0_START);
877 afi_writel(pcie, size >> 12, AFI_AXI_BAR0_SZ);
879 resource_list_for_each_entry(entry, &bridge->windows) {
880 u32 fpci_bar, axi_address;
881 struct resource *res = entry->res;
883 size = resource_size(res);
885 switch (resource_type(res)) {
887 /* Bar 1: downstream IO bar */
888 fpci_bar = 0xfdfc0000;
889 axi_address = pci_pio_to_address(res->start);
890 afi_writel(pcie, axi_address, AFI_AXI_BAR1_START);
891 afi_writel(pcie, size >> 12, AFI_AXI_BAR1_SZ);
892 afi_writel(pcie, fpci_bar, AFI_FPCI_BAR1);
895 fpci_bar = (((res->start >> 12) & 0x0fffffff) << 4) | 0x1;
896 axi_address = res->start;
898 if (res->flags & IORESOURCE_PREFETCH) {
899 /* Bar 2: prefetchable memory BAR */
900 afi_writel(pcie, axi_address, AFI_AXI_BAR2_START);
901 afi_writel(pcie, size >> 12, AFI_AXI_BAR2_SZ);
902 afi_writel(pcie, fpci_bar, AFI_FPCI_BAR2);
905 /* Bar 3: non prefetchable memory BAR */
906 afi_writel(pcie, axi_address, AFI_AXI_BAR3_START);
907 afi_writel(pcie, size >> 12, AFI_AXI_BAR3_SZ);
908 afi_writel(pcie, fpci_bar, AFI_FPCI_BAR3);
914 /* NULL out the remaining BARs as they are not used */
915 afi_writel(pcie, 0, AFI_AXI_BAR4_START);
916 afi_writel(pcie, 0, AFI_AXI_BAR4_SZ);
917 afi_writel(pcie, 0, AFI_FPCI_BAR4);
919 afi_writel(pcie, 0, AFI_AXI_BAR5_START);
920 afi_writel(pcie, 0, AFI_AXI_BAR5_SZ);
921 afi_writel(pcie, 0, AFI_FPCI_BAR5);
923 if (pcie->soc->has_cache_bars) {
924 /* map all upstream transactions as uncached */
925 afi_writel(pcie, 0, AFI_CACHE_BAR0_ST);
926 afi_writel(pcie, 0, AFI_CACHE_BAR0_SZ);
927 afi_writel(pcie, 0, AFI_CACHE_BAR1_ST);
928 afi_writel(pcie, 0, AFI_CACHE_BAR1_SZ);
931 /* MSI translations are setup only when needed */
932 afi_writel(pcie, 0, AFI_MSI_FPCI_BAR_ST);
933 afi_writel(pcie, 0, AFI_MSI_BAR_SZ);
934 afi_writel(pcie, 0, AFI_MSI_AXI_BAR_ST);
935 afi_writel(pcie, 0, AFI_MSI_BAR_SZ);
938 static int tegra_pcie_pll_wait(struct tegra_pcie *pcie, unsigned long timeout)
940 const struct tegra_pcie_soc *soc = pcie->soc;
943 timeout = jiffies + msecs_to_jiffies(timeout);
945 while (time_before(jiffies, timeout)) {
946 value = pads_readl(pcie, soc->pads_pll_ctl);
947 if (value & PADS_PLL_CTL_LOCKDET)
954 static int tegra_pcie_phy_enable(struct tegra_pcie *pcie)
956 struct device *dev = pcie->dev;
957 const struct tegra_pcie_soc *soc = pcie->soc;
961 /* initialize internal PHY, enable up to 16 PCIE lanes */
962 pads_writel(pcie, 0x0, PADS_CTL_SEL);
964 /* override IDDQ to 1 on all 4 lanes */
965 value = pads_readl(pcie, PADS_CTL);
966 value |= PADS_CTL_IDDQ_1L;
967 pads_writel(pcie, value, PADS_CTL);
970 * Set up PHY PLL inputs select PLLE output as refclock,
971 * set TX ref sel to div10 (not div5).
973 value = pads_readl(pcie, soc->pads_pll_ctl);
974 value &= ~(PADS_PLL_CTL_REFCLK_MASK | PADS_PLL_CTL_TXCLKREF_MASK);
975 value |= PADS_PLL_CTL_REFCLK_INTERNAL_CML | soc->tx_ref_sel;
976 pads_writel(pcie, value, soc->pads_pll_ctl);
979 value = pads_readl(pcie, soc->pads_pll_ctl);
980 value &= ~PADS_PLL_CTL_RST_B4SM;
981 pads_writel(pcie, value, soc->pads_pll_ctl);
983 usleep_range(20, 100);
985 /* take PLL out of reset */
986 value = pads_readl(pcie, soc->pads_pll_ctl);
987 value |= PADS_PLL_CTL_RST_B4SM;
988 pads_writel(pcie, value, soc->pads_pll_ctl);
990 /* wait for the PLL to lock */
991 err = tegra_pcie_pll_wait(pcie, 500);
993 dev_err(dev, "PLL failed to lock: %d\n", err);
997 /* turn off IDDQ override */
998 value = pads_readl(pcie, PADS_CTL);
999 value &= ~PADS_CTL_IDDQ_1L;
1000 pads_writel(pcie, value, PADS_CTL);
1002 /* enable TX/RX data */
1003 value = pads_readl(pcie, PADS_CTL);
1004 value |= PADS_CTL_TX_DATA_EN_1L | PADS_CTL_RX_DATA_EN_1L;
1005 pads_writel(pcie, value, PADS_CTL);
1010 static int tegra_pcie_phy_disable(struct tegra_pcie *pcie)
1012 const struct tegra_pcie_soc *soc = pcie->soc;
1015 /* disable TX/RX data */
1016 value = pads_readl(pcie, PADS_CTL);
1017 value &= ~(PADS_CTL_TX_DATA_EN_1L | PADS_CTL_RX_DATA_EN_1L);
1018 pads_writel(pcie, value, PADS_CTL);
1021 value = pads_readl(pcie, PADS_CTL);
1022 value |= PADS_CTL_IDDQ_1L;
1023 pads_writel(pcie, value, PADS_CTL);
1026 value = pads_readl(pcie, soc->pads_pll_ctl);
1027 value &= ~PADS_PLL_CTL_RST_B4SM;
1028 pads_writel(pcie, value, soc->pads_pll_ctl);
1030 usleep_range(20, 100);
1035 static int tegra_pcie_port_phy_power_on(struct tegra_pcie_port *port)
1037 struct device *dev = port->pcie->dev;
1041 for (i = 0; i < port->lanes; i++) {
1042 err = phy_power_on(port->phys[i]);
1044 dev_err(dev, "failed to power on PHY#%u: %d\n", i, err);
1052 static int tegra_pcie_port_phy_power_off(struct tegra_pcie_port *port)
1054 struct device *dev = port->pcie->dev;
1058 for (i = 0; i < port->lanes; i++) {
1059 err = phy_power_off(port->phys[i]);
1061 dev_err(dev, "failed to power off PHY#%u: %d\n", i,
1070 static int tegra_pcie_phy_power_on(struct tegra_pcie *pcie)
1072 struct device *dev = pcie->dev;
1073 struct tegra_pcie_port *port;
1076 if (pcie->legacy_phy) {
1078 err = phy_power_on(pcie->phy);
1080 err = tegra_pcie_phy_enable(pcie);
1083 dev_err(dev, "failed to power on PHY: %d\n", err);
1088 list_for_each_entry(port, &pcie->ports, list) {
1089 err = tegra_pcie_port_phy_power_on(port);
1092 "failed to power on PCIe port %u PHY: %d\n",
1101 static int tegra_pcie_phy_power_off(struct tegra_pcie *pcie)
1103 struct device *dev = pcie->dev;
1104 struct tegra_pcie_port *port;
1107 if (pcie->legacy_phy) {
1109 err = phy_power_off(pcie->phy);
1111 err = tegra_pcie_phy_disable(pcie);
1114 dev_err(dev, "failed to power off PHY: %d\n", err);
1119 list_for_each_entry(port, &pcie->ports, list) {
1120 err = tegra_pcie_port_phy_power_off(port);
1123 "failed to power off PCIe port %u PHY: %d\n",
1132 static void tegra_pcie_enable_controller(struct tegra_pcie *pcie)
1134 const struct tegra_pcie_soc *soc = pcie->soc;
1135 struct tegra_pcie_port *port;
1136 unsigned long value;
1138 /* enable PLL power down */
1140 value = afi_readl(pcie, AFI_PLLE_CONTROL);
1141 value &= ~AFI_PLLE_CONTROL_BYPASS_PADS2PLLE_CONTROL;
1142 value |= AFI_PLLE_CONTROL_PADS2PLLE_CONTROL_EN;
1143 afi_writel(pcie, value, AFI_PLLE_CONTROL);
1146 /* power down PCIe slot clock bias pad */
1147 if (soc->has_pex_bias_ctrl)
1148 afi_writel(pcie, 0, AFI_PEXBIAS_CTRL_0);
1150 /* configure mode and disable all ports */
1151 value = afi_readl(pcie, AFI_PCIE_CONFIG);
1152 value &= ~AFI_PCIE_CONFIG_SM2TMS0_XBAR_CONFIG_MASK;
1153 value |= AFI_PCIE_CONFIG_PCIE_DISABLE_ALL | pcie->xbar_config;
1154 value |= AFI_PCIE_CONFIG_PCIE_CLKREQ_GPIO_ALL;
1156 list_for_each_entry(port, &pcie->ports, list) {
1157 value &= ~AFI_PCIE_CONFIG_PCIE_DISABLE(port->index);
1158 value &= ~AFI_PCIE_CONFIG_PCIE_CLKREQ_GPIO(port->index);
1161 afi_writel(pcie, value, AFI_PCIE_CONFIG);
1163 if (soc->has_gen2) {
1164 value = afi_readl(pcie, AFI_FUSE);
1165 value &= ~AFI_FUSE_PCIE_T0_GEN2_DIS;
1166 afi_writel(pcie, value, AFI_FUSE);
1168 value = afi_readl(pcie, AFI_FUSE);
1169 value |= AFI_FUSE_PCIE_T0_GEN2_DIS;
1170 afi_writel(pcie, value, AFI_FUSE);
1173 /* Disable AFI dynamic clock gating and enable PCIe */
1174 value = afi_readl(pcie, AFI_CONFIGURATION);
1175 value |= AFI_CONFIGURATION_EN_FPCI;
1176 value |= AFI_CONFIGURATION_CLKEN_OVERRIDE;
1177 afi_writel(pcie, value, AFI_CONFIGURATION);
1179 value = AFI_INTR_EN_INI_SLVERR | AFI_INTR_EN_INI_DECERR |
1180 AFI_INTR_EN_TGT_SLVERR | AFI_INTR_EN_TGT_DECERR |
1181 AFI_INTR_EN_TGT_WRERR | AFI_INTR_EN_DFPCI_DECERR;
1183 if (soc->has_intr_prsnt_sense)
1184 value |= AFI_INTR_EN_PRSNT_SENSE;
1186 afi_writel(pcie, value, AFI_AFI_INTR_ENABLE);
1187 afi_writel(pcie, 0xffffffff, AFI_SM_INTR_ENABLE);
1189 /* don't enable MSI for now, only when needed */
1190 afi_writel(pcie, AFI_INTR_MASK_INT_MASK, AFI_INTR_MASK);
1192 /* disable all exceptions */
1193 afi_writel(pcie, 0, AFI_FPCI_ERROR_MASKS);
1196 static void tegra_pcie_power_off(struct tegra_pcie *pcie)
1198 struct device *dev = pcie->dev;
1199 const struct tegra_pcie_soc *soc = pcie->soc;
1202 reset_control_assert(pcie->afi_rst);
1204 clk_disable_unprepare(pcie->pll_e);
1205 if (soc->has_cml_clk)
1206 clk_disable_unprepare(pcie->cml_clk);
1207 clk_disable_unprepare(pcie->afi_clk);
1209 if (!dev->pm_domain)
1210 tegra_powergate_power_off(TEGRA_POWERGATE_PCIE);
1212 err = regulator_bulk_disable(pcie->num_supplies, pcie->supplies);
1214 dev_warn(dev, "failed to disable regulators: %d\n", err);
1217 static int tegra_pcie_power_on(struct tegra_pcie *pcie)
1219 struct device *dev = pcie->dev;
1220 const struct tegra_pcie_soc *soc = pcie->soc;
1223 reset_control_assert(pcie->pcie_xrst);
1224 reset_control_assert(pcie->afi_rst);
1225 reset_control_assert(pcie->pex_rst);
1227 if (!dev->pm_domain)
1228 tegra_powergate_power_off(TEGRA_POWERGATE_PCIE);
1230 /* enable regulators */
1231 err = regulator_bulk_enable(pcie->num_supplies, pcie->supplies);
1233 dev_err(dev, "failed to enable regulators: %d\n", err);
1235 if (!dev->pm_domain) {
1236 err = tegra_powergate_power_on(TEGRA_POWERGATE_PCIE);
1238 dev_err(dev, "failed to power ungate: %d\n", err);
1239 goto regulator_disable;
1241 err = tegra_powergate_remove_clamping(TEGRA_POWERGATE_PCIE);
1243 dev_err(dev, "failed to remove clamp: %d\n", err);
1248 err = clk_prepare_enable(pcie->afi_clk);
1250 dev_err(dev, "failed to enable AFI clock: %d\n", err);
1254 if (soc->has_cml_clk) {
1255 err = clk_prepare_enable(pcie->cml_clk);
1257 dev_err(dev, "failed to enable CML clock: %d\n", err);
1258 goto disable_afi_clk;
1262 err = clk_prepare_enable(pcie->pll_e);
1264 dev_err(dev, "failed to enable PLLE clock: %d\n", err);
1265 goto disable_cml_clk;
1268 reset_control_deassert(pcie->afi_rst);
1273 if (soc->has_cml_clk)
1274 clk_disable_unprepare(pcie->cml_clk);
1276 clk_disable_unprepare(pcie->afi_clk);
1278 if (!dev->pm_domain)
1279 tegra_powergate_power_off(TEGRA_POWERGATE_PCIE);
1281 regulator_bulk_disable(pcie->num_supplies, pcie->supplies);
1286 static void tegra_pcie_apply_pad_settings(struct tegra_pcie *pcie)
1288 const struct tegra_pcie_soc *soc = pcie->soc;
1290 /* Configure the reference clock driver */
1291 pads_writel(pcie, soc->pads_refclk_cfg0, PADS_REFCLK_CFG0);
1293 if (soc->num_ports > 2)
1294 pads_writel(pcie, soc->pads_refclk_cfg1, PADS_REFCLK_CFG1);
1297 static int tegra_pcie_clocks_get(struct tegra_pcie *pcie)
1299 struct device *dev = pcie->dev;
1300 const struct tegra_pcie_soc *soc = pcie->soc;
1302 pcie->pex_clk = devm_clk_get(dev, "pex");
1303 if (IS_ERR(pcie->pex_clk))
1304 return PTR_ERR(pcie->pex_clk);
1306 pcie->afi_clk = devm_clk_get(dev, "afi");
1307 if (IS_ERR(pcie->afi_clk))
1308 return PTR_ERR(pcie->afi_clk);
1310 pcie->pll_e = devm_clk_get(dev, "pll_e");
1311 if (IS_ERR(pcie->pll_e))
1312 return PTR_ERR(pcie->pll_e);
1314 if (soc->has_cml_clk) {
1315 pcie->cml_clk = devm_clk_get(dev, "cml");
1316 if (IS_ERR(pcie->cml_clk))
1317 return PTR_ERR(pcie->cml_clk);
1323 static int tegra_pcie_resets_get(struct tegra_pcie *pcie)
1325 struct device *dev = pcie->dev;
1327 pcie->pex_rst = devm_reset_control_get_exclusive(dev, "pex");
1328 if (IS_ERR(pcie->pex_rst))
1329 return PTR_ERR(pcie->pex_rst);
1331 pcie->afi_rst = devm_reset_control_get_exclusive(dev, "afi");
1332 if (IS_ERR(pcie->afi_rst))
1333 return PTR_ERR(pcie->afi_rst);
1335 pcie->pcie_xrst = devm_reset_control_get_exclusive(dev, "pcie_x");
1336 if (IS_ERR(pcie->pcie_xrst))
1337 return PTR_ERR(pcie->pcie_xrst);
1342 static int tegra_pcie_phys_get_legacy(struct tegra_pcie *pcie)
1344 struct device *dev = pcie->dev;
1347 pcie->phy = devm_phy_optional_get(dev, "pcie");
1348 if (IS_ERR(pcie->phy)) {
1349 err = PTR_ERR(pcie->phy);
1350 dev_err(dev, "failed to get PHY: %d\n", err);
1354 err = phy_init(pcie->phy);
1356 dev_err(dev, "failed to initialize PHY: %d\n", err);
1360 pcie->legacy_phy = true;
1365 static struct phy *devm_of_phy_optional_get_index(struct device *dev,
1366 struct device_node *np,
1367 const char *consumer,
1373 name = kasprintf(GFP_KERNEL, "%s-%u", consumer, index);
1375 return ERR_PTR(-ENOMEM);
1377 phy = devm_of_phy_get(dev, np, name);
1380 if (PTR_ERR(phy) == -ENODEV)
1386 static int tegra_pcie_port_get_phys(struct tegra_pcie_port *port)
1388 struct device *dev = port->pcie->dev;
1393 port->phys = devm_kcalloc(dev, sizeof(phy), port->lanes, GFP_KERNEL);
1397 for (i = 0; i < port->lanes; i++) {
1398 phy = devm_of_phy_optional_get_index(dev, port->np, "pcie", i);
1400 dev_err(dev, "failed to get PHY#%u: %ld\n", i,
1402 return PTR_ERR(phy);
1405 err = phy_init(phy);
1407 dev_err(dev, "failed to initialize PHY#%u: %d\n", i,
1412 port->phys[i] = phy;
1418 static int tegra_pcie_phys_get(struct tegra_pcie *pcie)
1420 const struct tegra_pcie_soc *soc = pcie->soc;
1421 struct device_node *np = pcie->dev->of_node;
1422 struct tegra_pcie_port *port;
1425 if (!soc->has_gen2 || of_find_property(np, "phys", NULL) != NULL)
1426 return tegra_pcie_phys_get_legacy(pcie);
1428 list_for_each_entry(port, &pcie->ports, list) {
1429 err = tegra_pcie_port_get_phys(port);
1437 static void tegra_pcie_phys_put(struct tegra_pcie *pcie)
1439 struct tegra_pcie_port *port;
1440 struct device *dev = pcie->dev;
1443 if (pcie->legacy_phy) {
1444 err = phy_exit(pcie->phy);
1446 dev_err(dev, "failed to teardown PHY: %d\n", err);
1450 list_for_each_entry(port, &pcie->ports, list) {
1451 for (i = 0; i < port->lanes; i++) {
1452 err = phy_exit(port->phys[i]);
1454 dev_err(dev, "failed to teardown PHY#%u: %d\n",
1461 static int tegra_pcie_get_resources(struct tegra_pcie *pcie)
1463 struct device *dev = pcie->dev;
1464 struct platform_device *pdev = to_platform_device(dev);
1465 struct resource *pads, *afi, *res;
1466 const struct tegra_pcie_soc *soc = pcie->soc;
1469 err = tegra_pcie_clocks_get(pcie);
1471 dev_err(dev, "failed to get clocks: %d\n", err);
1475 err = tegra_pcie_resets_get(pcie);
1477 dev_err(dev, "failed to get resets: %d\n", err);
1481 if (soc->program_uphy) {
1482 err = tegra_pcie_phys_get(pcie);
1484 dev_err(dev, "failed to get PHYs: %d\n", err);
1489 pads = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pads");
1490 pcie->pads = devm_ioremap_resource(dev, pads);
1491 if (IS_ERR(pcie->pads)) {
1492 err = PTR_ERR(pcie->pads);
1496 afi = platform_get_resource_byname(pdev, IORESOURCE_MEM, "afi");
1497 pcie->afi = devm_ioremap_resource(dev, afi);
1498 if (IS_ERR(pcie->afi)) {
1499 err = PTR_ERR(pcie->afi);
1503 /* request configuration space, but remap later, on demand */
1504 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "cs");
1506 err = -EADDRNOTAVAIL;
1512 /* constrain configuration space to 4 KiB */
1513 pcie->cs.end = pcie->cs.start + SZ_4K - 1;
1515 pcie->cfg = devm_ioremap_resource(dev, &pcie->cs);
1516 if (IS_ERR(pcie->cfg)) {
1517 err = PTR_ERR(pcie->cfg);
1521 /* request interrupt */
1522 err = platform_get_irq_byname(pdev, "intr");
1524 dev_err(dev, "failed to get IRQ: %d\n", err);
1530 err = request_irq(pcie->irq, tegra_pcie_isr, IRQF_SHARED, "PCIE", pcie);
1532 dev_err(dev, "failed to register IRQ: %d\n", err);
1539 if (soc->program_uphy)
1540 tegra_pcie_phys_put(pcie);
1544 static int tegra_pcie_put_resources(struct tegra_pcie *pcie)
1546 const struct tegra_pcie_soc *soc = pcie->soc;
1549 free_irq(pcie->irq, pcie);
1551 if (soc->program_uphy)
1552 tegra_pcie_phys_put(pcie);
1557 static void tegra_pcie_pme_turnoff(struct tegra_pcie_port *port)
1559 struct tegra_pcie *pcie = port->pcie;
1560 const struct tegra_pcie_soc *soc = pcie->soc;
1565 val = afi_readl(pcie, AFI_PCIE_PME);
1566 val |= (0x1 << soc->ports[port->index].pme.turnoff_bit);
1567 afi_writel(pcie, val, AFI_PCIE_PME);
1569 ack_bit = soc->ports[port->index].pme.ack_bit;
1570 err = readl_poll_timeout(pcie->afi + AFI_PCIE_PME, val,
1571 val & (0x1 << ack_bit), 1, PME_ACK_TIMEOUT);
1573 dev_err(pcie->dev, "PME Ack is not received on port: %d\n",
1576 usleep_range(10000, 11000);
1578 val = afi_readl(pcie, AFI_PCIE_PME);
1579 val &= ~(0x1 << soc->ports[port->index].pme.turnoff_bit);
1580 afi_writel(pcie, val, AFI_PCIE_PME);
1583 static int tegra_msi_alloc(struct tegra_msi *chip)
1587 mutex_lock(&chip->lock);
1589 msi = find_first_zero_bit(chip->used, INT_PCI_MSI_NR);
1590 if (msi < INT_PCI_MSI_NR)
1591 set_bit(msi, chip->used);
1595 mutex_unlock(&chip->lock);
1600 static void tegra_msi_free(struct tegra_msi *chip, unsigned long irq)
1602 struct device *dev = chip->chip.dev;
1604 mutex_lock(&chip->lock);
1606 if (!test_bit(irq, chip->used))
1607 dev_err(dev, "trying to free unused MSI#%lu\n", irq);
1609 clear_bit(irq, chip->used);
1611 mutex_unlock(&chip->lock);
1614 static irqreturn_t tegra_pcie_msi_irq(int irq, void *data)
1616 struct tegra_pcie *pcie = data;
1617 struct device *dev = pcie->dev;
1618 struct tegra_msi *msi = &pcie->msi;
1619 unsigned int i, processed = 0;
1621 for (i = 0; i < 8; i++) {
1622 unsigned long reg = afi_readl(pcie, AFI_MSI_VEC0 + i * 4);
1625 unsigned int offset = find_first_bit(®, 32);
1626 unsigned int index = i * 32 + offset;
1629 /* clear the interrupt */
1630 afi_writel(pcie, 1 << offset, AFI_MSI_VEC0 + i * 4);
1632 irq = irq_find_mapping(msi->domain, index);
1634 if (test_bit(index, msi->used))
1635 generic_handle_irq(irq);
1637 dev_info(dev, "unhandled MSI\n");
1640 * that's weird who triggered this?
1643 dev_info(dev, "unexpected MSI\n");
1646 /* see if there's any more pending in this vector */
1647 reg = afi_readl(pcie, AFI_MSI_VEC0 + i * 4);
1653 return processed > 0 ? IRQ_HANDLED : IRQ_NONE;
1656 static int tegra_msi_setup_irq(struct msi_controller *chip,
1657 struct pci_dev *pdev, struct msi_desc *desc)
1659 struct tegra_msi *msi = to_tegra_msi(chip);
1664 hwirq = tegra_msi_alloc(msi);
1668 irq = irq_create_mapping(msi->domain, hwirq);
1670 tegra_msi_free(msi, hwirq);
1674 irq_set_msi_desc(irq, desc);
1676 msg.address_lo = lower_32_bits(msi->phys);
1677 msg.address_hi = upper_32_bits(msi->phys);
1680 pci_write_msi_msg(irq, &msg);
1685 static void tegra_msi_teardown_irq(struct msi_controller *chip,
1688 struct tegra_msi *msi = to_tegra_msi(chip);
1689 struct irq_data *d = irq_get_irq_data(irq);
1690 irq_hw_number_t hwirq = irqd_to_hwirq(d);
1692 irq_dispose_mapping(irq);
1693 tegra_msi_free(msi, hwirq);
1696 static struct irq_chip tegra_msi_irq_chip = {
1697 .name = "Tegra PCIe MSI",
1698 .irq_enable = pci_msi_unmask_irq,
1699 .irq_disable = pci_msi_mask_irq,
1700 .irq_mask = pci_msi_mask_irq,
1701 .irq_unmask = pci_msi_unmask_irq,
1704 static int tegra_msi_map(struct irq_domain *domain, unsigned int irq,
1705 irq_hw_number_t hwirq)
1707 irq_set_chip_and_handler(irq, &tegra_msi_irq_chip, handle_simple_irq);
1708 irq_set_chip_data(irq, domain->host_data);
1710 tegra_cpuidle_pcie_irqs_in_use();
1715 static const struct irq_domain_ops msi_domain_ops = {
1716 .map = tegra_msi_map,
1719 static int tegra_pcie_msi_setup(struct tegra_pcie *pcie)
1721 struct pci_host_bridge *host = pci_host_bridge_from_priv(pcie);
1722 struct platform_device *pdev = to_platform_device(pcie->dev);
1723 struct tegra_msi *msi = &pcie->msi;
1724 struct device *dev = pcie->dev;
1727 mutex_init(&msi->lock);
1729 msi->chip.dev = dev;
1730 msi->chip.setup_irq = tegra_msi_setup_irq;
1731 msi->chip.teardown_irq = tegra_msi_teardown_irq;
1733 msi->domain = irq_domain_add_linear(dev->of_node, INT_PCI_MSI_NR,
1734 &msi_domain_ops, &msi->chip);
1736 dev_err(dev, "failed to create IRQ domain\n");
1740 err = platform_get_irq_byname(pdev, "msi");
1742 dev_err(dev, "failed to get IRQ: %d\n", err);
1743 goto free_irq_domain;
1748 err = request_irq(msi->irq, tegra_pcie_msi_irq, IRQF_NO_THREAD,
1749 tegra_msi_irq_chip.name, pcie);
1751 dev_err(dev, "failed to request IRQ: %d\n", err);
1752 goto free_irq_domain;
1755 /* Though the PCIe controller can address >32-bit address space, to
1756 * facilitate endpoints that support only 32-bit MSI target address,
1757 * the mask is set to 32-bit to make sure that MSI target address is
1758 * always a 32-bit address
1760 err = dma_set_coherent_mask(dev, DMA_BIT_MASK(32));
1762 dev_err(dev, "failed to set DMA coherent mask: %d\n", err);
1766 msi->virt = dma_alloc_attrs(dev, PAGE_SIZE, &msi->phys, GFP_KERNEL,
1767 DMA_ATTR_NO_KERNEL_MAPPING);
1769 dev_err(dev, "failed to allocate DMA memory for MSI\n");
1774 host->msi = &msi->chip;
1779 free_irq(msi->irq, pcie);
1781 irq_domain_remove(msi->domain);
1785 static void tegra_pcie_enable_msi(struct tegra_pcie *pcie)
1787 const struct tegra_pcie_soc *soc = pcie->soc;
1788 struct tegra_msi *msi = &pcie->msi;
1791 afi_writel(pcie, msi->phys >> soc->msi_base_shift, AFI_MSI_FPCI_BAR_ST);
1792 afi_writel(pcie, msi->phys, AFI_MSI_AXI_BAR_ST);
1793 /* this register is in 4K increments */
1794 afi_writel(pcie, 1, AFI_MSI_BAR_SZ);
1796 /* enable all MSI vectors */
1797 afi_writel(pcie, 0xffffffff, AFI_MSI_EN_VEC0);
1798 afi_writel(pcie, 0xffffffff, AFI_MSI_EN_VEC1);
1799 afi_writel(pcie, 0xffffffff, AFI_MSI_EN_VEC2);
1800 afi_writel(pcie, 0xffffffff, AFI_MSI_EN_VEC3);
1801 afi_writel(pcie, 0xffffffff, AFI_MSI_EN_VEC4);
1802 afi_writel(pcie, 0xffffffff, AFI_MSI_EN_VEC5);
1803 afi_writel(pcie, 0xffffffff, AFI_MSI_EN_VEC6);
1804 afi_writel(pcie, 0xffffffff, AFI_MSI_EN_VEC7);
1806 /* and unmask the MSI interrupt */
1807 reg = afi_readl(pcie, AFI_INTR_MASK);
1808 reg |= AFI_INTR_MASK_MSI_MASK;
1809 afi_writel(pcie, reg, AFI_INTR_MASK);
1812 static void tegra_pcie_msi_teardown(struct tegra_pcie *pcie)
1814 struct tegra_msi *msi = &pcie->msi;
1815 unsigned int i, irq;
1817 dma_free_attrs(pcie->dev, PAGE_SIZE, msi->virt, msi->phys,
1818 DMA_ATTR_NO_KERNEL_MAPPING);
1821 free_irq(msi->irq, pcie);
1823 for (i = 0; i < INT_PCI_MSI_NR; i++) {
1824 irq = irq_find_mapping(msi->domain, i);
1826 irq_dispose_mapping(irq);
1829 irq_domain_remove(msi->domain);
1832 static int tegra_pcie_disable_msi(struct tegra_pcie *pcie)
1836 /* mask the MSI interrupt */
1837 value = afi_readl(pcie, AFI_INTR_MASK);
1838 value &= ~AFI_INTR_MASK_MSI_MASK;
1839 afi_writel(pcie, value, AFI_INTR_MASK);
1841 /* disable all MSI vectors */
1842 afi_writel(pcie, 0, AFI_MSI_EN_VEC0);
1843 afi_writel(pcie, 0, AFI_MSI_EN_VEC1);
1844 afi_writel(pcie, 0, AFI_MSI_EN_VEC2);
1845 afi_writel(pcie, 0, AFI_MSI_EN_VEC3);
1846 afi_writel(pcie, 0, AFI_MSI_EN_VEC4);
1847 afi_writel(pcie, 0, AFI_MSI_EN_VEC5);
1848 afi_writel(pcie, 0, AFI_MSI_EN_VEC6);
1849 afi_writel(pcie, 0, AFI_MSI_EN_VEC7);
1854 static void tegra_pcie_disable_interrupts(struct tegra_pcie *pcie)
1858 value = afi_readl(pcie, AFI_INTR_MASK);
1859 value &= ~AFI_INTR_MASK_INT_MASK;
1860 afi_writel(pcie, value, AFI_INTR_MASK);
1863 static int tegra_pcie_get_xbar_config(struct tegra_pcie *pcie, u32 lanes,
1866 struct device *dev = pcie->dev;
1867 struct device_node *np = dev->of_node;
1869 if (of_device_is_compatible(np, "nvidia,tegra186-pcie")) {
1872 dev_info(dev, "4x1, 1x1 configuration\n");
1873 *xbar = AFI_PCIE_CONFIG_SM2TMS0_XBAR_CONFIG_401;
1877 dev_info(dev, "2x1, 1X1, 1x1 configuration\n");
1878 *xbar = AFI_PCIE_CONFIG_SM2TMS0_XBAR_CONFIG_211;
1882 dev_info(dev, "1x1, 1x1, 1x1 configuration\n");
1883 *xbar = AFI_PCIE_CONFIG_SM2TMS0_XBAR_CONFIG_111;
1887 dev_info(dev, "wrong configuration updated in DT, "
1888 "switching to default 2x1, 1x1, 1x1 "
1890 *xbar = AFI_PCIE_CONFIG_SM2TMS0_XBAR_CONFIG_211;
1893 } else if (of_device_is_compatible(np, "nvidia,tegra124-pcie") ||
1894 of_device_is_compatible(np, "nvidia,tegra210-pcie")) {
1897 dev_info(dev, "4x1, 1x1 configuration\n");
1898 *xbar = AFI_PCIE_CONFIG_SM2TMS0_XBAR_CONFIG_X4_X1;
1902 dev_info(dev, "2x1, 1x1 configuration\n");
1903 *xbar = AFI_PCIE_CONFIG_SM2TMS0_XBAR_CONFIG_X2_X1;
1906 } else if (of_device_is_compatible(np, "nvidia,tegra30-pcie")) {
1909 dev_info(dev, "4x1, 2x1 configuration\n");
1910 *xbar = AFI_PCIE_CONFIG_SM2TMS0_XBAR_CONFIG_420;
1914 dev_info(dev, "2x3 configuration\n");
1915 *xbar = AFI_PCIE_CONFIG_SM2TMS0_XBAR_CONFIG_222;
1919 dev_info(dev, "4x1, 1x2 configuration\n");
1920 *xbar = AFI_PCIE_CONFIG_SM2TMS0_XBAR_CONFIG_411;
1923 } else if (of_device_is_compatible(np, "nvidia,tegra20-pcie")) {
1926 dev_info(dev, "single-mode configuration\n");
1927 *xbar = AFI_PCIE_CONFIG_SM2TMS0_XBAR_CONFIG_SINGLE;
1931 dev_info(dev, "dual-mode configuration\n");
1932 *xbar = AFI_PCIE_CONFIG_SM2TMS0_XBAR_CONFIG_DUAL;
1941 * Check whether a given set of supplies is available in a device tree node.
1942 * This is used to check whether the new or the legacy device tree bindings
1945 static bool of_regulator_bulk_available(struct device_node *np,
1946 struct regulator_bulk_data *supplies,
1947 unsigned int num_supplies)
1952 for (i = 0; i < num_supplies; i++) {
1953 snprintf(property, 32, "%s-supply", supplies[i].supply);
1955 if (of_find_property(np, property, NULL) == NULL)
1963 * Old versions of the device tree binding for this device used a set of power
1964 * supplies that didn't match the hardware inputs. This happened to work for a
1965 * number of cases but is not future proof. However to preserve backwards-
1966 * compatibility with old device trees, this function will try to use the old
1969 static int tegra_pcie_get_legacy_regulators(struct tegra_pcie *pcie)
1971 struct device *dev = pcie->dev;
1972 struct device_node *np = dev->of_node;
1974 if (of_device_is_compatible(np, "nvidia,tegra30-pcie"))
1975 pcie->num_supplies = 3;
1976 else if (of_device_is_compatible(np, "nvidia,tegra20-pcie"))
1977 pcie->num_supplies = 2;
1979 if (pcie->num_supplies == 0) {
1980 dev_err(dev, "device %pOF not supported in legacy mode\n", np);
1984 pcie->supplies = devm_kcalloc(dev, pcie->num_supplies,
1985 sizeof(*pcie->supplies),
1987 if (!pcie->supplies)
1990 pcie->supplies[0].supply = "pex-clk";
1991 pcie->supplies[1].supply = "vdd";
1993 if (pcie->num_supplies > 2)
1994 pcie->supplies[2].supply = "avdd";
1996 return devm_regulator_bulk_get(dev, pcie->num_supplies, pcie->supplies);
2000 * Obtains the list of regulators required for a particular generation of the
2003 * This would've been nice to do simply by providing static tables for use
2004 * with the regulator_bulk_*() API, but unfortunately Tegra30 is a bit quirky
2005 * in that it has two pairs or AVDD_PEX and VDD_PEX supplies (PEXA and PEXB)
2006 * and either seems to be optional depending on which ports are being used.
2008 static int tegra_pcie_get_regulators(struct tegra_pcie *pcie, u32 lane_mask)
2010 struct device *dev = pcie->dev;
2011 struct device_node *np = dev->of_node;
2014 if (of_device_is_compatible(np, "nvidia,tegra186-pcie")) {
2015 pcie->num_supplies = 4;
2017 pcie->supplies = devm_kcalloc(pcie->dev, pcie->num_supplies,
2018 sizeof(*pcie->supplies),
2020 if (!pcie->supplies)
2023 pcie->supplies[i++].supply = "dvdd-pex";
2024 pcie->supplies[i++].supply = "hvdd-pex-pll";
2025 pcie->supplies[i++].supply = "hvdd-pex";
2026 pcie->supplies[i++].supply = "vddio-pexctl-aud";
2027 } else if (of_device_is_compatible(np, "nvidia,tegra210-pcie")) {
2028 pcie->num_supplies = 6;
2030 pcie->supplies = devm_kcalloc(pcie->dev, pcie->num_supplies,
2031 sizeof(*pcie->supplies),
2033 if (!pcie->supplies)
2036 pcie->supplies[i++].supply = "avdd-pll-uerefe";
2037 pcie->supplies[i++].supply = "hvddio-pex";
2038 pcie->supplies[i++].supply = "dvddio-pex";
2039 pcie->supplies[i++].supply = "dvdd-pex-pll";
2040 pcie->supplies[i++].supply = "hvdd-pex-pll-e";
2041 pcie->supplies[i++].supply = "vddio-pex-ctl";
2042 } else if (of_device_is_compatible(np, "nvidia,tegra124-pcie")) {
2043 pcie->num_supplies = 7;
2045 pcie->supplies = devm_kcalloc(dev, pcie->num_supplies,
2046 sizeof(*pcie->supplies),
2048 if (!pcie->supplies)
2051 pcie->supplies[i++].supply = "avddio-pex";
2052 pcie->supplies[i++].supply = "dvddio-pex";
2053 pcie->supplies[i++].supply = "avdd-pex-pll";
2054 pcie->supplies[i++].supply = "hvdd-pex";
2055 pcie->supplies[i++].supply = "hvdd-pex-pll-e";
2056 pcie->supplies[i++].supply = "vddio-pex-ctl";
2057 pcie->supplies[i++].supply = "avdd-pll-erefe";
2058 } else if (of_device_is_compatible(np, "nvidia,tegra30-pcie")) {
2059 bool need_pexa = false, need_pexb = false;
2061 /* VDD_PEXA and AVDD_PEXA supply lanes 0 to 3 */
2062 if (lane_mask & 0x0f)
2065 /* VDD_PEXB and AVDD_PEXB supply lanes 4 to 5 */
2066 if (lane_mask & 0x30)
2069 pcie->num_supplies = 4 + (need_pexa ? 2 : 0) +
2070 (need_pexb ? 2 : 0);
2072 pcie->supplies = devm_kcalloc(dev, pcie->num_supplies,
2073 sizeof(*pcie->supplies),
2075 if (!pcie->supplies)
2078 pcie->supplies[i++].supply = "avdd-pex-pll";
2079 pcie->supplies[i++].supply = "hvdd-pex";
2080 pcie->supplies[i++].supply = "vddio-pex-ctl";
2081 pcie->supplies[i++].supply = "avdd-plle";
2084 pcie->supplies[i++].supply = "avdd-pexa";
2085 pcie->supplies[i++].supply = "vdd-pexa";
2089 pcie->supplies[i++].supply = "avdd-pexb";
2090 pcie->supplies[i++].supply = "vdd-pexb";
2092 } else if (of_device_is_compatible(np, "nvidia,tegra20-pcie")) {
2093 pcie->num_supplies = 5;
2095 pcie->supplies = devm_kcalloc(dev, pcie->num_supplies,
2096 sizeof(*pcie->supplies),
2098 if (!pcie->supplies)
2101 pcie->supplies[0].supply = "avdd-pex";
2102 pcie->supplies[1].supply = "vdd-pex";
2103 pcie->supplies[2].supply = "avdd-pex-pll";
2104 pcie->supplies[3].supply = "avdd-plle";
2105 pcie->supplies[4].supply = "vddio-pex-clk";
2108 if (of_regulator_bulk_available(dev->of_node, pcie->supplies,
2109 pcie->num_supplies))
2110 return devm_regulator_bulk_get(dev, pcie->num_supplies,
2114 * If not all regulators are available for this new scheme, assume
2115 * that the device tree complies with an older version of the device
2118 dev_info(dev, "using legacy DT binding for power supplies\n");
2120 devm_kfree(dev, pcie->supplies);
2121 pcie->num_supplies = 0;
2123 return tegra_pcie_get_legacy_regulators(pcie);
2126 static int tegra_pcie_parse_dt(struct tegra_pcie *pcie)
2128 struct device *dev = pcie->dev;
2129 struct device_node *np = dev->of_node, *port;
2130 const struct tegra_pcie_soc *soc = pcie->soc;
2131 u32 lanes = 0, mask = 0;
2132 unsigned int lane = 0;
2135 /* parse root ports */
2136 for_each_child_of_node(np, port) {
2137 struct tegra_pcie_port *rp;
2142 err = of_pci_get_devfn(port);
2144 dev_err(dev, "failed to parse address: %d\n", err);
2148 index = PCI_SLOT(err);
2150 if (index < 1 || index > soc->num_ports) {
2151 dev_err(dev, "invalid port number: %d\n", index);
2158 err = of_property_read_u32(port, "nvidia,num-lanes", &value);
2160 dev_err(dev, "failed to parse # of lanes: %d\n",
2166 dev_err(dev, "invalid # of lanes: %u\n", value);
2171 lanes |= value << (index << 3);
2173 if (!of_device_is_available(port)) {
2178 mask |= ((1 << value) - 1) << lane;
2181 rp = devm_kzalloc(dev, sizeof(*rp), GFP_KERNEL);
2187 err = of_address_to_resource(port, 0, &rp->regs);
2189 dev_err(dev, "failed to parse address: %d\n", err);
2193 INIT_LIST_HEAD(&rp->list);
2199 rp->base = devm_pci_remap_cfg_resource(dev, &rp->regs);
2200 if (IS_ERR(rp->base))
2201 return PTR_ERR(rp->base);
2203 label = devm_kasprintf(dev, GFP_KERNEL, "pex-reset-%u", index);
2205 dev_err(dev, "failed to create reset GPIO label\n");
2210 * Returns -ENOENT if reset-gpios property is not populated
2211 * and in this case fall back to using AFI per port register
2212 * to toggle PERST# SFIO line.
2214 rp->reset_gpio = devm_gpiod_get_from_of_node(dev, port,
2218 if (IS_ERR(rp->reset_gpio)) {
2219 if (PTR_ERR(rp->reset_gpio) == -ENOENT) {
2220 rp->reset_gpio = NULL;
2222 dev_err(dev, "failed to get reset GPIO: %d\n",
2224 return PTR_ERR(rp->reset_gpio);
2228 list_add_tail(&rp->list, &pcie->ports);
2231 err = tegra_pcie_get_xbar_config(pcie, lanes, &pcie->xbar_config);
2233 dev_err(dev, "invalid lane configuration\n");
2237 err = tegra_pcie_get_regulators(pcie, mask);
2249 * FIXME: If there are no PCIe cards attached, then calling this function
2250 * can result in the increase of the bootup time as there are big timeout
2253 #define TEGRA_PCIE_LINKUP_TIMEOUT 200 /* up to 1.2 seconds */
2254 static bool tegra_pcie_port_check_link(struct tegra_pcie_port *port)
2256 struct device *dev = port->pcie->dev;
2257 unsigned int retries = 3;
2258 unsigned long value;
2260 /* override presence detection */
2261 value = readl(port->base + RP_PRIV_MISC);
2262 value &= ~RP_PRIV_MISC_PRSNT_MAP_EP_ABSNT;
2263 value |= RP_PRIV_MISC_PRSNT_MAP_EP_PRSNT;
2264 writel(value, port->base + RP_PRIV_MISC);
2267 unsigned int timeout = TEGRA_PCIE_LINKUP_TIMEOUT;
2270 value = readl(port->base + RP_VEND_XP);
2272 if (value & RP_VEND_XP_DL_UP)
2275 usleep_range(1000, 2000);
2276 } while (--timeout);
2279 dev_dbg(dev, "link %u down, retrying\n", port->index);
2283 timeout = TEGRA_PCIE_LINKUP_TIMEOUT;
2286 value = readl(port->base + RP_LINK_CONTROL_STATUS);
2288 if (value & RP_LINK_CONTROL_STATUS_DL_LINK_ACTIVE)
2291 usleep_range(1000, 2000);
2292 } while (--timeout);
2295 tegra_pcie_port_reset(port);
2296 } while (--retries);
2301 static void tegra_pcie_change_link_speed(struct tegra_pcie *pcie)
2303 struct device *dev = pcie->dev;
2304 struct tegra_pcie_port *port;
2308 list_for_each_entry(port, &pcie->ports, list) {
2310 * "Supported Link Speeds Vector" in "Link Capabilities 2"
2311 * is not supported by Tegra. tegra_pcie_change_link_speed()
2312 * is called only for Tegra chips which support Gen2.
2313 * So there no harm if supported link speed is not verified.
2315 value = readl(port->base + RP_LINK_CONTROL_STATUS_2);
2316 value &= ~PCI_EXP_LNKSTA_CLS;
2317 value |= PCI_EXP_LNKSTA_CLS_5_0GB;
2318 writel(value, port->base + RP_LINK_CONTROL_STATUS_2);
2321 * Poll until link comes back from recovery to avoid race
2324 deadline = ktime_add_us(ktime_get(), LINK_RETRAIN_TIMEOUT);
2326 while (ktime_before(ktime_get(), deadline)) {
2327 value = readl(port->base + RP_LINK_CONTROL_STATUS);
2328 if ((value & PCI_EXP_LNKSTA_LT) == 0)
2331 usleep_range(2000, 3000);
2334 if (value & PCI_EXP_LNKSTA_LT)
2335 dev_warn(dev, "PCIe port %u link is in recovery\n",
2338 /* Retrain the link */
2339 value = readl(port->base + RP_LINK_CONTROL_STATUS);
2340 value |= PCI_EXP_LNKCTL_RL;
2341 writel(value, port->base + RP_LINK_CONTROL_STATUS);
2343 deadline = ktime_add_us(ktime_get(), LINK_RETRAIN_TIMEOUT);
2345 while (ktime_before(ktime_get(), deadline)) {
2346 value = readl(port->base + RP_LINK_CONTROL_STATUS);
2347 if ((value & PCI_EXP_LNKSTA_LT) == 0)
2350 usleep_range(2000, 3000);
2353 if (value & PCI_EXP_LNKSTA_LT)
2354 dev_err(dev, "failed to retrain link of port %u\n",
2359 static void tegra_pcie_enable_ports(struct tegra_pcie *pcie)
2361 struct device *dev = pcie->dev;
2362 struct tegra_pcie_port *port, *tmp;
2364 list_for_each_entry_safe(port, tmp, &pcie->ports, list) {
2365 dev_info(dev, "probing port %u, using %u lanes\n",
2366 port->index, port->lanes);
2368 tegra_pcie_port_enable(port);
2371 /* Start LTSSM from Tegra side */
2372 reset_control_deassert(pcie->pcie_xrst);
2374 list_for_each_entry_safe(port, tmp, &pcie->ports, list) {
2375 if (tegra_pcie_port_check_link(port))
2378 dev_info(dev, "link %u down, ignoring\n", port->index);
2380 tegra_pcie_port_disable(port);
2381 tegra_pcie_port_free(port);
2384 if (pcie->soc->has_gen2)
2385 tegra_pcie_change_link_speed(pcie);
2388 static void tegra_pcie_disable_ports(struct tegra_pcie *pcie)
2390 struct tegra_pcie_port *port, *tmp;
2392 reset_control_assert(pcie->pcie_xrst);
2394 list_for_each_entry_safe(port, tmp, &pcie->ports, list)
2395 tegra_pcie_port_disable(port);
2398 static const struct tegra_pcie_port_soc tegra20_pcie_ports[] = {
2399 { .pme.turnoff_bit = 0, .pme.ack_bit = 5 },
2400 { .pme.turnoff_bit = 8, .pme.ack_bit = 10 },
2403 static const struct tegra_pcie_soc tegra20_pcie = {
2405 .ports = tegra20_pcie_ports,
2406 .msi_base_shift = 0,
2407 .pads_pll_ctl = PADS_PLL_CTL_TEGRA20,
2408 .tx_ref_sel = PADS_PLL_CTL_TXCLKREF_DIV10,
2409 .pads_refclk_cfg0 = 0xfa5cfa5c,
2410 .has_pex_clkreq_en = false,
2411 .has_pex_bias_ctrl = false,
2412 .has_intr_prsnt_sense = false,
2413 .has_cml_clk = false,
2415 .force_pca_enable = false,
2416 .program_uphy = true,
2417 .update_clamp_threshold = false,
2418 .program_deskew_time = false,
2419 .raw_violation_fixup = false,
2420 .update_fc_timer = false,
2421 .has_cache_bars = true,
2422 .ectl.enable = false,
2425 static const struct tegra_pcie_port_soc tegra30_pcie_ports[] = {
2426 { .pme.turnoff_bit = 0, .pme.ack_bit = 5 },
2427 { .pme.turnoff_bit = 8, .pme.ack_bit = 10 },
2428 { .pme.turnoff_bit = 16, .pme.ack_bit = 18 },
2431 static const struct tegra_pcie_soc tegra30_pcie = {
2433 .ports = tegra30_pcie_ports,
2434 .msi_base_shift = 8,
2435 .afi_pex2_ctrl = 0x128,
2436 .pads_pll_ctl = PADS_PLL_CTL_TEGRA30,
2437 .tx_ref_sel = PADS_PLL_CTL_TXCLKREF_BUF_EN,
2438 .pads_refclk_cfg0 = 0xfa5cfa5c,
2439 .pads_refclk_cfg1 = 0xfa5cfa5c,
2440 .has_pex_clkreq_en = true,
2441 .has_pex_bias_ctrl = true,
2442 .has_intr_prsnt_sense = true,
2443 .has_cml_clk = true,
2445 .force_pca_enable = false,
2446 .program_uphy = true,
2447 .update_clamp_threshold = false,
2448 .program_deskew_time = false,
2449 .raw_violation_fixup = false,
2450 .update_fc_timer = false,
2451 .has_cache_bars = false,
2452 .ectl.enable = false,
2455 static const struct tegra_pcie_soc tegra124_pcie = {
2457 .ports = tegra20_pcie_ports,
2458 .msi_base_shift = 8,
2459 .pads_pll_ctl = PADS_PLL_CTL_TEGRA30,
2460 .tx_ref_sel = PADS_PLL_CTL_TXCLKREF_BUF_EN,
2461 .pads_refclk_cfg0 = 0x44ac44ac,
2462 /* FC threshold is bit[25:18] */
2463 .update_fc_threshold = 0x03fc0000,
2464 .has_pex_clkreq_en = true,
2465 .has_pex_bias_ctrl = true,
2466 .has_intr_prsnt_sense = true,
2467 .has_cml_clk = true,
2469 .force_pca_enable = false,
2470 .program_uphy = true,
2471 .update_clamp_threshold = true,
2472 .program_deskew_time = false,
2473 .raw_violation_fixup = true,
2474 .update_fc_timer = false,
2475 .has_cache_bars = false,
2476 .ectl.enable = false,
2479 static const struct tegra_pcie_soc tegra210_pcie = {
2481 .ports = tegra20_pcie_ports,
2482 .msi_base_shift = 8,
2483 .pads_pll_ctl = PADS_PLL_CTL_TEGRA30,
2484 .tx_ref_sel = PADS_PLL_CTL_TXCLKREF_BUF_EN,
2485 .pads_refclk_cfg0 = 0x90b890b8,
2486 /* FC threshold is bit[25:18] */
2487 .update_fc_threshold = 0x01800000,
2488 .has_pex_clkreq_en = true,
2489 .has_pex_bias_ctrl = true,
2490 .has_intr_prsnt_sense = true,
2491 .has_cml_clk = true,
2493 .force_pca_enable = true,
2494 .program_uphy = true,
2495 .update_clamp_threshold = true,
2496 .program_deskew_time = true,
2497 .raw_violation_fixup = false,
2498 .update_fc_timer = true,
2499 .has_cache_bars = false,
2502 .rp_ectl_2_r1 = 0x0000000f,
2503 .rp_ectl_4_r1 = 0x00000067,
2504 .rp_ectl_5_r1 = 0x55010000,
2505 .rp_ectl_6_r1 = 0x00000001,
2506 .rp_ectl_2_r2 = 0x0000008f,
2507 .rp_ectl_4_r2 = 0x000000c7,
2508 .rp_ectl_5_r2 = 0x55010000,
2509 .rp_ectl_6_r2 = 0x00000001,
2515 static const struct tegra_pcie_port_soc tegra186_pcie_ports[] = {
2516 { .pme.turnoff_bit = 0, .pme.ack_bit = 5 },
2517 { .pme.turnoff_bit = 8, .pme.ack_bit = 10 },
2518 { .pme.turnoff_bit = 12, .pme.ack_bit = 14 },
2521 static const struct tegra_pcie_soc tegra186_pcie = {
2523 .ports = tegra186_pcie_ports,
2524 .msi_base_shift = 8,
2525 .afi_pex2_ctrl = 0x19c,
2526 .pads_pll_ctl = PADS_PLL_CTL_TEGRA30,
2527 .tx_ref_sel = PADS_PLL_CTL_TXCLKREF_BUF_EN,
2528 .pads_refclk_cfg0 = 0x80b880b8,
2529 .pads_refclk_cfg1 = 0x000480b8,
2530 .has_pex_clkreq_en = true,
2531 .has_pex_bias_ctrl = true,
2532 .has_intr_prsnt_sense = true,
2533 .has_cml_clk = false,
2535 .force_pca_enable = false,
2536 .program_uphy = false,
2537 .update_clamp_threshold = false,
2538 .program_deskew_time = false,
2539 .raw_violation_fixup = false,
2540 .update_fc_timer = false,
2541 .has_cache_bars = false,
2542 .ectl.enable = false,
2545 static const struct of_device_id tegra_pcie_of_match[] = {
2546 { .compatible = "nvidia,tegra186-pcie", .data = &tegra186_pcie },
2547 { .compatible = "nvidia,tegra210-pcie", .data = &tegra210_pcie },
2548 { .compatible = "nvidia,tegra124-pcie", .data = &tegra124_pcie },
2549 { .compatible = "nvidia,tegra30-pcie", .data = &tegra30_pcie },
2550 { .compatible = "nvidia,tegra20-pcie", .data = &tegra20_pcie },
2554 static void *tegra_pcie_ports_seq_start(struct seq_file *s, loff_t *pos)
2556 struct tegra_pcie *pcie = s->private;
2558 if (list_empty(&pcie->ports))
2561 seq_printf(s, "Index Status\n");
2563 return seq_list_start(&pcie->ports, *pos);
2566 static void *tegra_pcie_ports_seq_next(struct seq_file *s, void *v, loff_t *pos)
2568 struct tegra_pcie *pcie = s->private;
2570 return seq_list_next(v, &pcie->ports, pos);
2573 static void tegra_pcie_ports_seq_stop(struct seq_file *s, void *v)
2577 static int tegra_pcie_ports_seq_show(struct seq_file *s, void *v)
2579 bool up = false, active = false;
2580 struct tegra_pcie_port *port;
2583 port = list_entry(v, struct tegra_pcie_port, list);
2585 value = readl(port->base + RP_VEND_XP);
2587 if (value & RP_VEND_XP_DL_UP)
2590 value = readl(port->base + RP_LINK_CONTROL_STATUS);
2592 if (value & RP_LINK_CONTROL_STATUS_DL_LINK_ACTIVE)
2595 seq_printf(s, "%2u ", port->index);
2598 seq_printf(s, "up");
2602 seq_printf(s, ", ");
2604 seq_printf(s, "active");
2607 seq_printf(s, "\n");
2611 static const struct seq_operations tegra_pcie_ports_seq_ops = {
2612 .start = tegra_pcie_ports_seq_start,
2613 .next = tegra_pcie_ports_seq_next,
2614 .stop = tegra_pcie_ports_seq_stop,
2615 .show = tegra_pcie_ports_seq_show,
2618 static int tegra_pcie_ports_open(struct inode *inode, struct file *file)
2620 struct tegra_pcie *pcie = inode->i_private;
2624 err = seq_open(file, &tegra_pcie_ports_seq_ops);
2628 s = file->private_data;
2634 static const struct file_operations tegra_pcie_ports_ops = {
2635 .owner = THIS_MODULE,
2636 .open = tegra_pcie_ports_open,
2638 .llseek = seq_lseek,
2639 .release = seq_release,
2642 static void tegra_pcie_debugfs_exit(struct tegra_pcie *pcie)
2644 debugfs_remove_recursive(pcie->debugfs);
2645 pcie->debugfs = NULL;
2648 static int tegra_pcie_debugfs_init(struct tegra_pcie *pcie)
2650 struct dentry *file;
2652 pcie->debugfs = debugfs_create_dir("pcie", NULL);
2656 file = debugfs_create_file("ports", S_IFREG | S_IRUGO, pcie->debugfs,
2657 pcie, &tegra_pcie_ports_ops);
2664 tegra_pcie_debugfs_exit(pcie);
2668 static int tegra_pcie_probe(struct platform_device *pdev)
2670 struct device *dev = &pdev->dev;
2671 struct pci_host_bridge *host;
2672 struct tegra_pcie *pcie;
2673 struct pci_bus *child;
2674 struct resource *bus;
2677 host = devm_pci_alloc_host_bridge(dev, sizeof(*pcie));
2681 pcie = pci_host_bridge_priv(host);
2682 host->sysdata = pcie;
2683 platform_set_drvdata(pdev, pcie);
2685 pcie->soc = of_device_get_match_data(dev);
2686 INIT_LIST_HEAD(&pcie->ports);
2689 err = pci_parse_request_of_pci_ranges(dev, &host->windows, NULL, &bus);
2691 dev_err(dev, "Getting bridge resources failed\n");
2695 err = tegra_pcie_parse_dt(pcie);
2699 err = tegra_pcie_get_resources(pcie);
2701 dev_err(dev, "failed to request resources: %d\n", err);
2705 err = tegra_pcie_msi_setup(pcie);
2707 dev_err(dev, "failed to enable MSI support: %d\n", err);
2711 pm_runtime_enable(pcie->dev);
2712 err = pm_runtime_get_sync(pcie->dev);
2714 dev_err(dev, "fail to enable pcie controller: %d\n", err);
2718 host->busnr = bus->start;
2719 host->dev.parent = &pdev->dev;
2720 host->ops = &tegra_pcie_ops;
2721 host->map_irq = tegra_pcie_map_irq;
2722 host->swizzle_irq = pci_common_swizzle;
2724 err = pci_scan_root_bus_bridge(host);
2726 dev_err(dev, "failed to register host: %d\n", err);
2727 goto pm_runtime_put;
2730 pci_bus_size_bridges(host->bus);
2731 pci_bus_assign_resources(host->bus);
2733 list_for_each_entry(child, &host->bus->children, node)
2734 pcie_bus_configure_settings(child);
2736 pci_bus_add_devices(host->bus);
2738 if (IS_ENABLED(CONFIG_DEBUG_FS)) {
2739 err = tegra_pcie_debugfs_init(pcie);
2741 dev_err(dev, "failed to setup debugfs: %d\n", err);
2747 pm_runtime_put_sync(pcie->dev);
2748 pm_runtime_disable(pcie->dev);
2750 tegra_pcie_msi_teardown(pcie);
2752 tegra_pcie_put_resources(pcie);
2756 static int tegra_pcie_remove(struct platform_device *pdev)
2758 struct tegra_pcie *pcie = platform_get_drvdata(pdev);
2759 struct pci_host_bridge *host = pci_host_bridge_from_priv(pcie);
2760 struct tegra_pcie_port *port, *tmp;
2762 if (IS_ENABLED(CONFIG_DEBUG_FS))
2763 tegra_pcie_debugfs_exit(pcie);
2765 pci_stop_root_bus(host->bus);
2766 pci_remove_root_bus(host->bus);
2767 pm_runtime_put_sync(pcie->dev);
2768 pm_runtime_disable(pcie->dev);
2770 if (IS_ENABLED(CONFIG_PCI_MSI))
2771 tegra_pcie_msi_teardown(pcie);
2773 tegra_pcie_put_resources(pcie);
2775 list_for_each_entry_safe(port, tmp, &pcie->ports, list)
2776 tegra_pcie_port_free(port);
2781 static int __maybe_unused tegra_pcie_pm_suspend(struct device *dev)
2783 struct tegra_pcie *pcie = dev_get_drvdata(dev);
2784 struct tegra_pcie_port *port;
2787 list_for_each_entry(port, &pcie->ports, list)
2788 tegra_pcie_pme_turnoff(port);
2790 tegra_pcie_disable_ports(pcie);
2793 * AFI_INTR is unmasked in tegra_pcie_enable_controller(), mask it to
2794 * avoid unwanted interrupts raised by AFI after pex_rst is asserted.
2796 tegra_pcie_disable_interrupts(pcie);
2798 if (pcie->soc->program_uphy) {
2799 err = tegra_pcie_phy_power_off(pcie);
2801 dev_err(dev, "failed to power off PHY(s): %d\n", err);
2804 reset_control_assert(pcie->pex_rst);
2805 clk_disable_unprepare(pcie->pex_clk);
2807 if (IS_ENABLED(CONFIG_PCI_MSI))
2808 tegra_pcie_disable_msi(pcie);
2810 pinctrl_pm_select_idle_state(dev);
2811 tegra_pcie_power_off(pcie);
2816 static int __maybe_unused tegra_pcie_pm_resume(struct device *dev)
2818 struct tegra_pcie *pcie = dev_get_drvdata(dev);
2821 err = tegra_pcie_power_on(pcie);
2823 dev_err(dev, "tegra pcie power on fail: %d\n", err);
2827 err = pinctrl_pm_select_default_state(dev);
2829 dev_err(dev, "failed to disable PCIe IO DPD: %d\n", err);
2833 tegra_pcie_enable_controller(pcie);
2834 tegra_pcie_setup_translations(pcie);
2836 if (IS_ENABLED(CONFIG_PCI_MSI))
2837 tegra_pcie_enable_msi(pcie);
2839 err = clk_prepare_enable(pcie->pex_clk);
2841 dev_err(dev, "failed to enable PEX clock: %d\n", err);
2842 goto pex_dpd_enable;
2845 reset_control_deassert(pcie->pex_rst);
2847 if (pcie->soc->program_uphy) {
2848 err = tegra_pcie_phy_power_on(pcie);
2850 dev_err(dev, "failed to power on PHY(s): %d\n", err);
2851 goto disable_pex_clk;
2855 tegra_pcie_apply_pad_settings(pcie);
2856 tegra_pcie_enable_ports(pcie);
2861 reset_control_assert(pcie->pex_rst);
2862 clk_disable_unprepare(pcie->pex_clk);
2864 pinctrl_pm_select_idle_state(dev);
2866 tegra_pcie_power_off(pcie);
2871 static const struct dev_pm_ops tegra_pcie_pm_ops = {
2872 SET_RUNTIME_PM_OPS(tegra_pcie_pm_suspend, tegra_pcie_pm_resume, NULL)
2873 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(tegra_pcie_pm_suspend,
2874 tegra_pcie_pm_resume)
2877 static struct platform_driver tegra_pcie_driver = {
2879 .name = "tegra-pcie",
2880 .of_match_table = tegra_pcie_of_match,
2881 .suppress_bind_attrs = true,
2882 .pm = &tegra_pcie_pm_ops,
2884 .probe = tegra_pcie_probe,
2885 .remove = tegra_pcie_remove,
2887 module_platform_driver(tegra_pcie_driver);
2888 MODULE_LICENSE("GPL");