1 // SPDX-License-Identifier: GPL-2.0
3 * Freescale i.MX6 PCI Express Root-Complex driver
5 * Copyright (C) 2013 Marek Vasut <marex@denx.de>
7 * Based on upstream Linux kernel driver:
8 * pci-imx6.c: Sean Cross <xobs@kosagi.com>
9 * pcie-designware.c: Jingoo Han <jg1.han@samsung.com>
17 #include <power/regulator.h>
18 #include <asm/arch/clock.h>
19 #include <asm/arch/iomux.h>
20 #include <asm/arch/crm_regs.h>
24 #include <linux/delay.h>
25 #include <linux/sizes.h>
27 #include <asm/arch/sys_proto.h>
29 #define PCI_ACCESS_READ 0
30 #define PCI_ACCESS_WRITE 1
33 #define MX6_DBI_ADDR 0x08ffc000
34 #define MX6_IO_ADDR 0x08000000
35 #define MX6_MEM_ADDR 0x08100000
36 #define MX6_ROOT_ADDR 0x08f00000
38 #define MX6_DBI_ADDR 0x01ffc000
39 #define MX6_IO_ADDR 0x01000000
40 #define MX6_MEM_ADDR 0x01100000
41 #define MX6_ROOT_ADDR 0x01f00000
43 #define MX6_DBI_SIZE 0x4000
44 #define MX6_IO_SIZE 0x100000
45 #define MX6_MEM_SIZE 0xe00000
46 #define MX6_ROOT_SIZE 0xfc000
48 /* PCIe Port Logic registers (memory-mapped) */
49 #define PL_OFFSET 0x700
50 #define PCIE_PL_PFLR (PL_OFFSET + 0x08)
51 #define PCIE_PL_PFLR_LINK_STATE_MASK (0x3f << 16)
52 #define PCIE_PL_PFLR_FORCE_LINK (1 << 15)
53 #define PCIE_PHY_DEBUG_R0 (PL_OFFSET + 0x28)
54 #define PCIE_PHY_DEBUG_R1 (PL_OFFSET + 0x2c)
55 #define PCIE_PHY_DEBUG_R1_LINK_UP (1 << 4)
56 #define PCIE_PHY_DEBUG_R1_LINK_IN_TRAINING (1 << 29)
58 #define PCIE_PHY_CTRL (PL_OFFSET + 0x114)
59 #define PCIE_PHY_CTRL_DATA_LOC 0
60 #define PCIE_PHY_CTRL_CAP_ADR_LOC 16
61 #define PCIE_PHY_CTRL_CAP_DAT_LOC 17
62 #define PCIE_PHY_CTRL_WR_LOC 18
63 #define PCIE_PHY_CTRL_RD_LOC 19
65 #define PCIE_PHY_STAT (PL_OFFSET + 0x110)
66 #define PCIE_PHY_STAT_DATA_LOC 0
67 #define PCIE_PHY_STAT_ACK_LOC 16
69 /* PHY registers (not memory-mapped) */
70 #define PCIE_PHY_RX_ASIC_OUT 0x100D
72 #define PHY_RX_OVRD_IN_LO 0x1005
73 #define PHY_RX_OVRD_IN_LO_RX_DATA_EN (1 << 5)
74 #define PHY_RX_OVRD_IN_LO_RX_PLL_EN (1 << 3)
76 #define PCIE_PHY_PUP_REQ (1 << 7)
79 #define PCIE_ATU_VIEWPORT 0x900
80 #define PCIE_ATU_REGION_INBOUND (0x1 << 31)
81 #define PCIE_ATU_REGION_OUTBOUND (0x0 << 31)
82 #define PCIE_ATU_REGION_INDEX1 (0x1 << 0)
83 #define PCIE_ATU_REGION_INDEX0 (0x0 << 0)
84 #define PCIE_ATU_CR1 0x904
85 #define PCIE_ATU_TYPE_MEM (0x0 << 0)
86 #define PCIE_ATU_TYPE_IO (0x2 << 0)
87 #define PCIE_ATU_TYPE_CFG0 (0x4 << 0)
88 #define PCIE_ATU_TYPE_CFG1 (0x5 << 0)
89 #define PCIE_ATU_CR2 0x908
90 #define PCIE_ATU_ENABLE (0x1 << 31)
91 #define PCIE_ATU_BAR_MODE_ENABLE (0x1 << 30)
92 #define PCIE_ATU_LOWER_BASE 0x90C
93 #define PCIE_ATU_UPPER_BASE 0x910
94 #define PCIE_ATU_LIMIT 0x914
95 #define PCIE_ATU_LOWER_TARGET 0x918
96 #define PCIE_ATU_BUS(x) (((x) & 0xff) << 24)
97 #define PCIE_ATU_DEV(x) (((x) & 0x1f) << 19)
98 #define PCIE_ATU_FUNC(x) (((x) & 0x7) << 16)
99 #define PCIE_ATU_UPPER_TARGET 0x91C
101 struct imx_pcie_priv {
102 void __iomem *dbi_base;
103 void __iomem *cfg_base;
104 struct gpio_desc reset_gpio;
105 bool reset_active_high;
106 struct udevice *vpcie;
110 * PHY access functions
112 static int pcie_phy_poll_ack(void __iomem *dbi_base, int exp_val)
115 u32 max_iterations = 10;
116 u32 wait_counter = 0;
119 val = readl(dbi_base + PCIE_PHY_STAT);
120 val = (val >> PCIE_PHY_STAT_ACK_LOC) & 0x1;
127 } while (wait_counter < max_iterations);
132 static int pcie_phy_wait_ack(void __iomem *dbi_base, int addr)
137 val = addr << PCIE_PHY_CTRL_DATA_LOC;
138 writel(val, dbi_base + PCIE_PHY_CTRL);
140 val |= (0x1 << PCIE_PHY_CTRL_CAP_ADR_LOC);
141 writel(val, dbi_base + PCIE_PHY_CTRL);
143 ret = pcie_phy_poll_ack(dbi_base, 1);
147 val = addr << PCIE_PHY_CTRL_DATA_LOC;
148 writel(val, dbi_base + PCIE_PHY_CTRL);
150 ret = pcie_phy_poll_ack(dbi_base, 0);
157 /* Read from the 16-bit PCIe PHY control registers (not memory-mapped) */
158 static int pcie_phy_read(void __iomem *dbi_base, int addr , int *data)
163 ret = pcie_phy_wait_ack(dbi_base, addr);
167 /* assert Read signal */
168 phy_ctl = 0x1 << PCIE_PHY_CTRL_RD_LOC;
169 writel(phy_ctl, dbi_base + PCIE_PHY_CTRL);
171 ret = pcie_phy_poll_ack(dbi_base, 1);
175 val = readl(dbi_base + PCIE_PHY_STAT);
176 *data = val & 0xffff;
178 /* deassert Read signal */
179 writel(0x00, dbi_base + PCIE_PHY_CTRL);
181 ret = pcie_phy_poll_ack(dbi_base, 0);
188 static int pcie_phy_write(void __iomem *dbi_base, int addr, int data)
195 ret = pcie_phy_wait_ack(dbi_base, addr);
199 var = data << PCIE_PHY_CTRL_DATA_LOC;
200 writel(var, dbi_base + PCIE_PHY_CTRL);
203 var |= (0x1 << PCIE_PHY_CTRL_CAP_DAT_LOC);
204 writel(var, dbi_base + PCIE_PHY_CTRL);
206 ret = pcie_phy_poll_ack(dbi_base, 1);
210 /* deassert cap data */
211 var = data << PCIE_PHY_CTRL_DATA_LOC;
212 writel(var, dbi_base + PCIE_PHY_CTRL);
214 /* wait for ack de-assertion */
215 ret = pcie_phy_poll_ack(dbi_base, 0);
219 /* assert wr signal */
220 var = 0x1 << PCIE_PHY_CTRL_WR_LOC;
221 writel(var, dbi_base + PCIE_PHY_CTRL);
224 ret = pcie_phy_poll_ack(dbi_base, 1);
228 /* deassert wr signal */
229 var = data << PCIE_PHY_CTRL_DATA_LOC;
230 writel(var, dbi_base + PCIE_PHY_CTRL);
232 /* wait for ack de-assertion */
233 ret = pcie_phy_poll_ack(dbi_base, 0);
237 writel(0x0, dbi_base + PCIE_PHY_CTRL);
242 static int imx6_pcie_link_up(struct imx_pcie_priv *priv)
247 /* link is debug bit 36, debug register 1 starts at bit 32 */
248 rc = readl(priv->dbi_base + PCIE_PHY_DEBUG_R1);
249 if ((rc & PCIE_PHY_DEBUG_R1_LINK_UP) &&
250 !(rc & PCIE_PHY_DEBUG_R1_LINK_IN_TRAINING))
254 * From L0, initiate MAC entry to gen2 if EP/RC supports gen2.
255 * Wait 2ms (LTSSM timeout is 24ms, PHY lock is ~5us in gen2).
256 * If (MAC/LTSSM.state == Recovery.RcvrLock)
257 * && (PHY/rx_valid==0) then pulse PHY/rx_reset. Transition
260 pcie_phy_read(priv->dbi_base, PCIE_PHY_RX_ASIC_OUT, &rx_valid);
261 ltssm = readl(priv->dbi_base + PCIE_PHY_DEBUG_R0) & 0x3F;
269 printf("transition to gen2 is stuck, reset PHY!\n");
271 pcie_phy_read(priv->dbi_base, PHY_RX_OVRD_IN_LO, &temp);
272 temp |= (PHY_RX_OVRD_IN_LO_RX_DATA_EN | PHY_RX_OVRD_IN_LO_RX_PLL_EN);
273 pcie_phy_write(priv->dbi_base, PHY_RX_OVRD_IN_LO, temp);
277 pcie_phy_read(priv->dbi_base, PHY_RX_OVRD_IN_LO, &temp);
278 temp &= ~(PHY_RX_OVRD_IN_LO_RX_DATA_EN | PHY_RX_OVRD_IN_LO_RX_PLL_EN);
279 pcie_phy_write(priv->dbi_base, PHY_RX_OVRD_IN_LO, temp);
287 static int imx_pcie_regions_setup(struct imx_pcie_priv *priv)
290 * i.MX6 defines 16MB in the AXI address map for PCIe.
292 * That address space excepted the pcie registers is
293 * split and defined into different regions by iATU,
294 * with sizes and offsets as follows:
296 * 0x0100_0000 --- 0x010F_FFFF 1MB IORESOURCE_IO
297 * 0x0110_0000 --- 0x01EF_FFFF 14MB IORESOURCE_MEM
298 * 0x01F0_0000 --- 0x01FF_FFFF 1MB Cfg + Registers
301 /* CMD reg:I/O space, MEM space, and Bus Master Enable */
302 setbits_le32(priv->dbi_base + PCI_COMMAND,
303 PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
305 /* Set the CLASS_REV of RC CFG header to PCI_CLASS_BRIDGE_PCI_NORMAL */
306 setbits_le32(priv->dbi_base + PCI_CLASS_REVISION,
307 PCI_CLASS_BRIDGE_PCI_NORMAL << 8);
309 /* Region #0 is used for Outbound CFG space access. */
310 writel(0, priv->dbi_base + PCIE_ATU_VIEWPORT);
312 writel(lower_32_bits((uintptr_t)priv->cfg_base),
313 priv->dbi_base + PCIE_ATU_LOWER_BASE);
314 writel(upper_32_bits((uintptr_t)priv->cfg_base),
315 priv->dbi_base + PCIE_ATU_UPPER_BASE);
316 writel(lower_32_bits((uintptr_t)priv->cfg_base + MX6_ROOT_SIZE),
317 priv->dbi_base + PCIE_ATU_LIMIT);
319 writel(0, priv->dbi_base + PCIE_ATU_LOWER_TARGET);
320 writel(0, priv->dbi_base + PCIE_ATU_UPPER_TARGET);
321 writel(PCIE_ATU_TYPE_CFG0, priv->dbi_base + PCIE_ATU_CR1);
322 writel(PCIE_ATU_ENABLE, priv->dbi_base + PCIE_ATU_CR2);
328 * PCI Express accessors
330 static void __iomem *get_bus_address(struct imx_pcie_priv *priv,
331 pci_dev_t d, int where)
333 void __iomem *va_address;
335 /* Reconfigure Region #0 */
336 writel(0, priv->dbi_base + PCIE_ATU_VIEWPORT);
339 writel(PCIE_ATU_TYPE_CFG0, priv->dbi_base + PCIE_ATU_CR1);
341 writel(PCIE_ATU_TYPE_CFG1, priv->dbi_base + PCIE_ATU_CR1);
343 if (PCI_BUS(d) == 0) {
344 va_address = priv->dbi_base;
346 writel(d << 8, priv->dbi_base + PCIE_ATU_LOWER_TARGET);
347 va_address = priv->cfg_base;
350 va_address += (where & ~0x3);
355 static int imx_pcie_addr_valid(pci_dev_t d)
357 if ((PCI_BUS(d) == 0) && (PCI_DEV(d) > 1))
359 if ((PCI_BUS(d) == 1) && (PCI_DEV(d) > 0))
365 * Replace the original ARM DABT handler with a simple jump-back one.
367 * The problem here is that if we have a PCIe bridge attached to this PCIe
368 * controller, but no PCIe device is connected to the bridges' downstream
369 * port, the attempt to read/write from/to the config space will produce
370 * a DABT. This is a behavior of the controller and can not be disabled
373 * To work around the problem, we backup the current DABT handler address
374 * and replace it with our own DABT handler, which only bounces right back
377 static void imx_pcie_fix_dabt_handler(bool set)
379 extern uint32_t *_data_abort;
380 uint32_t *data_abort_addr = (uint32_t *)&_data_abort;
382 static const uint32_t data_abort_bounce_handler = 0xe25ef004;
383 uint32_t data_abort_bounce_addr = (uint32_t)&data_abort_bounce_handler;
385 static uint32_t data_abort_backup;
388 data_abort_backup = *data_abort_addr;
389 *data_abort_addr = data_abort_bounce_addr;
391 *data_abort_addr = data_abort_backup;
395 static int imx_pcie_read_cfg(struct imx_pcie_priv *priv, pci_dev_t d,
398 void __iomem *va_address;
401 ret = imx_pcie_addr_valid(d);
407 va_address = get_bus_address(priv, d, where);
410 * Read the PCIe config space. We must replace the DABT handler
411 * here in case we got data abort from the PCIe controller, see
412 * imx_pcie_fix_dabt_handler() description. Note that writing the
413 * "val" with valid value is also imperative here as in case we
414 * did got DABT, the val would contain random value.
416 imx_pcie_fix_dabt_handler(true);
417 writel(0xffffffff, val);
418 *val = readl(va_address);
419 imx_pcie_fix_dabt_handler(false);
424 static int imx_pcie_write_cfg(struct imx_pcie_priv *priv, pci_dev_t d,
427 void __iomem *va_address = NULL;
430 ret = imx_pcie_addr_valid(d);
434 va_address = get_bus_address(priv, d, where);
437 * Write the PCIe config space. We must replace the DABT handler
438 * here in case we got data abort from the PCIe controller, see
439 * imx_pcie_fix_dabt_handler() description.
441 imx_pcie_fix_dabt_handler(true);
442 writel(val, va_address);
443 imx_pcie_fix_dabt_handler(false);
451 static int imx6_pcie_assert_core_reset(struct imx_pcie_priv *priv,
452 bool prepare_for_boot)
454 struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
457 setbits_le32(&iomuxc_regs->gpr[1], IOMUXC_GPR1_PCIE_SW_RST);
459 #if defined(CONFIG_MX6SX)
460 struct gpc *gpc_regs = (struct gpc *)GPC_BASE_ADDR;
462 /* SSP_EN is not used on MX6SX anymore */
463 setbits_le32(&iomuxc_regs->gpr[12], IOMUXC_GPR12_TEST_POWERDOWN);
464 /* Force PCIe PHY reset */
465 setbits_le32(&iomuxc_regs->gpr[5], IOMUXC_GPR5_PCIE_BTNRST);
466 /* Power up PCIe PHY */
467 setbits_le32(&gpc_regs->cntr, PCIE_PHY_PUP_REQ);
470 * If the bootloader already enabled the link we need some special
471 * handling to get the core back into a state where it is safe to
472 * touch it for configuration. As there is no dedicated reset signal
473 * wired up for MX6QDL, we need to manually force LTSSM into "detect"
474 * state before completely disabling LTSSM, which is a prerequisite
475 * for core configuration.
477 * If both LTSSM_ENABLE and REF_SSP_ENABLE are active we have a strong
478 * indication that the bootloader activated the link.
480 if ((is_mx6dq() || is_mx6sdl()) && prepare_for_boot) {
481 u32 val, gpr1, gpr12;
483 gpr1 = readl(&iomuxc_regs->gpr[1]);
484 gpr12 = readl(&iomuxc_regs->gpr[12]);
485 if ((gpr1 & IOMUXC_GPR1_PCIE_REF_CLK_EN) &&
486 (gpr12 & IOMUXC_GPR12_PCIE_CTL_2)) {
487 val = readl(priv->dbi_base + PCIE_PL_PFLR);
488 val &= ~PCIE_PL_PFLR_LINK_STATE_MASK;
489 val |= PCIE_PL_PFLR_FORCE_LINK;
491 imx_pcie_fix_dabt_handler(true);
492 writel(val, priv->dbi_base + PCIE_PL_PFLR);
493 imx_pcie_fix_dabt_handler(false);
495 gpr12 &= ~IOMUXC_GPR12_PCIE_CTL_2;
496 writel(val, &iomuxc_regs->gpr[12]);
499 setbits_le32(&iomuxc_regs->gpr[1], IOMUXC_GPR1_TEST_POWERDOWN);
500 clrbits_le32(&iomuxc_regs->gpr[1], IOMUXC_GPR1_REF_SSP_EN);
506 static int imx6_pcie_init_phy(void)
508 struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
510 clrbits_le32(&iomuxc_regs->gpr[12], IOMUXC_GPR12_APPS_LTSSM_ENABLE);
512 clrsetbits_le32(&iomuxc_regs->gpr[12],
513 IOMUXC_GPR12_DEVICE_TYPE_MASK,
514 IOMUXC_GPR12_DEVICE_TYPE_RC);
515 clrsetbits_le32(&iomuxc_regs->gpr[12],
516 IOMUXC_GPR12_LOS_LEVEL_MASK,
517 IOMUXC_GPR12_LOS_LEVEL_9);
520 clrsetbits_le32(&iomuxc_regs->gpr[12],
521 IOMUXC_GPR12_RX_EQ_MASK,
522 IOMUXC_GPR12_RX_EQ_2);
525 writel((0x0 << IOMUXC_GPR8_PCS_TX_DEEMPH_GEN1_OFFSET) |
526 (0x0 << IOMUXC_GPR8_PCS_TX_DEEMPH_GEN2_3P5DB_OFFSET) |
527 (20 << IOMUXC_GPR8_PCS_TX_DEEMPH_GEN2_6DB_OFFSET) |
528 (127 << IOMUXC_GPR8_PCS_TX_SWING_FULL_OFFSET) |
529 (127 << IOMUXC_GPR8_PCS_TX_SWING_LOW_OFFSET),
530 &iomuxc_regs->gpr[8]);
535 int imx6_pcie_toggle_power(struct udevice *vpcie)
537 #ifdef CONFIG_PCIE_IMX_POWER_GPIO
538 gpio_request(CONFIG_PCIE_IMX_POWER_GPIO, "pcie_power");
539 gpio_direction_output(CONFIG_PCIE_IMX_POWER_GPIO, 0);
541 gpio_set_value(CONFIG_PCIE_IMX_POWER_GPIO, 1);
543 gpio_free(CONFIG_PCIE_IMX_POWER_GPIO);
546 #if CONFIG_IS_ENABLED(DM_REGULATOR)
548 regulator_set_enable(vpcie, false);
550 regulator_set_enable(vpcie, true);
557 int imx6_pcie_toggle_reset(struct gpio_desc *gpio, bool active_high)
560 * See 'PCI EXPRESS BASE SPECIFICATION, REV 3.0, SECTION 6.6.1'
561 * for detailed understanding of the PCIe CR reset logic.
563 * The PCIe #PERST reset line _MUST_ be connected, otherwise your
564 * design does not conform to the specification. You must wait at
565 * least 20 ms after de-asserting the #PERST so the EP device can
566 * do self-initialisation.
568 * In case your #PERST pin is connected to a plain GPIO pin of the
569 * CPU, you can define CONFIG_PCIE_IMX_PERST_GPIO in your board's
570 * configuration file and the condition below will handle the rest
571 * of the reset toggling.
573 * In case your #PERST line of the PCIe EP device is not connected
574 * at all, your design is broken and you should fix your design,
575 * otherwise you will observe problems like for example the link
576 * not coming up after rebooting the system back from running Linux
577 * that uses the PCIe as well OR the PCIe link might not come up in
578 * Linux at all in the first place since it's in some non-reset
579 * state due to being previously used in U-Boot.
581 #ifdef CONFIG_PCIE_IMX_PERST_GPIO
582 gpio_request(CONFIG_PCIE_IMX_PERST_GPIO, "pcie_reset");
583 gpio_direction_output(CONFIG_PCIE_IMX_PERST_GPIO, 0);
585 gpio_set_value(CONFIG_PCIE_IMX_PERST_GPIO, 1);
587 gpio_free(CONFIG_PCIE_IMX_PERST_GPIO);
589 if (dm_gpio_is_valid(gpio)) {
590 /* Assert PERST# for 20ms then de-assert */
591 dm_gpio_set_value(gpio, active_high ? 0 : 1);
593 dm_gpio_set_value(gpio, active_high ? 1 : 0);
596 puts("WARNING: Make sure the PCIe #PERST line is connected!\n");
602 static int imx6_pcie_deassert_core_reset(struct imx_pcie_priv *priv)
604 struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
606 imx6_pcie_toggle_power(priv->vpcie);
611 clrbits_le32(&iomuxc_regs->gpr[1], IOMUXC_GPR1_PCIE_SW_RST);
614 * Wait for the clock to settle a bit, when the clock are sourced
615 * from the CPU, we need about 30 ms to settle.
619 #if defined(CONFIG_MX6SX)
620 /* SSP_EN is not used on MX6SX anymore */
621 clrbits_le32(&iomuxc_regs->gpr[12], IOMUXC_GPR12_TEST_POWERDOWN);
622 /* Clear PCIe PHY reset bit */
623 clrbits_le32(&iomuxc_regs->gpr[5], IOMUXC_GPR5_PCIE_BTNRST);
626 clrbits_le32(&iomuxc_regs->gpr[1], IOMUXC_GPR1_TEST_POWERDOWN);
627 setbits_le32(&iomuxc_regs->gpr[1], IOMUXC_GPR1_REF_SSP_EN);
630 imx6_pcie_toggle_reset(&priv->reset_gpio, priv->reset_active_high);
635 static int imx_pcie_link_up(struct imx_pcie_priv *priv)
637 struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
641 imx6_pcie_assert_core_reset(priv, false);
642 imx6_pcie_init_phy();
643 imx6_pcie_deassert_core_reset(priv);
645 imx_pcie_regions_setup(priv);
648 * By default, the subordinate is set equally to the secondary
649 * bus (0x01) when the RC boots.
650 * This means that theoretically, only bus 1 is reachable from the RC.
651 * Force the PCIe RC subordinate to 0xff, otherwise no downstream
652 * devices will be detected if the enumeration is applied strictly.
654 tmp = readl(priv->dbi_base + 0x18);
656 writel(tmp, priv->dbi_base + 0x18);
659 * FIXME: Force the PCIe RC to Gen1 operation
660 * The RC must be forced into Gen1 mode before bringing the link
661 * up, otherwise no downstream devices are detected. After the
662 * link is up, a managed Gen1->Gen2 transition can be initiated.
664 tmp = readl(priv->dbi_base + 0x7c);
667 writel(tmp, priv->dbi_base + 0x7c);
669 /* LTSSM enable, starting link. */
670 setbits_le32(&iomuxc_regs->gpr[12], IOMUXC_GPR12_APPS_LTSSM_ENABLE);
672 while (!imx6_pcie_link_up(priv)) {
676 #ifdef CONFIG_PCI_SCAN_SHOW
677 puts("PCI: pcie phy link never came up\n");
679 debug("DEBUG_R0: 0x%08x, DEBUG_R1: 0x%08x\n",
680 readl(priv->dbi_base + PCIE_PHY_DEBUG_R0),
681 readl(priv->dbi_base + PCIE_PHY_DEBUG_R1));
689 static int imx_pcie_dm_read_config(const struct udevice *dev, pci_dev_t bdf,
690 uint offset, ulong *value,
691 enum pci_size_t size)
693 struct imx_pcie_priv *priv = dev_get_priv(dev);
697 ret = imx_pcie_read_cfg(priv, bdf, offset, &tmpval);
701 *value = pci_conv_32_to_size(tmpval, offset, size);
705 static int imx_pcie_dm_write_config(struct udevice *dev, pci_dev_t bdf,
706 uint offset, ulong value,
707 enum pci_size_t size)
709 struct imx_pcie_priv *priv = dev_get_priv(dev);
713 ret = imx_pcie_read_cfg(priv, bdf, offset, &tmpval);
717 newval = pci_conv_size_to_32(tmpval, value, offset, size);
718 return imx_pcie_write_cfg(priv, bdf, offset, newval);
721 static int imx_pcie_dm_probe(struct udevice *dev)
723 struct imx_pcie_priv *priv = dev_get_priv(dev);
725 #if CONFIG_IS_ENABLED(DM_REGULATOR)
726 device_get_supply_regulator(dev, "vpcie-supply", &priv->vpcie);
729 /* if PERST# valid from dt then assert it */
730 gpio_request_by_name(dev, "reset-gpio", 0, &priv->reset_gpio,
732 priv->reset_active_high = dev_read_bool(dev, "reset-gpio-active-high");
733 if (dm_gpio_is_valid(&priv->reset_gpio)) {
734 dm_gpio_set_value(&priv->reset_gpio,
735 priv->reset_active_high ? 0 : 1);
738 return imx_pcie_link_up(priv);
741 static int imx_pcie_dm_remove(struct udevice *dev)
743 struct imx_pcie_priv *priv = dev_get_priv(dev);
745 imx6_pcie_assert_core_reset(priv, true);
750 static int imx_pcie_of_to_plat(struct udevice *dev)
752 struct imx_pcie_priv *priv = dev_get_priv(dev);
754 priv->dbi_base = (void __iomem *)devfdt_get_addr_index(dev, 0);
755 priv->cfg_base = (void __iomem *)devfdt_get_addr_index(dev, 1);
756 if (!priv->dbi_base || !priv->cfg_base)
762 static const struct dm_pci_ops imx_pcie_ops = {
763 .read_config = imx_pcie_dm_read_config,
764 .write_config = imx_pcie_dm_write_config,
767 static const struct udevice_id imx_pcie_ids[] = {
768 { .compatible = "fsl,imx6q-pcie" },
769 { .compatible = "fsl,imx6sx-pcie" },
773 U_BOOT_DRIVER(imx_pcie) = {
776 .of_match = imx_pcie_ids,
777 .ops = &imx_pcie_ops,
778 .probe = imx_pcie_dm_probe,
779 .remove = imx_pcie_dm_remove,
780 .of_to_plat = imx_pcie_of_to_plat,
781 .priv_auto = sizeof(struct imx_pcie_priv),
782 .flags = DM_FLAG_OS_PREPARE,