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/interrupt.h>
18 #include <linux/kernel.h>
19 #include <linux/mfd/syscon.h>
20 #include <linux/mfd/syscon/imx6q-iomuxc-gpr.h>
21 #include <linux/module.h>
22 #include <linux/of_gpio.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/busfreq-imx6.h>
31 #include "pcie-designware.h"
33 #define to_imx6_pcie(x) container_of(x, struct imx6_pcie, pp)
36 * The default values of the RC's reserved ddr memory
37 * used to verify EP mode.
38 * BTW, here is the layout of the 1G ddr on SD boards
39 * 0x1000_0000 ~ 0x4FFF_FFFF
41 static u32 rc_ddr_test_region = 0x40000000;
42 static u32 test_region_size = SZ_2M;
49 struct clk *lvds_gate;
50 struct clk *sata_ref_100m;
51 struct clk *pcie_ref_125m;
54 struct regmap *iomuxc_gpr;
55 void __iomem *mem_base;
58 /* PCIe Port Logic registers (memory-mapped) */
59 #define PL_OFFSET 0x700
60 #define PCIE_PHY_DEBUG_R0 (PL_OFFSET + 0x28)
61 #define PCIE_PHY_DEBUG_R1 (PL_OFFSET + 0x2c)
63 #define PCIE_PHY_CTRL (PL_OFFSET + 0x114)
64 #define PCIE_PHY_CTRL_DATA_LOC 0
65 #define PCIE_PHY_CTRL_CAP_ADR_LOC 16
66 #define PCIE_PHY_CTRL_CAP_DAT_LOC 17
67 #define PCIE_PHY_CTRL_WR_LOC 18
68 #define PCIE_PHY_CTRL_RD_LOC 19
70 #define PCIE_PHY_STAT (PL_OFFSET + 0x110)
71 #define PCIE_PHY_STAT_ACK_LOC 16
73 /* PHY registers (not memory-mapped) */
74 #define PCIE_PHY_RX_ASIC_OUT 0x100D
76 #define PHY_RX_OVRD_IN_LO 0x1005
77 #define PHY_RX_OVRD_IN_LO_RX_DATA_EN (1 << 5)
78 #define PHY_RX_OVRD_IN_LO_RX_PLL_EN (1 << 3)
80 static int pcie_phy_poll_ack(void __iomem *dbi_base, int exp_val)
83 u32 max_iterations = 10;
87 val = readl(dbi_base + PCIE_PHY_STAT);
88 val = (val >> PCIE_PHY_STAT_ACK_LOC) & 0x1;
95 } while (wait_counter < max_iterations);
100 static int pcie_phy_wait_ack(void __iomem *dbi_base, int addr)
105 val = addr << PCIE_PHY_CTRL_DATA_LOC;
106 writel(val, dbi_base + PCIE_PHY_CTRL);
108 val |= (0x1 << PCIE_PHY_CTRL_CAP_ADR_LOC);
109 writel(val, dbi_base + PCIE_PHY_CTRL);
111 ret = pcie_phy_poll_ack(dbi_base, 1);
115 val = addr << PCIE_PHY_CTRL_DATA_LOC;
116 writel(val, dbi_base + PCIE_PHY_CTRL);
118 ret = pcie_phy_poll_ack(dbi_base, 0);
125 /* Read from the 16-bit PCIe PHY control registers (not memory-mapped) */
126 static int pcie_phy_read(void __iomem *dbi_base, int addr , int *data)
131 ret = pcie_phy_wait_ack(dbi_base, addr);
135 /* assert Read signal */
136 phy_ctl = 0x1 << PCIE_PHY_CTRL_RD_LOC;
137 writel(phy_ctl, dbi_base + PCIE_PHY_CTRL);
139 ret = pcie_phy_poll_ack(dbi_base, 1);
143 val = readl(dbi_base + PCIE_PHY_STAT);
144 *data = val & 0xffff;
146 /* deassert Read signal */
147 writel(0x00, dbi_base + PCIE_PHY_CTRL);
149 ret = pcie_phy_poll_ack(dbi_base, 0);
156 static int pcie_phy_write(void __iomem *dbi_base, int addr, int data)
163 ret = pcie_phy_wait_ack(dbi_base, addr);
167 var = data << PCIE_PHY_CTRL_DATA_LOC;
168 writel(var, dbi_base + PCIE_PHY_CTRL);
171 var |= (0x1 << PCIE_PHY_CTRL_CAP_DAT_LOC);
172 writel(var, dbi_base + PCIE_PHY_CTRL);
174 ret = pcie_phy_poll_ack(dbi_base, 1);
178 /* deassert cap data */
179 var = data << PCIE_PHY_CTRL_DATA_LOC;
180 writel(var, dbi_base + PCIE_PHY_CTRL);
182 /* wait for ack de-assertion */
183 ret = pcie_phy_poll_ack(dbi_base, 0);
187 /* assert wr signal */
188 var = 0x1 << PCIE_PHY_CTRL_WR_LOC;
189 writel(var, dbi_base + PCIE_PHY_CTRL);
192 ret = pcie_phy_poll_ack(dbi_base, 1);
196 /* deassert wr signal */
197 var = data << PCIE_PHY_CTRL_DATA_LOC;
198 writel(var, dbi_base + PCIE_PHY_CTRL);
200 /* wait for ack de-assertion */
201 ret = pcie_phy_poll_ack(dbi_base, 0);
205 writel(0x0, dbi_base + PCIE_PHY_CTRL);
210 /* Added for PCI abort handling */
211 static int imx6q_pcie_abort_handler(unsigned long addr,
212 unsigned int fsr, struct pt_regs *regs)
217 static int imx6_pcie_deassert_core_reset(struct pcie_port *pp)
219 struct imx6_pcie *imx6_pcie = to_imx6_pcie(pp);
222 if (gpio_is_valid(imx6_pcie->power_on_gpio))
223 gpio_set_value(imx6_pcie->power_on_gpio, 1);
225 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1,
226 IMX6Q_GPR1_PCIE_TEST_PD, 0 << 18);
227 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1,
228 IMX6Q_GPR1_PCIE_REF_CLK_EN, 1 << 16);
229 request_bus_freq(BUS_FREQ_HIGH);
231 ret = clk_prepare_enable(imx6_pcie->sata_ref_100m);
233 dev_err(pp->dev, "unable to enable sata_ref_100m\n");
237 ret = clk_prepare_enable(imx6_pcie->pcie_ref_125m);
239 dev_err(pp->dev, "unable to enable pcie_ref_125m\n");
243 if (!IS_ENABLED(CONFIG_EP_MODE_IN_EP_RC_SYS)
244 && !IS_ENABLED(CONFIG_RC_MODE_IN_EP_RC_SYS)) {
245 ret = clk_prepare_enable(imx6_pcie->lvds_gate);
247 dev_err(pp->dev, "unable to enable lvds_gate\n");
252 ret = clk_prepare_enable(imx6_pcie->pcie_axi);
254 dev_err(pp->dev, "unable to enable pcie_axi\n");
258 /* allow the clocks to stabilize */
259 usleep_range(200, 500);
261 if (gpio_is_valid(imx6_pcie->reset_gpio)) {
262 gpio_set_value(imx6_pcie->reset_gpio, 0);
264 gpio_set_value(imx6_pcie->reset_gpio, 1);
270 clk_disable_unprepare(imx6_pcie->lvds_gate);
272 clk_disable_unprepare(imx6_pcie->pcie_ref_125m);
274 clk_disable_unprepare(imx6_pcie->sata_ref_100m);
276 release_bus_freq(BUS_FREQ_HIGH);
281 static void imx6_pcie_init_phy(struct pcie_port *pp)
283 struct imx6_pcie *imx6_pcie = to_imx6_pcie(pp);
285 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
286 IMX6Q_GPR12_PCIE_CTL_2, 0 << 10);
288 /* configure constant input signal to the pcie ctrl and phy */
289 if (IS_ENABLED(CONFIG_EP_MODE_IN_EP_RC_SYS))
290 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
291 IMX6Q_GPR12_DEVICE_TYPE,
292 PCI_EXP_TYPE_ENDPOINT << 12);
294 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
295 IMX6Q_GPR12_DEVICE_TYPE,
296 PCI_EXP_TYPE_ROOT_PORT << 12);
297 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
298 IMX6Q_GPR12_LOS_LEVEL, 9 << 4);
300 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR8,
301 IMX6Q_GPR8_TX_DEEMPH_GEN1, 0 << 0);
302 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR8,
303 IMX6Q_GPR8_TX_DEEMPH_GEN2_3P5DB, 0 << 6);
304 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR8,
305 IMX6Q_GPR8_TX_DEEMPH_GEN2_6DB, 20 << 12);
306 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR8,
307 IMX6Q_GPR8_TX_SWING_FULL, 127 << 18);
308 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR8,
309 IMX6Q_GPR8_TX_SWING_LOW, 127 << 25);
312 static irqreturn_t imx_pcie_msi_irq_handler(int irq, void *arg)
314 struct pcie_port *pp = arg;
316 dw_handle_msi_irq(pp);
321 static void imx6_pcie_host_init(struct pcie_port *pp)
324 struct imx6_pcie *imx6_pcie = to_imx6_pcie(pp);
326 imx6_pcie_init_phy(pp);
328 imx6_pcie_deassert_core_reset(pp);
330 dw_pcie_setup_rc(pp);
332 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
333 IMX6Q_GPR12_PCIE_CTL_2, 1 << 10);
335 while (!dw_pcie_link_up(pp)) {
336 usleep_range(100, 1000);
339 dev_err(pp->dev, "phy link never came up\n");
341 "DEBUG_R0: 0x%08x, DEBUG_R1: 0x%08x\n",
342 readl(pp->dbi_base + PCIE_PHY_DEBUG_R0),
343 readl(pp->dbi_base + PCIE_PHY_DEBUG_R1));
348 if (IS_ENABLED(CONFIG_PCI_MSI)) {
349 pp->quirks |= DW_PCIE_QUIRK_NO_MSI_VEC;
350 pp->quirks |= DW_PCIE_QUIRK_MSI_SELF_EN;
351 dw_pcie_msi_init(pp);
357 static int imx6_pcie_link_up(struct pcie_port *pp)
359 u32 rc, ltssm, rx_valid, temp;
361 /* link is debug bit 36, debug register 1 starts at bit 32 */
362 rc = readl(pp->dbi_base + PCIE_PHY_DEBUG_R1) & (0x1 << (36 - 32));
367 * From L0, initiate MAC entry to gen2 if EP/RC supports gen2.
368 * Wait 2ms (LTSSM timeout is 24ms, PHY lock is ~5us in gen2).
369 * If (MAC/LTSSM.state == Recovery.RcvrLock)
370 * && (PHY/rx_valid==0) then pulse PHY/rx_reset. Transition
373 pcie_phy_read(pp->dbi_base, PCIE_PHY_RX_ASIC_OUT, &rx_valid);
374 ltssm = readl(pp->dbi_base + PCIE_PHY_DEBUG_R0) & 0x3F;
382 dev_err(pp->dev, "transition to gen2 is stuck, reset PHY!\n");
384 pcie_phy_read(pp->dbi_base,
385 PHY_RX_OVRD_IN_LO, &temp);
386 temp |= (PHY_RX_OVRD_IN_LO_RX_DATA_EN
387 | PHY_RX_OVRD_IN_LO_RX_PLL_EN);
388 pcie_phy_write(pp->dbi_base,
389 PHY_RX_OVRD_IN_LO, temp);
391 usleep_range(2000, 3000);
393 pcie_phy_read(pp->dbi_base,
394 PHY_RX_OVRD_IN_LO, &temp);
395 temp &= ~(PHY_RX_OVRD_IN_LO_RX_DATA_EN
396 | PHY_RX_OVRD_IN_LO_RX_PLL_EN);
397 pcie_phy_write(pp->dbi_base,
398 PHY_RX_OVRD_IN_LO, temp);
403 static struct pcie_host_ops imx6_pcie_host_ops = {
404 .link_up = imx6_pcie_link_up,
405 .host_init = imx6_pcie_host_init,
408 static int imx6_add_pcie_port(struct pcie_port *pp,
409 struct platform_device *pdev)
413 pp->irq = platform_get_irq(pdev, 0);
415 dev_err(&pdev->dev, "failed to get irq\n");
419 if (IS_ENABLED(CONFIG_PCI_MSI)) {
420 pp->msi_irq = pp->irq - 3;
422 dev_err(&pdev->dev, "failed to get msi irq\n");
426 ret = devm_request_irq(&pdev->dev, pp->msi_irq,
427 imx_pcie_msi_irq_handler,
428 IRQF_SHARED, "imx6q-pcie", pp);
430 dev_err(&pdev->dev, "failed to request msi irq\n");
435 pp->root_bus_nr = -1;
436 pp->ops = &imx6_pcie_host_ops;
438 spin_lock_init(&pp->conf_lock);
439 ret = dw_pcie_host_init(pp);
441 dev_err(&pdev->dev, "failed to initialize host\n");
448 static void imx_pcie_regions_setup(struct device *dev)
450 struct imx6_pcie *imx6_pcie = dev_get_drvdata(dev);
451 struct pcie_port *pp = &imx6_pcie->pp;
454 * region0 outbound used to access RC's reserved ddr memory
456 writel(0, pp->dbi_base + PCIE_ATU_VIEWPORT);
457 writel(0x01000000, pp->dbi_base + PCIE_ATU_LOWER_BASE);
458 writel(0, pp->dbi_base + PCIE_ATU_UPPER_BASE);
459 writel(0x01000000 + test_region_size,
460 pp->dbi_base + PCIE_ATU_LIMIT);
462 writel(rc_ddr_test_region,
463 pp->dbi_base + PCIE_ATU_LOWER_TARGET);
464 writel(0, pp->dbi_base + PCIE_ATU_UPPER_TARGET);
465 writel(PCIE_ATU_TYPE_MEM, pp->dbi_base + PCIE_ATU_CR1);
466 writel(PCIE_ATU_ENABLE, pp->dbi_base + PCIE_ATU_CR2);
469 static ssize_t imx_pcie_rc_memw_info(struct device *dev,
470 struct device_attribute *devattr, char *buf)
472 return sprintf(buf, "imx-pcie-rc-memw-info start 0x%08x, size 0x%08x\n",
473 rc_ddr_test_region, test_region_size);
477 imx_pcie_rc_memw_start(struct device *dev, struct device_attribute *attr,
478 const char *buf, size_t count)
482 sscanf(buf, "%x\n", &memw_start);
484 if (memw_start < 0x10000000) {
485 dev_err(dev, "Invalid memory start address.\n");
486 dev_info(dev, "For example: echo 0x41000000 > /sys/...");
490 if (rc_ddr_test_region != memw_start) {
491 rc_ddr_test_region = memw_start;
492 /* Re-setup the iATU */
493 imx_pcie_regions_setup(dev);
500 imx_pcie_rc_memw_size(struct device *dev, struct device_attribute *attr,
501 const char *buf, size_t count)
505 sscanf(buf, "%x\n", &memw_size);
507 if ((memw_size > (SZ_16M - SZ_16K)) || (memw_size < SZ_64K)) {
508 dev_err(dev, "Invalid, should be [SZ_64K,SZ_16M - SZ_16KB].\n");
509 dev_info(dev, "For example: echo 0x800000 > /sys/...");
513 if (test_region_size != memw_size) {
514 test_region_size = memw_size;
515 /* Re-setup the iATU */
516 imx_pcie_regions_setup(dev);
522 static DEVICE_ATTR(rc_memw_info, S_IRUGO, imx_pcie_rc_memw_info, NULL);
523 static DEVICE_ATTR(rc_memw_start_set, S_IWUGO, NULL, imx_pcie_rc_memw_start);
524 static DEVICE_ATTR(rc_memw_size_set, S_IWUGO, NULL, imx_pcie_rc_memw_size);
526 static struct attribute *imx_pcie_attrs[] = {
528 * The start address, and the limitation (64KB ~ (16MB - 16KB))
529 * of the ddr mem window reserved by RC, and used for EP to access.
530 * BTW, these attrs are only configured at EP side.
532 &dev_attr_rc_memw_info.attr,
533 &dev_attr_rc_memw_start_set.attr,
534 &dev_attr_rc_memw_size_set.attr,
538 static struct attribute_group imx_pcie_attrgroup = {
539 .attrs = imx_pcie_attrs,
542 static int __init imx6_pcie_probe(struct platform_device *pdev)
544 struct imx6_pcie *imx6_pcie;
545 struct pcie_port *pp;
546 struct device_node *np = pdev->dev.of_node;
547 struct resource *dbi_base;
549 void *test_reg1, *test_reg2;
550 void __iomem *pcie_arb_base_addr;
551 struct timeval tv1, tv2, tv3;
552 u32 tv_count1, tv_count2;
554 imx6_pcie = devm_kzalloc(&pdev->dev, sizeof(*imx6_pcie), GFP_KERNEL);
559 pp->dev = &pdev->dev;
561 if (IS_ENABLED(CONFIG_EP_MODE_IN_EP_RC_SYS)) {
562 /* add attributes for device */
563 ret = sysfs_create_group(&pdev->dev.kobj, &imx_pcie_attrgroup);
568 /* Added for PCI abort handling */
569 hook_fault_code(16 + 6, imx6q_pcie_abort_handler, SIGBUS, 0,
570 "imprecise external abort");
572 dbi_base = platform_get_resource(pdev, IORESOURCE_MEM, 0);
574 dev_err(&pdev->dev, "dbi_base memory resource not found\n");
578 pp->dbi_base = devm_ioremap_resource(&pdev->dev, dbi_base);
579 if (IS_ERR(pp->dbi_base)) {
580 ret = PTR_ERR(pp->dbi_base);
585 imx6_pcie->reset_gpio = of_get_named_gpio(np, "reset-gpio", 0);
586 if (gpio_is_valid(imx6_pcie->reset_gpio)) {
587 ret = devm_gpio_request_one(&pdev->dev,
588 imx6_pcie->reset_gpio,
592 dev_err(&pdev->dev, "unable to get reset gpio\n");
597 imx6_pcie->power_on_gpio = of_get_named_gpio(np, "power-on-gpio", 0);
598 if (gpio_is_valid(imx6_pcie->power_on_gpio)) {
599 ret = devm_gpio_request_one(&pdev->dev,
600 imx6_pcie->power_on_gpio,
602 "PCIe power enable");
604 dev_err(&pdev->dev, "unable to get power-on gpio\n");
609 imx6_pcie->wake_up_gpio = of_get_named_gpio(np, "wake-up-gpio", 0);
610 if (gpio_is_valid(imx6_pcie->wake_up_gpio)) {
611 ret = devm_gpio_request_one(&pdev->dev,
612 imx6_pcie->wake_up_gpio,
616 dev_err(&pdev->dev, "unable to get wake-up gpio\n");
621 imx6_pcie->disable_gpio = of_get_named_gpio(np, "disable-gpio", 0);
622 if (gpio_is_valid(imx6_pcie->disable_gpio)) {
623 ret = devm_gpio_request_one(&pdev->dev,
624 imx6_pcie->disable_gpio,
626 "PCIe disable endpoint");
628 dev_err(&pdev->dev, "unable to get disable-ep gpio\n");
634 imx6_pcie->lvds_gate = devm_clk_get(&pdev->dev, "lvds_gate");
635 if (IS_ERR(imx6_pcie->lvds_gate)) {
637 "lvds_gate clock select missing or invalid\n");
638 ret = PTR_ERR(imx6_pcie->lvds_gate);
642 imx6_pcie->sata_ref_100m = devm_clk_get(&pdev->dev, "sata_ref_100m");
643 if (IS_ERR(imx6_pcie->sata_ref_100m)) {
645 "sata_ref_100m clock source missing or invalid\n");
646 ret = PTR_ERR(imx6_pcie->sata_ref_100m);
650 imx6_pcie->pcie_ref_125m = devm_clk_get(&pdev->dev, "pcie_ref_125m");
651 if (IS_ERR(imx6_pcie->pcie_ref_125m)) {
653 "pcie_ref_125m clock source missing or invalid\n");
654 ret = PTR_ERR(imx6_pcie->pcie_ref_125m);
658 imx6_pcie->pcie_axi = devm_clk_get(&pdev->dev, "pcie_axi");
659 if (IS_ERR(imx6_pcie->pcie_axi)) {
661 "pcie_axi clock source missing or invalid\n");
662 ret = PTR_ERR(imx6_pcie->pcie_axi);
666 /* Grab GPR config register range */
667 imx6_pcie->iomuxc_gpr =
668 syscon_regmap_lookup_by_compatible("fsl,imx6q-iomuxc-gpr");
669 if (IS_ERR(imx6_pcie->iomuxc_gpr)) {
670 dev_err(&pdev->dev, "unable to find iomuxc registers\n");
671 ret = PTR_ERR(imx6_pcie->iomuxc_gpr);
675 if (IS_ENABLED(CONFIG_EP_MODE_IN_EP_RC_SYS)) {
676 if (IS_ENABLED(CONFIG_EP_SELF_IO_TEST)) {
677 /* Prepare the test regions and data */
678 test_reg1 = devm_kzalloc(&pdev->dev,
679 test_region_size, GFP_KERNEL);
681 pr_err("pcie ep: can't alloc the test reg1.\n");
682 ret = PTR_ERR(test_reg1);
686 test_reg2 = devm_kzalloc(&pdev->dev,
687 test_region_size, GFP_KERNEL);
689 pr_err("pcie ep: can't alloc the test reg2.\n");
690 ret = PTR_ERR(test_reg1);
694 pcie_arb_base_addr = ioremap_cached(0x01000000,
697 if (!pcie_arb_base_addr) {
698 pr_err("error with ioremap in ep selftest\n");
699 ret = PTR_ERR(pcie_arb_base_addr);
703 for (i = 0; i < test_region_size; i = i + 4) {
704 writel(0xE6600D00 + i, test_reg1 + i);
705 writel(0xDEADBEAF, test_reg2 + i);
709 imx6_pcie_init_phy(pp);
711 imx6_pcie_deassert_core_reset(pp);
713 /* assert LTSSM enable */
714 regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
715 IMX6Q_GPR12_PCIE_CTL_2, 1 << 10);
718 dev_info(&pdev->dev, "PCIe EP: waiting for link up...\n");
720 platform_set_drvdata(pdev, imx6_pcie);
721 /* link is indicated by the bit4 of DB_R1 register */
723 usleep_range(10, 20);
724 } while ((readl(pp->dbi_base + PCIE_PHY_DEBUG_R1) & 0x10) == 0);
726 /* CMD reg:I/O space, MEM space, and Bus Master Enable */
727 writel(readl(pp->dbi_base + PCI_COMMAND)
730 | PCI_COMMAND_MASTER,
731 pp->dbi_base + PCI_COMMAND);
734 * configure the class_rev(emaluate one memory ram ep device),
735 * bar0 and bar1 of ep
737 writel(0xdeadbeaf, pp->dbi_base + PCI_VENDOR_ID);
738 writel(readl(pp->dbi_base + PCI_CLASS_REVISION)
739 | (PCI_CLASS_MEMORY_RAM << 16),
740 pp->dbi_base + PCI_CLASS_REVISION);
741 writel(0xdeadbeaf, pp->dbi_base
742 + PCI_SUBSYSTEM_VENDOR_ID);
744 /* 32bit none-prefetchable 8M bytes memory on bar0 */
745 writel(0x0, pp->dbi_base + PCI_BASE_ADDRESS_0);
746 writel(SZ_8M - 1, pp->dbi_base + (1 << 12)
747 + PCI_BASE_ADDRESS_0);
750 writel(0x0, pp->dbi_base + PCI_BASE_ADDRESS_1);
751 writel(0, pp->dbi_base + (1 << 12) + PCI_BASE_ADDRESS_1);
753 /* 4K bytes IO on bar2 */
754 writel(0x1, pp->dbi_base + PCI_BASE_ADDRESS_2);
755 writel(SZ_4K - 1, pp->dbi_base + (1 << 12) +
759 * 32bit prefetchable 1M bytes memory on bar3
760 * FIXME BAR MASK3 is not changable, the size
761 * is fixed to 256 bytes.
763 writel(0x8, pp->dbi_base + PCI_BASE_ADDRESS_3);
764 writel(SZ_1M - 1, pp->dbi_base + (1 << 12)
765 + PCI_BASE_ADDRESS_3);
768 * 64bit prefetchable 1M bytes memory on bar4-5.
769 * FIXME BAR4,5 are not enabled yet
771 writel(0xc, pp->dbi_base + PCI_BASE_ADDRESS_4);
772 writel(SZ_1M - 1, pp->dbi_base + (1 << 12)
773 + PCI_BASE_ADDRESS_4);
774 writel(0, pp->dbi_base + (1 << 12) + PCI_BASE_ADDRESS_5);
776 /* Re-setup the iATU */
777 imx_pcie_regions_setup(&pdev->dev);
779 if (IS_ENABLED(CONFIG_EP_SELF_IO_TEST)) {
780 /* PCIe EP start the data transfer after link up */
781 pr_info("pcie ep: Starting data transfer...\n");
782 do_gettimeofday(&tv1);
784 memcpy((unsigned long *)pcie_arb_base_addr,
785 (unsigned long *)test_reg1,
788 do_gettimeofday(&tv2);
790 memcpy((unsigned long *)test_reg2,
791 (unsigned long *)pcie_arb_base_addr,
794 do_gettimeofday(&tv3);
796 if (memcmp(test_reg2, test_reg1, test_region_size) == 0) {
797 tv_count1 = (tv2.tv_sec - tv1.tv_sec)
799 + tv2.tv_usec - tv1.tv_usec;
800 tv_count2 = (tv3.tv_sec - tv2.tv_sec)
802 + tv3.tv_usec - tv2.tv_usec;
804 pr_info("pcie ep: Data transfer is successful."
806 " tv_count2 %dus.\n",
807 tv_count1, tv_count2);
808 pr_info("pcie ep: Data write speed:%ldMB/s.\n",
809 ((test_region_size/1024)
812 pr_info("pcie ep: Data read speed:%ldMB/s.\n",
813 ((test_region_size/1024)
817 pr_info("pcie ep: Data transfer is failed.\n");
821 ret = imx6_add_pcie_port(pp, pdev);
825 platform_set_drvdata(pdev, imx6_pcie);
833 static const struct of_device_id imx6_pcie_of_match[] = {
834 { .compatible = "fsl,imx6q-pcie", },
837 MODULE_DEVICE_TABLE(of, imx6_pcie_of_match);
839 static struct platform_driver imx6_pcie_driver = {
841 .name = "imx6q-pcie",
842 .owner = THIS_MODULE,
843 .of_match_table = imx6_pcie_of_match,
847 /* Freescale PCIe driver does not allow module unload */
849 static int __init imx6_pcie_init(void)
851 return platform_driver_probe(&imx6_pcie_driver, imx6_pcie_probe);
853 fs_initcall(imx6_pcie_init);
855 MODULE_AUTHOR("Sean Cross <xobs@kosagi.com>");
856 MODULE_DESCRIPTION("Freescale i.MX6 PCIe host controller driver");
857 MODULE_LICENSE("GPL v2");