1 // SPDX-License-Identifier: GPL-2.0
3 * Freescale i.MX6 PCI Express Root-Complex driver
7 * Based on upstream Linux kernel driver:
11 * This is a legacy PCIe iMX driver kept to support older iMX6 SoCs. It is
12 * rather tied to quite old port of pcie-designware driver from Linux which
13 * suffices only iMX6 specific needs. But now we have modern PCIe iMX driver
14 * (drivers/pci/pcie_dw_imx.c) utilizing all the common DWC specific bits from
15 * (drivers/pci/pcie_dw_common.*). So you are encouraged to add any further iMX
16 * SoC support there or even better if you posses older iMX6 SoCs then switch
17 * those too in order to have a single modern PCIe iMX driver.
24 #include <power/regulator.h>
25 #include <asm/arch/clock.h>
26 #include <asm/arch/iomux.h>
27 #include <asm/arch/crm_regs.h>
31 #include <linux/delay.h>
32 #include <linux/sizes.h>
34 #include <asm/arch/sys_proto.h>
36 #define PCI_ACCESS_READ 0
37 #define PCI_ACCESS_WRITE 1
40 #define MX6_DBI_ADDR 0x08ffc000
41 #define MX6_IO_ADDR 0x08000000
42 #define MX6_MEM_ADDR 0x08100000
43 #define MX6_ROOT_ADDR 0x08f00000
45 #define MX6_DBI_ADDR 0x01ffc000
46 #define MX6_IO_ADDR 0x01000000
47 #define MX6_MEM_ADDR 0x01100000
48 #define MX6_ROOT_ADDR 0x01f00000
50 #define MX6_DBI_SIZE 0x4000
51 #define MX6_IO_SIZE 0x100000
52 #define MX6_MEM_SIZE 0xe00000
53 #define MX6_ROOT_SIZE 0xfc000
55 /* PCIe Port Logic registers (memory-mapped) */
56 #define PL_OFFSET 0x700
57 #define PCIE_PL_PFLR (PL_OFFSET + 0x08)
58 #define PCIE_PL_PFLR_LINK_STATE_MASK (0x3f << 16)
59 #define PCIE_PL_PFLR_FORCE_LINK (1 << 15)
60 #define PCIE_PHY_DEBUG_R0 (PL_OFFSET + 0x28)
61 #define PCIE_PHY_DEBUG_R1 (PL_OFFSET + 0x2c)
62 #define PCIE_PHY_DEBUG_R1_LINK_UP (1 << 4)
63 #define PCIE_PHY_DEBUG_R1_LINK_IN_TRAINING (1 << 29)
65 #define PCIE_PHY_CTRL (PL_OFFSET + 0x114)
66 #define PCIE_PHY_CTRL_DATA_LOC 0
67 #define PCIE_PHY_CTRL_CAP_ADR_LOC 16
68 #define PCIE_PHY_CTRL_CAP_DAT_LOC 17
69 #define PCIE_PHY_CTRL_WR_LOC 18
70 #define PCIE_PHY_CTRL_RD_LOC 19
72 #define PCIE_PHY_STAT (PL_OFFSET + 0x110)
73 #define PCIE_PHY_STAT_DATA_LOC 0
74 #define PCIE_PHY_STAT_ACK_LOC 16
76 /* PHY registers (not memory-mapped) */
77 #define PCIE_PHY_RX_ASIC_OUT 0x100D
79 #define PHY_RX_OVRD_IN_LO 0x1005
80 #define PHY_RX_OVRD_IN_LO_RX_DATA_EN (1 << 5)
81 #define PHY_RX_OVRD_IN_LO_RX_PLL_EN (1 << 3)
83 #define PCIE_PHY_PUP_REQ (1 << 7)
86 #define PCIE_ATU_VIEWPORT 0x900
87 #define PCIE_ATU_REGION_INBOUND (0x1 << 31)
88 #define PCIE_ATU_REGION_OUTBOUND (0x0 << 31)
89 #define PCIE_ATU_REGION_INDEX1 (0x1 << 0)
90 #define PCIE_ATU_REGION_INDEX0 (0x0 << 0)
91 #define PCIE_ATU_CR1 0x904
92 #define PCIE_ATU_TYPE_MEM (0x0 << 0)
93 #define PCIE_ATU_TYPE_IO (0x2 << 0)
94 #define PCIE_ATU_TYPE_CFG0 (0x4 << 0)
95 #define PCIE_ATU_TYPE_CFG1 (0x5 << 0)
96 #define PCIE_ATU_CR2 0x908
97 #define PCIE_ATU_ENABLE (0x1 << 31)
98 #define PCIE_ATU_BAR_MODE_ENABLE (0x1 << 30)
99 #define PCIE_ATU_LOWER_BASE 0x90C
100 #define PCIE_ATU_UPPER_BASE 0x910
101 #define PCIE_ATU_LIMIT 0x914
102 #define PCIE_ATU_LOWER_TARGET 0x918
103 #define PCIE_ATU_BUS(x) (((x) & 0xff) << 24)
104 #define PCIE_ATU_DEV(x) (((x) & 0x1f) << 19)
105 #define PCIE_ATU_FUNC(x) (((x) & 0x7) << 16)
106 #define PCIE_ATU_UPPER_TARGET 0x91C
108 struct imx_pcie_priv {
109 void __iomem *dbi_base;
110 void __iomem *cfg_base;
111 struct gpio_desc reset_gpio;
112 bool reset_active_high;
113 struct udevice *vpcie;
117 * PHY access functions
119 static int pcie_phy_poll_ack(void __iomem *dbi_base, int exp_val)
122 u32 max_iterations = 10;
123 u32 wait_counter = 0;
126 val = readl(dbi_base + PCIE_PHY_STAT);
127 val = (val >> PCIE_PHY_STAT_ACK_LOC) & 0x1;
134 } while (wait_counter < max_iterations);
139 static int pcie_phy_wait_ack(void __iomem *dbi_base, int addr)
144 val = addr << PCIE_PHY_CTRL_DATA_LOC;
145 writel(val, dbi_base + PCIE_PHY_CTRL);
147 val |= (0x1 << PCIE_PHY_CTRL_CAP_ADR_LOC);
148 writel(val, dbi_base + PCIE_PHY_CTRL);
150 ret = pcie_phy_poll_ack(dbi_base, 1);
154 val = addr << PCIE_PHY_CTRL_DATA_LOC;
155 writel(val, dbi_base + PCIE_PHY_CTRL);
157 ret = pcie_phy_poll_ack(dbi_base, 0);
164 /* Read from the 16-bit PCIe PHY control registers (not memory-mapped) */
165 static int pcie_phy_read(void __iomem *dbi_base, int addr , int *data)
170 ret = pcie_phy_wait_ack(dbi_base, addr);
174 /* assert Read signal */
175 phy_ctl = 0x1 << PCIE_PHY_CTRL_RD_LOC;
176 writel(phy_ctl, dbi_base + PCIE_PHY_CTRL);
178 ret = pcie_phy_poll_ack(dbi_base, 1);
182 val = readl(dbi_base + PCIE_PHY_STAT);
183 *data = val & 0xffff;
185 /* deassert Read signal */
186 writel(0x00, dbi_base + PCIE_PHY_CTRL);
188 ret = pcie_phy_poll_ack(dbi_base, 0);
195 static int pcie_phy_write(void __iomem *dbi_base, int addr, int data)
202 ret = pcie_phy_wait_ack(dbi_base, addr);
206 var = data << PCIE_PHY_CTRL_DATA_LOC;
207 writel(var, dbi_base + PCIE_PHY_CTRL);
210 var |= (0x1 << PCIE_PHY_CTRL_CAP_DAT_LOC);
211 writel(var, dbi_base + PCIE_PHY_CTRL);
213 ret = pcie_phy_poll_ack(dbi_base, 1);
217 /* deassert cap data */
218 var = data << PCIE_PHY_CTRL_DATA_LOC;
219 writel(var, dbi_base + PCIE_PHY_CTRL);
221 /* wait for ack de-assertion */
222 ret = pcie_phy_poll_ack(dbi_base, 0);
226 /* assert wr signal */
227 var = 0x1 << PCIE_PHY_CTRL_WR_LOC;
228 writel(var, dbi_base + PCIE_PHY_CTRL);
231 ret = pcie_phy_poll_ack(dbi_base, 1);
235 /* deassert wr signal */
236 var = data << PCIE_PHY_CTRL_DATA_LOC;
237 writel(var, dbi_base + PCIE_PHY_CTRL);
239 /* wait for ack de-assertion */
240 ret = pcie_phy_poll_ack(dbi_base, 0);
244 writel(0x0, dbi_base + PCIE_PHY_CTRL);
249 static int imx6_pcie_link_up(struct imx_pcie_priv *priv)
254 /* link is debug bit 36, debug register 1 starts at bit 32 */
255 rc = readl(priv->dbi_base + PCIE_PHY_DEBUG_R1);
256 if ((rc & PCIE_PHY_DEBUG_R1_LINK_UP) &&
257 !(rc & PCIE_PHY_DEBUG_R1_LINK_IN_TRAINING))
261 * From L0, initiate MAC entry to gen2 if EP/RC supports gen2.
262 * Wait 2ms (LTSSM timeout is 24ms, PHY lock is ~5us in gen2).
263 * If (MAC/LTSSM.state == Recovery.RcvrLock)
264 * && (PHY/rx_valid==0) then pulse PHY/rx_reset. Transition
267 pcie_phy_read(priv->dbi_base, PCIE_PHY_RX_ASIC_OUT, &rx_valid);
268 ltssm = readl(priv->dbi_base + PCIE_PHY_DEBUG_R0) & 0x3F;
276 printf("transition to gen2 is stuck, reset PHY!\n");
278 pcie_phy_read(priv->dbi_base, PHY_RX_OVRD_IN_LO, &temp);
279 temp |= (PHY_RX_OVRD_IN_LO_RX_DATA_EN | PHY_RX_OVRD_IN_LO_RX_PLL_EN);
280 pcie_phy_write(priv->dbi_base, PHY_RX_OVRD_IN_LO, temp);
284 pcie_phy_read(priv->dbi_base, PHY_RX_OVRD_IN_LO, &temp);
285 temp &= ~(PHY_RX_OVRD_IN_LO_RX_DATA_EN | PHY_RX_OVRD_IN_LO_RX_PLL_EN);
286 pcie_phy_write(priv->dbi_base, PHY_RX_OVRD_IN_LO, temp);
294 static int imx_pcie_regions_setup(struct imx_pcie_priv *priv)
297 * i.MX6 defines 16MB in the AXI address map for PCIe.
299 * That address space excepted the pcie registers is
300 * split and defined into different regions by iATU,
301 * with sizes and offsets as follows:
303 * 0x0100_0000 --- 0x010F_FFFF 1MB IORESOURCE_IO
304 * 0x0110_0000 --- 0x01EF_FFFF 14MB IORESOURCE_MEM
305 * 0x01F0_0000 --- 0x01FF_FFFF 1MB Cfg + Registers
308 /* CMD reg:I/O space, MEM space, and Bus Master Enable */
309 setbits_le32(priv->dbi_base + PCI_COMMAND,
310 PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
312 /* Set the CLASS_REV of RC CFG header to PCI_CLASS_BRIDGE_PCI_NORMAL */
313 setbits_le32(priv->dbi_base + PCI_CLASS_REVISION,
314 PCI_CLASS_BRIDGE_PCI_NORMAL << 8);
316 /* Region #0 is used for Outbound CFG space access. */
317 writel(0, priv->dbi_base + PCIE_ATU_VIEWPORT);
319 writel(lower_32_bits((uintptr_t)priv->cfg_base),
320 priv->dbi_base + PCIE_ATU_LOWER_BASE);
321 writel(upper_32_bits((uintptr_t)priv->cfg_base),
322 priv->dbi_base + PCIE_ATU_UPPER_BASE);
323 writel(lower_32_bits((uintptr_t)priv->cfg_base + MX6_ROOT_SIZE),
324 priv->dbi_base + PCIE_ATU_LIMIT);
326 writel(0, priv->dbi_base + PCIE_ATU_LOWER_TARGET);
327 writel(0, priv->dbi_base + PCIE_ATU_UPPER_TARGET);
328 writel(PCIE_ATU_TYPE_CFG0, priv->dbi_base + PCIE_ATU_CR1);
329 writel(PCIE_ATU_ENABLE, priv->dbi_base + PCIE_ATU_CR2);
335 * PCI Express accessors
337 static void __iomem *get_bus_address(struct imx_pcie_priv *priv,
338 pci_dev_t d, int where)
340 void __iomem *va_address;
342 /* Reconfigure Region #0 */
343 writel(0, priv->dbi_base + PCIE_ATU_VIEWPORT);
346 writel(PCIE_ATU_TYPE_CFG0, priv->dbi_base + PCIE_ATU_CR1);
348 writel(PCIE_ATU_TYPE_CFG1, priv->dbi_base + PCIE_ATU_CR1);
350 if (PCI_BUS(d) == 0) {
351 va_address = priv->dbi_base;
353 writel(d << 8, priv->dbi_base + PCIE_ATU_LOWER_TARGET);
354 va_address = priv->cfg_base;
357 va_address += (where & ~0x3);
362 static int imx_pcie_addr_valid(pci_dev_t d)
364 if ((PCI_BUS(d) == 0) && (PCI_DEV(d) > 1))
366 if ((PCI_BUS(d) == 1) && (PCI_DEV(d) > 0))
372 * Replace the original ARM DABT handler with a simple jump-back one.
374 * The problem here is that if we have a PCIe bridge attached to this PCIe
375 * controller, but no PCIe device is connected to the bridges' downstream
376 * port, the attempt to read/write from/to the config space will produce
377 * a DABT. This is a behavior of the controller and can not be disabled
380 * To work around the problem, we backup the current DABT handler address
381 * and replace it with our own DABT handler, which only bounces right back
384 static void imx_pcie_fix_dabt_handler(bool set)
386 extern uint32_t *_data_abort;
387 uint32_t *data_abort_addr = (uint32_t *)&_data_abort;
389 static const uint32_t data_abort_bounce_handler = 0xe25ef004;
390 uint32_t data_abort_bounce_addr = (uint32_t)&data_abort_bounce_handler;
392 static uint32_t data_abort_backup;
395 data_abort_backup = *data_abort_addr;
396 *data_abort_addr = data_abort_bounce_addr;
398 *data_abort_addr = data_abort_backup;
402 static int imx_pcie_read_cfg(struct imx_pcie_priv *priv, pci_dev_t d,
405 void __iomem *va_address;
408 ret = imx_pcie_addr_valid(d);
414 va_address = get_bus_address(priv, d, where);
417 * Read the PCIe config space. We must replace the DABT handler
418 * here in case we got data abort from the PCIe controller, see
419 * imx_pcie_fix_dabt_handler() description. Note that writing the
420 * "val" with valid value is also imperative here as in case we
421 * did got DABT, the val would contain random value.
423 imx_pcie_fix_dabt_handler(true);
424 writel(0xffffffff, val);
425 *val = readl(va_address);
426 imx_pcie_fix_dabt_handler(false);
431 static int imx_pcie_write_cfg(struct imx_pcie_priv *priv, pci_dev_t d,
434 void __iomem *va_address = NULL;
437 ret = imx_pcie_addr_valid(d);
441 va_address = get_bus_address(priv, d, where);
444 * Write the PCIe config space. We must replace the DABT handler
445 * here in case we got data abort from the PCIe controller, see
446 * imx_pcie_fix_dabt_handler() description.
448 imx_pcie_fix_dabt_handler(true);
449 writel(val, va_address);
450 imx_pcie_fix_dabt_handler(false);
458 static int imx6_pcie_assert_core_reset(struct imx_pcie_priv *priv,
459 bool prepare_for_boot)
461 struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
464 setbits_le32(&iomuxc_regs->gpr[1], IOMUXC_GPR1_PCIE_SW_RST);
466 #if defined(CONFIG_MX6SX)
467 struct gpc *gpc_regs = (struct gpc *)GPC_BASE_ADDR;
469 /* SSP_EN is not used on MX6SX anymore */
470 setbits_le32(&iomuxc_regs->gpr[12], IOMUXC_GPR12_TEST_POWERDOWN);
471 /* Force PCIe PHY reset */
472 setbits_le32(&iomuxc_regs->gpr[5], IOMUXC_GPR5_PCIE_BTNRST);
473 /* Power up PCIe PHY */
474 setbits_le32(&gpc_regs->cntr, PCIE_PHY_PUP_REQ);
477 * If the bootloader already enabled the link we need some special
478 * handling to get the core back into a state where it is safe to
479 * touch it for configuration. As there is no dedicated reset signal
480 * wired up for MX6QDL, we need to manually force LTSSM into "detect"
481 * state before completely disabling LTSSM, which is a prerequisite
482 * for core configuration.
484 * If both LTSSM_ENABLE and REF_SSP_ENABLE are active we have a strong
485 * indication that the bootloader activated the link.
487 if ((is_mx6dq() || is_mx6sdl()) && prepare_for_boot) {
488 u32 val, gpr1, gpr12;
490 gpr1 = readl(&iomuxc_regs->gpr[1]);
491 gpr12 = readl(&iomuxc_regs->gpr[12]);
492 if ((gpr1 & IOMUXC_GPR1_PCIE_REF_CLK_EN) &&
493 (gpr12 & IOMUXC_GPR12_PCIE_CTL_2)) {
494 val = readl(priv->dbi_base + PCIE_PL_PFLR);
495 val &= ~PCIE_PL_PFLR_LINK_STATE_MASK;
496 val |= PCIE_PL_PFLR_FORCE_LINK;
498 imx_pcie_fix_dabt_handler(true);
499 writel(val, priv->dbi_base + PCIE_PL_PFLR);
500 imx_pcie_fix_dabt_handler(false);
502 gpr12 &= ~IOMUXC_GPR12_PCIE_CTL_2;
503 writel(val, &iomuxc_regs->gpr[12]);
506 setbits_le32(&iomuxc_regs->gpr[1], IOMUXC_GPR1_TEST_POWERDOWN);
507 clrbits_le32(&iomuxc_regs->gpr[1], IOMUXC_GPR1_REF_SSP_EN);
513 static int imx6_pcie_init_phy(void)
515 struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
517 clrbits_le32(&iomuxc_regs->gpr[12], IOMUXC_GPR12_APPS_LTSSM_ENABLE);
519 clrsetbits_le32(&iomuxc_regs->gpr[12],
520 IOMUXC_GPR12_DEVICE_TYPE_MASK,
521 IOMUXC_GPR12_DEVICE_TYPE_RC);
522 clrsetbits_le32(&iomuxc_regs->gpr[12],
523 IOMUXC_GPR12_LOS_LEVEL_MASK,
524 IOMUXC_GPR12_LOS_LEVEL_9);
527 clrsetbits_le32(&iomuxc_regs->gpr[12],
528 IOMUXC_GPR12_RX_EQ_MASK,
529 IOMUXC_GPR12_RX_EQ_2);
532 writel((0x0 << IOMUXC_GPR8_PCS_TX_DEEMPH_GEN1_OFFSET) |
533 (0x0 << IOMUXC_GPR8_PCS_TX_DEEMPH_GEN2_3P5DB_OFFSET) |
534 (20 << IOMUXC_GPR8_PCS_TX_DEEMPH_GEN2_6DB_OFFSET) |
535 (127 << IOMUXC_GPR8_PCS_TX_SWING_FULL_OFFSET) |
536 (127 << IOMUXC_GPR8_PCS_TX_SWING_LOW_OFFSET),
537 &iomuxc_regs->gpr[8]);
542 int imx6_pcie_toggle_power(struct udevice *vpcie)
544 #ifdef CFG_PCIE_IMX_POWER_GPIO
545 gpio_request(CFG_PCIE_IMX_POWER_GPIO, "pcie_power");
546 gpio_direction_output(CFG_PCIE_IMX_POWER_GPIO, 0);
548 gpio_set_value(CFG_PCIE_IMX_POWER_GPIO, 1);
550 gpio_free(CFG_PCIE_IMX_POWER_GPIO);
553 #if CONFIG_IS_ENABLED(DM_REGULATOR)
555 regulator_set_enable(vpcie, false);
557 regulator_set_enable(vpcie, true);
564 int imx6_pcie_toggle_reset(struct gpio_desc *gpio, bool active_high)
567 * See 'PCI EXPRESS BASE SPECIFICATION, REV 3.0, SECTION 6.6.1'
568 * for detailed understanding of the PCIe CR reset logic.
570 * The PCIe #PERST reset line _MUST_ be connected, otherwise your
571 * design does not conform to the specification. You must wait at
572 * least 20 ms after de-asserting the #PERST so the EP device can
573 * do self-initialisation.
575 * In case your #PERST pin is connected to a plain GPIO pin of the
576 * CPU, you can define CFG_PCIE_IMX_PERST_GPIO in your board's
577 * configuration file and the condition below will handle the rest
578 * of the reset toggling.
580 * In case your #PERST line of the PCIe EP device is not connected
581 * at all, your design is broken and you should fix your design,
582 * otherwise you will observe problems like for example the link
583 * not coming up after rebooting the system back from running Linux
584 * that uses the PCIe as well OR the PCIe link might not come up in
585 * Linux at all in the first place since it's in some non-reset
586 * state due to being previously used in U-Boot.
588 #ifdef CFG_PCIE_IMX_PERST_GPIO
589 gpio_request(CFG_PCIE_IMX_PERST_GPIO, "pcie_reset");
590 gpio_direction_output(CFG_PCIE_IMX_PERST_GPIO, 0);
592 gpio_set_value(CFG_PCIE_IMX_PERST_GPIO, 1);
594 gpio_free(CFG_PCIE_IMX_PERST_GPIO);
596 if (dm_gpio_is_valid(gpio)) {
597 /* Assert PERST# for 20ms then de-assert */
598 dm_gpio_set_value(gpio, active_high ? 0 : 1);
600 dm_gpio_set_value(gpio, active_high ? 1 : 0);
603 puts("WARNING: Make sure the PCIe #PERST line is connected!\n");
609 static int imx6_pcie_deassert_core_reset(struct imx_pcie_priv *priv)
611 struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
613 imx6_pcie_toggle_power(priv->vpcie);
618 clrbits_le32(&iomuxc_regs->gpr[1], IOMUXC_GPR1_PCIE_SW_RST);
621 * Wait for the clock to settle a bit, when the clock are sourced
622 * from the CPU, we need about 30 ms to settle.
626 #if defined(CONFIG_MX6SX)
627 /* SSP_EN is not used on MX6SX anymore */
628 clrbits_le32(&iomuxc_regs->gpr[12], IOMUXC_GPR12_TEST_POWERDOWN);
629 /* Clear PCIe PHY reset bit */
630 clrbits_le32(&iomuxc_regs->gpr[5], IOMUXC_GPR5_PCIE_BTNRST);
633 clrbits_le32(&iomuxc_regs->gpr[1], IOMUXC_GPR1_TEST_POWERDOWN);
634 setbits_le32(&iomuxc_regs->gpr[1], IOMUXC_GPR1_REF_SSP_EN);
637 imx6_pcie_toggle_reset(&priv->reset_gpio, priv->reset_active_high);
642 static int imx_pcie_link_up(struct imx_pcie_priv *priv)
644 struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
648 imx6_pcie_assert_core_reset(priv, false);
649 imx6_pcie_init_phy();
650 imx6_pcie_deassert_core_reset(priv);
652 imx_pcie_regions_setup(priv);
655 * By default, the subordinate is set equally to the secondary
656 * bus (0x01) when the RC boots.
657 * This means that theoretically, only bus 1 is reachable from the RC.
658 * Force the PCIe RC subordinate to 0xff, otherwise no downstream
659 * devices will be detected if the enumeration is applied strictly.
661 tmp = readl(priv->dbi_base + 0x18);
663 writel(tmp, priv->dbi_base + 0x18);
666 * FIXME: Force the PCIe RC to Gen1 operation
667 * The RC must be forced into Gen1 mode before bringing the link
668 * up, otherwise no downstream devices are detected. After the
669 * link is up, a managed Gen1->Gen2 transition can be initiated.
671 tmp = readl(priv->dbi_base + 0x7c);
674 writel(tmp, priv->dbi_base + 0x7c);
676 /* LTSSM enable, starting link. */
677 setbits_le32(&iomuxc_regs->gpr[12], IOMUXC_GPR12_APPS_LTSSM_ENABLE);
679 while (!imx6_pcie_link_up(priv)) {
683 #ifdef CONFIG_PCI_SCAN_SHOW
684 puts("PCI: pcie phy link never came up\n");
686 debug("DEBUG_R0: 0x%08x, DEBUG_R1: 0x%08x\n",
687 readl(priv->dbi_base + PCIE_PHY_DEBUG_R0),
688 readl(priv->dbi_base + PCIE_PHY_DEBUG_R1));
696 static int imx_pcie_dm_read_config(const struct udevice *dev, pci_dev_t bdf,
697 uint offset, ulong *value,
698 enum pci_size_t size)
700 struct imx_pcie_priv *priv = dev_get_priv(dev);
704 ret = imx_pcie_read_cfg(priv, bdf, offset, &tmpval);
708 *value = pci_conv_32_to_size(tmpval, offset, size);
712 static int imx_pcie_dm_write_config(struct udevice *dev, pci_dev_t bdf,
713 uint offset, ulong value,
714 enum pci_size_t size)
716 struct imx_pcie_priv *priv = dev_get_priv(dev);
720 ret = imx_pcie_read_cfg(priv, bdf, offset, &tmpval);
724 newval = pci_conv_size_to_32(tmpval, value, offset, size);
725 return imx_pcie_write_cfg(priv, bdf, offset, newval);
728 static int imx_pcie_dm_probe(struct udevice *dev)
730 struct imx_pcie_priv *priv = dev_get_priv(dev);
732 #if CONFIG_IS_ENABLED(DM_REGULATOR)
733 device_get_supply_regulator(dev, "vpcie-supply", &priv->vpcie);
736 /* if PERST# valid from dt then assert it */
737 gpio_request_by_name(dev, "reset-gpio", 0, &priv->reset_gpio,
739 priv->reset_active_high = dev_read_bool(dev, "reset-gpio-active-high");
740 if (dm_gpio_is_valid(&priv->reset_gpio)) {
741 dm_gpio_set_value(&priv->reset_gpio,
742 priv->reset_active_high ? 0 : 1);
745 return imx_pcie_link_up(priv);
748 static int imx_pcie_dm_remove(struct udevice *dev)
750 struct imx_pcie_priv *priv = dev_get_priv(dev);
752 imx6_pcie_assert_core_reset(priv, true);
757 static int imx_pcie_of_to_plat(struct udevice *dev)
759 struct imx_pcie_priv *priv = dev_get_priv(dev);
761 priv->dbi_base = devfdt_get_addr_index_ptr(dev, 0);
762 priv->cfg_base = devfdt_get_addr_index_ptr(dev, 1);
763 if (!priv->dbi_base || !priv->cfg_base)
769 static const struct dm_pci_ops imx_pcie_ops = {
770 .read_config = imx_pcie_dm_read_config,
771 .write_config = imx_pcie_dm_write_config,
774 static const struct udevice_id imx_pcie_ids[] = {
775 { .compatible = "fsl,imx6q-pcie" },
776 { .compatible = "fsl,imx6sx-pcie" },
780 U_BOOT_DRIVER(imx_pcie) = {
783 .of_match = imx_pcie_ids,
784 .ops = &imx_pcie_ops,
785 .probe = imx_pcie_dm_probe,
786 .remove = imx_pcie_dm_remove,
787 .of_to_plat = imx_pcie_of_to_plat,
788 .priv_auto = sizeof(struct imx_pcie_priv),
789 .flags = DM_FLAG_OS_PREPARE,