2 * PCIe host controller driver for Freescale i.MX6 SoCs
4 * Copyright (C) 2013 Kosagi
5 * http://www.kosagi.com
7 * Author: Sean Cross <xobs@kosagi.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 #include <linux/clk.h>
15 #include <linux/delay.h>
16 #include <linux/gpio.h>
17 #include <linux/kernel.h>
18 #include <linux/mfd/syscon.h>
19 #include <linux/mfd/syscon/imx6q-iomuxc-gpr.h>
20 #include <linux/module.h>
21 #include <linux/of_gpio.h>
22 #include <linux/of_device.h>
23 #include <linux/pci.h>
24 #include <linux/platform_device.h>
25 #include <linux/regmap.h>
26 #include <linux/resource.h>
27 #include <linux/signal.h>
28 #include <linux/types.h>
29 #include <linux/interrupt.h>
31 #include "pcie-designware.h"
33 #define to_imx6_pcie(x) container_of(x, struct imx6_pcie, pp)
35 enum imx6_pcie_variants {
42 struct pcie_port pp; /* pp.dbi_base is DT 0th resource */
44 bool gpio_active_high;
47 struct clk *pcie_inbound_axi;
49 struct regmap *iomuxc_gpr;
50 enum imx6_pcie_variants variant;
52 u32 tx_deemph_gen2_3p5db;
53 u32 tx_deemph_gen2_6db;
59 /* PCIe Root Complex registers (memory-mapped) */
60 #define PCIE_RC_LCR 0x7c
61 #define PCIE_RC_LCR_MAX_LINK_SPEEDS_GEN1 0x1
62 #define PCIE_RC_LCR_MAX_LINK_SPEEDS_GEN2 0x2
63 #define PCIE_RC_LCR_MAX_LINK_SPEEDS_MASK 0xf
65 #define PCIE_RC_LCSR 0x80
67 /* PCIe Port Logic registers (memory-mapped) */
68 #define PL_OFFSET 0x700
69 #define PCIE_PL_PFLR (PL_OFFSET + 0x08)
70 #define PCIE_PL_PFLR_LINK_STATE_MASK (0x3f << 16)
71 #define PCIE_PL_PFLR_FORCE_LINK (1 << 15)
72 #define PCIE_PHY_DEBUG_R0 (PL_OFFSET + 0x28)
73 #define PCIE_PHY_DEBUG_R1 (PL_OFFSET + 0x2c)
74 #define PCIE_PHY_DEBUG_R1_XMLH_LINK_IN_TRAINING (1 << 29)
75 #define PCIE_PHY_DEBUG_R1_XMLH_LINK_UP (1 << 4)
77 #define PCIE_PHY_CTRL (PL_OFFSET + 0x114)
78 #define PCIE_PHY_CTRL_DATA_LOC 0
79 #define PCIE_PHY_CTRL_CAP_ADR_LOC 16
80 #define PCIE_PHY_CTRL_CAP_DAT_LOC 17
81 #define PCIE_PHY_CTRL_WR_LOC 18
82 #define PCIE_PHY_CTRL_RD_LOC 19
84 #define PCIE_PHY_STAT (PL_OFFSET + 0x110)
85 #define PCIE_PHY_STAT_ACK_LOC 16
87 #define PCIE_LINK_WIDTH_SPEED_CONTROL 0x80C
88 #define PORT_LOGIC_SPEED_CHANGE (0x1 << 17)
90 /* PHY registers (not memory-mapped) */
91 #define PCIE_PHY_RX_ASIC_OUT 0x100D
92 #define PCIE_PHY_RX_ASIC_OUT_VALID (1 << 0)
94 #define PHY_RX_OVRD_IN_LO 0x1005
95 #define PHY_RX_OVRD_IN_LO_RX_DATA_EN (1 << 5)
96 #define PHY_RX_OVRD_IN_LO_RX_PLL_EN (1 << 3)
98 static int pcie_phy_poll_ack(struct imx6_pcie *imx6_pcie, int exp_val)
100 struct pcie_port *pp = &imx6_pcie->pp;
102 u32 max_iterations = 10;
103 u32 wait_counter = 0;
106 val = dw_pcie_readl_rc(pp, PCIE_PHY_STAT);
107 val = (val >> PCIE_PHY_STAT_ACK_LOC) & 0x1;
114 } while (wait_counter < max_iterations);
119 static int pcie_phy_wait_ack(struct imx6_pcie *imx6_pcie, int addr)
121 struct pcie_port *pp = &imx6_pcie->pp;
125 val = addr << PCIE_PHY_CTRL_DATA_LOC;
126 dw_pcie_writel_rc(pp, PCIE_PHY_CTRL, val);
128 val |= (0x1 << PCIE_PHY_CTRL_CAP_ADR_LOC);
129 dw_pcie_writel_rc(pp, PCIE_PHY_CTRL, val);
131 ret = pcie_phy_poll_ack(imx6_pcie, 1);
135 val = addr << PCIE_PHY_CTRL_DATA_LOC;
136 dw_pcie_writel_rc(pp, PCIE_PHY_CTRL, val);
138 return pcie_phy_poll_ack(imx6_pcie, 0);
141 /* Read from the 16-bit PCIe PHY control registers (not memory-mapped) */
142 static int pcie_phy_read(struct imx6_pcie *imx6_pcie, int addr, int *data)
144 struct pcie_port *pp = &imx6_pcie->pp;
148 ret = pcie_phy_wait_ack(imx6_pcie, addr);
152 /* assert Read signal */
153 phy_ctl = 0x1 << PCIE_PHY_CTRL_RD_LOC;
154 dw_pcie_writel_rc(pp, PCIE_PHY_CTRL, phy_ctl);
156 ret = pcie_phy_poll_ack(imx6_pcie, 1);
160 val = dw_pcie_readl_rc(pp, PCIE_PHY_STAT);
161 *data = val & 0xffff;
163 /* deassert Read signal */
164 dw_pcie_writel_rc(pp, PCIE_PHY_CTRL, 0x00);
166 return pcie_phy_poll_ack(imx6_pcie, 0);
169 static int pcie_phy_write(struct imx6_pcie *imx6_pcie, int addr, int data)
171 struct pcie_port *pp = &imx6_pcie->pp;
177 ret = pcie_phy_wait_ack(imx6_pcie, addr);
181 var = data << PCIE_PHY_CTRL_DATA_LOC;
182 dw_pcie_writel_rc(pp, PCIE_PHY_CTRL, var);
185 var |= (0x1 << PCIE_PHY_CTRL_CAP_DAT_LOC);
186 dw_pcie_writel_rc(pp, PCIE_PHY_CTRL, var);
188 ret = pcie_phy_poll_ack(imx6_pcie, 1);
192 /* deassert cap data */
193 var = data << PCIE_PHY_CTRL_DATA_LOC;
194 dw_pcie_writel_rc(pp, PCIE_PHY_CTRL, var);
196 /* wait for ack de-assertion */
197 ret = pcie_phy_poll_ack(imx6_pcie, 0);
201 /* assert wr signal */
202 var = 0x1 << PCIE_PHY_CTRL_WR_LOC;
203 dw_pcie_writel_rc(pp, PCIE_PHY_CTRL, var);
206 ret = pcie_phy_poll_ack(imx6_pcie, 1);
210 /* deassert wr signal */
211 var = data << PCIE_PHY_CTRL_DATA_LOC;
212 dw_pcie_writel_rc(pp, PCIE_PHY_CTRL, var);
214 /* wait for ack de-assertion */
215 ret = pcie_phy_poll_ack(imx6_pcie, 0);
219 dw_pcie_writel_rc(pp, PCIE_PHY_CTRL, 0x0);
224 static void imx6_pcie_reset_phy(struct imx6_pcie *imx6_pcie)
228 pcie_phy_read(imx6_pcie, PHY_RX_OVRD_IN_LO, &tmp);
229 tmp |= (PHY_RX_OVRD_IN_LO_RX_DATA_EN |
230 PHY_RX_OVRD_IN_LO_RX_PLL_EN);
231 pcie_phy_write(imx6_pcie, PHY_RX_OVRD_IN_LO, tmp);
233 usleep_range(2000, 3000);
235 pcie_phy_read(imx6_pcie, PHY_RX_OVRD_IN_LO, &tmp);
236 tmp &= ~(PHY_RX_OVRD_IN_LO_RX_DATA_EN |
237 PHY_RX_OVRD_IN_LO_RX_PLL_EN);
238 pcie_phy_write(imx6_pcie, PHY_RX_OVRD_IN_LO, tmp);
241 /* Added for PCI abort handling */
242 static int imx6q_pcie_abort_handler(unsigned long addr,
243 unsigned int fsr, struct pt_regs *regs)
248 static int imx6_pcie_assert_core_reset(struct imx6_pcie *imx6_pcie)
250 struct pcie_port *pp = &imx6_pcie->pp;
251 u32 val, gpr1, gpr12;
253 switch (imx6_pcie->variant) {
255 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
256 IMX6SX_GPR12_PCIE_TEST_POWERDOWN,
257 IMX6SX_GPR12_PCIE_TEST_POWERDOWN);
258 /* Force PCIe PHY reset */
259 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR5,
260 IMX6SX_GPR5_PCIE_BTNRST_RESET,
261 IMX6SX_GPR5_PCIE_BTNRST_RESET);
264 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1,
265 IMX6Q_GPR1_PCIE_SW_RST,
266 IMX6Q_GPR1_PCIE_SW_RST);
270 * If the bootloader already enabled the link we need some
271 * special handling to get the core back into a state where
272 * it is safe to touch it for configuration. As there is
273 * no dedicated reset signal wired up for MX6QDL, we need
274 * to manually force LTSSM into "detect" state before
275 * completely disabling LTSSM, which is a prerequisite for
276 * core configuration.
278 * If both LTSSM_ENABLE and REF_SSP_ENABLE are active we
279 * have a strong indication that the bootloader activated
282 regmap_read(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1, &gpr1);
283 regmap_read(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12, &gpr12);
285 if ((gpr1 & IMX6Q_GPR1_PCIE_REF_CLK_EN) &&
286 (gpr12 & IMX6Q_GPR12_PCIE_CTL_2)) {
287 val = dw_pcie_readl_rc(pp, PCIE_PL_PFLR);
288 val &= ~PCIE_PL_PFLR_LINK_STATE_MASK;
289 val |= PCIE_PL_PFLR_FORCE_LINK;
290 dw_pcie_writel_rc(pp, PCIE_PL_PFLR, val);
292 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
293 IMX6Q_GPR12_PCIE_CTL_2, 0 << 10);
296 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1,
297 IMX6Q_GPR1_PCIE_TEST_PD, 1 << 18);
298 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1,
299 IMX6Q_GPR1_PCIE_REF_CLK_EN, 0 << 16);
306 static int imx6_pcie_enable_ref_clk(struct imx6_pcie *imx6_pcie)
308 struct pcie_port *pp = &imx6_pcie->pp;
309 struct device *dev = pp->dev;
312 switch (imx6_pcie->variant) {
314 ret = clk_prepare_enable(imx6_pcie->pcie_inbound_axi);
316 dev_err(dev, "unable to enable pcie_axi clock\n");
320 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
321 IMX6SX_GPR12_PCIE_TEST_POWERDOWN, 0);
323 case IMX6QP: /* FALLTHROUGH */
325 /* power up core phy and enable ref clock */
326 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1,
327 IMX6Q_GPR1_PCIE_TEST_PD, 0 << 18);
329 * the async reset input need ref clock to sync internally,
330 * when the ref clock comes after reset, internal synced
331 * reset time is too short, cannot meet the requirement.
332 * add one ~10us delay here.
335 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1,
336 IMX6Q_GPR1_PCIE_REF_CLK_EN, 1 << 16);
343 static int imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
345 struct pcie_port *pp = &imx6_pcie->pp;
346 struct device *dev = pp->dev;
349 ret = clk_prepare_enable(imx6_pcie->pcie_phy);
351 dev_err(dev, "unable to enable pcie_phy clock\n");
355 ret = clk_prepare_enable(imx6_pcie->pcie_bus);
357 dev_err(dev, "unable to enable pcie_bus clock\n");
361 ret = clk_prepare_enable(imx6_pcie->pcie);
363 dev_err(dev, "unable to enable pcie clock\n");
367 ret = imx6_pcie_enable_ref_clk(imx6_pcie);
369 dev_err(dev, "unable to enable pcie ref clock\n");
373 /* allow the clocks to stabilize */
374 usleep_range(200, 500);
376 /* Some boards don't have PCIe reset GPIO. */
377 if (gpio_is_valid(imx6_pcie->reset_gpio)) {
378 gpio_set_value_cansleep(imx6_pcie->reset_gpio,
379 imx6_pcie->gpio_active_high);
381 gpio_set_value_cansleep(imx6_pcie->reset_gpio,
382 !imx6_pcie->gpio_active_high);
385 switch (imx6_pcie->variant) {
387 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR5,
388 IMX6SX_GPR5_PCIE_BTNRST_RESET, 0);
391 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1,
392 IMX6Q_GPR1_PCIE_SW_RST, 0);
394 usleep_range(200, 500);
396 case IMX6Q: /* Nothing to do */
403 clk_disable_unprepare(imx6_pcie->pcie);
405 clk_disable_unprepare(imx6_pcie->pcie_bus);
407 clk_disable_unprepare(imx6_pcie->pcie_phy);
412 static void imx6_pcie_init_phy(struct imx6_pcie *imx6_pcie)
414 if (imx6_pcie->variant == IMX6SX)
415 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
416 IMX6SX_GPR12_PCIE_RX_EQ_MASK,
417 IMX6SX_GPR12_PCIE_RX_EQ_2);
419 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
420 IMX6Q_GPR12_PCIE_CTL_2, 0 << 10);
422 /* configure constant input signal to the pcie ctrl and phy */
423 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
424 IMX6Q_GPR12_DEVICE_TYPE, PCI_EXP_TYPE_ROOT_PORT << 12);
425 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
426 IMX6Q_GPR12_LOS_LEVEL, 9 << 4);
428 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR8,
429 IMX6Q_GPR8_TX_DEEMPH_GEN1,
430 imx6_pcie->tx_deemph_gen1 << 0);
431 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR8,
432 IMX6Q_GPR8_TX_DEEMPH_GEN2_3P5DB,
433 imx6_pcie->tx_deemph_gen2_3p5db << 6);
434 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR8,
435 IMX6Q_GPR8_TX_DEEMPH_GEN2_6DB,
436 imx6_pcie->tx_deemph_gen2_6db << 12);
437 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR8,
438 IMX6Q_GPR8_TX_SWING_FULL,
439 imx6_pcie->tx_swing_full << 18);
440 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR8,
441 IMX6Q_GPR8_TX_SWING_LOW,
442 imx6_pcie->tx_swing_low << 25);
445 static int imx6_pcie_wait_for_link(struct imx6_pcie *imx6_pcie)
447 struct pcie_port *pp = &imx6_pcie->pp;
448 struct device *dev = pp->dev;
450 /* check if the link is up or not */
451 if (!dw_pcie_wait_for_link(pp))
454 dev_dbg(dev, "DEBUG_R0: 0x%08x, DEBUG_R1: 0x%08x\n",
455 dw_pcie_readl_rc(pp, PCIE_PHY_DEBUG_R0),
456 dw_pcie_readl_rc(pp, PCIE_PHY_DEBUG_R1));
460 static int imx6_pcie_wait_for_speed_change(struct imx6_pcie *imx6_pcie)
462 struct pcie_port *pp = &imx6_pcie->pp;
463 struct device *dev = pp->dev;
465 unsigned int retries;
467 for (retries = 0; retries < 200; retries++) {
468 tmp = dw_pcie_readl_rc(pp, PCIE_LINK_WIDTH_SPEED_CONTROL);
469 /* Test if the speed change finished. */
470 if (!(tmp & PORT_LOGIC_SPEED_CHANGE))
472 usleep_range(100, 1000);
475 dev_err(dev, "Speed change timeout\n");
479 static irqreturn_t imx6_pcie_msi_handler(int irq, void *arg)
481 struct imx6_pcie *imx6_pcie = arg;
482 struct pcie_port *pp = &imx6_pcie->pp;
484 return dw_handle_msi_irq(pp);
487 static int imx6_pcie_establish_link(struct imx6_pcie *imx6_pcie)
489 struct pcie_port *pp = &imx6_pcie->pp;
490 struct device *dev = pp->dev;
495 * Force Gen1 operation when starting the link. In case the link is
496 * started in Gen2 mode, there is a possibility the devices on the
497 * bus will not be detected at all. This happens with PCIe switches.
499 tmp = dw_pcie_readl_rc(pp, PCIE_RC_LCR);
500 tmp &= ~PCIE_RC_LCR_MAX_LINK_SPEEDS_MASK;
501 tmp |= PCIE_RC_LCR_MAX_LINK_SPEEDS_GEN1;
502 dw_pcie_writel_rc(pp, PCIE_RC_LCR, tmp);
505 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
506 IMX6Q_GPR12_PCIE_CTL_2, 1 << 10);
508 ret = imx6_pcie_wait_for_link(imx6_pcie);
510 dev_info(dev, "Link never came up\n");
514 if (imx6_pcie->link_gen == 2) {
515 /* Allow Gen2 mode after the link is up. */
516 tmp = dw_pcie_readl_rc(pp, PCIE_RC_LCR);
517 tmp &= ~PCIE_RC_LCR_MAX_LINK_SPEEDS_MASK;
518 tmp |= PCIE_RC_LCR_MAX_LINK_SPEEDS_GEN2;
519 dw_pcie_writel_rc(pp, PCIE_RC_LCR, tmp);
521 dev_info(dev, "Link: Gen2 disabled\n");
525 * Start Directed Speed Change so the best possible speed both link
526 * partners support can be negotiated.
528 tmp = dw_pcie_readl_rc(pp, PCIE_LINK_WIDTH_SPEED_CONTROL);
529 tmp |= PORT_LOGIC_SPEED_CHANGE;
530 dw_pcie_writel_rc(pp, PCIE_LINK_WIDTH_SPEED_CONTROL, tmp);
532 ret = imx6_pcie_wait_for_speed_change(imx6_pcie);
534 dev_err(dev, "Failed to bring link up!\n");
538 /* Make sure link training is finished as well! */
539 ret = imx6_pcie_wait_for_link(imx6_pcie);
541 dev_err(dev, "Failed to bring link up!\n");
545 tmp = dw_pcie_readl_rc(pp, PCIE_RC_LCSR);
546 dev_info(dev, "Link up, Gen%i\n", (tmp >> 16) & 0xf);
550 dev_dbg(dev, "PHY DEBUG_R0=0x%08x DEBUG_R1=0x%08x\n",
551 dw_pcie_readl_rc(pp, PCIE_PHY_DEBUG_R0),
552 dw_pcie_readl_rc(pp, PCIE_PHY_DEBUG_R1));
553 imx6_pcie_reset_phy(imx6_pcie);
557 static void imx6_pcie_host_init(struct pcie_port *pp)
559 struct imx6_pcie *imx6_pcie = to_imx6_pcie(pp);
561 imx6_pcie_assert_core_reset(imx6_pcie);
562 imx6_pcie_init_phy(imx6_pcie);
563 imx6_pcie_deassert_core_reset(imx6_pcie);
564 dw_pcie_setup_rc(pp);
565 imx6_pcie_establish_link(imx6_pcie);
567 if (IS_ENABLED(CONFIG_PCI_MSI))
568 dw_pcie_msi_init(pp);
571 static int imx6_pcie_link_up(struct pcie_port *pp)
573 return dw_pcie_readl_rc(pp, PCIE_PHY_DEBUG_R1) &
574 PCIE_PHY_DEBUG_R1_XMLH_LINK_UP;
577 static struct pcie_host_ops imx6_pcie_host_ops = {
578 .link_up = imx6_pcie_link_up,
579 .host_init = imx6_pcie_host_init,
582 static int __init imx6_add_pcie_port(struct imx6_pcie *imx6_pcie,
583 struct platform_device *pdev)
585 struct pcie_port *pp = &imx6_pcie->pp;
586 struct device *dev = pp->dev;
589 if (IS_ENABLED(CONFIG_PCI_MSI)) {
590 pp->msi_irq = platform_get_irq_byname(pdev, "msi");
591 if (pp->msi_irq <= 0) {
592 dev_err(dev, "failed to get MSI irq\n");
596 ret = devm_request_irq(dev, pp->msi_irq,
597 imx6_pcie_msi_handler,
598 IRQF_SHARED | IRQF_NO_THREAD,
599 "mx6-pcie-msi", imx6_pcie);
601 dev_err(dev, "failed to request MSI irq\n");
606 pp->root_bus_nr = -1;
607 pp->ops = &imx6_pcie_host_ops;
609 ret = dw_pcie_host_init(pp);
611 dev_err(dev, "failed to initialize host\n");
618 static int __init imx6_pcie_probe(struct platform_device *pdev)
620 struct device *dev = &pdev->dev;
621 struct imx6_pcie *imx6_pcie;
622 struct pcie_port *pp;
623 struct resource *dbi_base;
624 struct device_node *node = dev->of_node;
627 imx6_pcie = devm_kzalloc(dev, sizeof(*imx6_pcie), GFP_KERNEL);
635 (enum imx6_pcie_variants)of_device_get_match_data(dev);
637 /* Added for PCI abort handling */
638 hook_fault_code(16 + 6, imx6q_pcie_abort_handler, SIGBUS, 0,
639 "imprecise external abort");
641 dbi_base = platform_get_resource(pdev, IORESOURCE_MEM, 0);
642 pp->dbi_base = devm_ioremap_resource(dev, dbi_base);
643 if (IS_ERR(pp->dbi_base))
644 return PTR_ERR(pp->dbi_base);
647 imx6_pcie->reset_gpio = of_get_named_gpio(node, "reset-gpio", 0);
648 imx6_pcie->gpio_active_high = of_property_read_bool(node,
649 "reset-gpio-active-high");
650 if (gpio_is_valid(imx6_pcie->reset_gpio)) {
651 ret = devm_gpio_request_one(dev, imx6_pcie->reset_gpio,
652 imx6_pcie->gpio_active_high ?
653 GPIOF_OUT_INIT_HIGH :
657 dev_err(dev, "unable to get reset gpio\n");
663 imx6_pcie->pcie_phy = devm_clk_get(dev, "pcie_phy");
664 if (IS_ERR(imx6_pcie->pcie_phy)) {
665 dev_err(dev, "pcie_phy clock source missing or invalid\n");
666 return PTR_ERR(imx6_pcie->pcie_phy);
669 imx6_pcie->pcie_bus = devm_clk_get(dev, "pcie_bus");
670 if (IS_ERR(imx6_pcie->pcie_bus)) {
671 dev_err(dev, "pcie_bus clock source missing or invalid\n");
672 return PTR_ERR(imx6_pcie->pcie_bus);
675 imx6_pcie->pcie = devm_clk_get(dev, "pcie");
676 if (IS_ERR(imx6_pcie->pcie)) {
677 dev_err(dev, "pcie clock source missing or invalid\n");
678 return PTR_ERR(imx6_pcie->pcie);
681 if (imx6_pcie->variant == IMX6SX) {
682 imx6_pcie->pcie_inbound_axi = devm_clk_get(dev,
684 if (IS_ERR(imx6_pcie->pcie_inbound_axi)) {
686 "pcie_incbound_axi clock missing or invalid\n");
687 return PTR_ERR(imx6_pcie->pcie_inbound_axi);
691 /* Grab GPR config register range */
692 imx6_pcie->iomuxc_gpr =
693 syscon_regmap_lookup_by_compatible("fsl,imx6q-iomuxc-gpr");
694 if (IS_ERR(imx6_pcie->iomuxc_gpr)) {
695 dev_err(dev, "unable to find iomuxc registers\n");
696 return PTR_ERR(imx6_pcie->iomuxc_gpr);
699 /* Grab PCIe PHY Tx Settings */
700 if (of_property_read_u32(node, "fsl,tx-deemph-gen1",
701 &imx6_pcie->tx_deemph_gen1))
702 imx6_pcie->tx_deemph_gen1 = 0;
704 if (of_property_read_u32(node, "fsl,tx-deemph-gen2-3p5db",
705 &imx6_pcie->tx_deemph_gen2_3p5db))
706 imx6_pcie->tx_deemph_gen2_3p5db = 0;
708 if (of_property_read_u32(node, "fsl,tx-deemph-gen2-6db",
709 &imx6_pcie->tx_deemph_gen2_6db))
710 imx6_pcie->tx_deemph_gen2_6db = 20;
712 if (of_property_read_u32(node, "fsl,tx-swing-full",
713 &imx6_pcie->tx_swing_full))
714 imx6_pcie->tx_swing_full = 127;
716 if (of_property_read_u32(node, "fsl,tx-swing-low",
717 &imx6_pcie->tx_swing_low))
718 imx6_pcie->tx_swing_low = 127;
720 /* Limit link speed */
721 ret = of_property_read_u32(node, "fsl,max-link-speed",
722 &imx6_pcie->link_gen);
724 imx6_pcie->link_gen = 1;
726 ret = imx6_add_pcie_port(imx6_pcie, pdev);
730 platform_set_drvdata(pdev, imx6_pcie);
734 static void imx6_pcie_shutdown(struct platform_device *pdev)
736 struct imx6_pcie *imx6_pcie = platform_get_drvdata(pdev);
738 /* bring down link, so bootloader gets clean state in case of reboot */
739 imx6_pcie_assert_core_reset(imx6_pcie);
742 static const struct of_device_id imx6_pcie_of_match[] = {
743 { .compatible = "fsl,imx6q-pcie", .data = (void *)IMX6Q, },
744 { .compatible = "fsl,imx6sx-pcie", .data = (void *)IMX6SX, },
745 { .compatible = "fsl,imx6qp-pcie", .data = (void *)IMX6QP, },
749 static struct platform_driver imx6_pcie_driver = {
751 .name = "imx6q-pcie",
752 .of_match_table = imx6_pcie_of_match,
754 .shutdown = imx6_pcie_shutdown,
757 static int __init imx6_pcie_init(void)
759 return platform_driver_probe(&imx6_pcie_driver, imx6_pcie_probe);
761 device_initcall(imx6_pcie_init);