Skip to contentSkip to conversation

Add PCIe support for i.MX6q

PATCH Superseded Sean Cross 3 participants 7 messages Sep 16, 2013

Subsystems (9)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Sean Cross

author
#0 lore raw

v5 cover Add PCIe support for i.MX6q

This patchset adds support for the PCI Express port present on the i.MX6 SoC. The port is based on Synopsis Designware IP with a custom PHY.

Changes since v4:
- Add an abort exception handler
- Fix register ordering in imx6q-iomuxc-gpr.h
- Enable sata_ref_100m during clock initialization
- Minor changes to lvds[12]_gate definitions

Changes since v3:
- Moved clock initialization to board clock file
- Reworked memory range layout
- Reduced the duration of several sleep calls

Changes since v2:
- Reworked source file with Sascha Hauer's suggestions

Changes since v1:
- Use the Designware controller code for BAR initialization

Sean Cross (3):
ARM: imx: Add LVDS general-purpose clocks to i.MX6Q
ARM: imx6q: Add PCIe bits to GPR syscon definition
PCI: imx6: Add support for i.MX6 PCIe controller

 .../devicetree/bindings/clock/imx6q-clock.txt      |    4 +
 .../devicetree/bindings/pci/designware-pcie.txt    |    5 +
 arch/arm/boot/dts/imx6qdl.dtsi                     |   16 +
 arch/arm/mach-imx/Kconfig                          |    2 +
 arch/arm/mach-imx/clk-imx6q.c                      |   34 +-
 drivers/pci/host/Kconfig                           |    6 +
 drivers/pci/host/Makefile                          |    1 +
 drivers/pci/host/pci-imx6.c                        |  499 ++++++++++++++++++++
 include/linux/mfd/syscon/imx6q-iomuxc-gpr.h        |    8 +
 9 files changed, 574 insertions(+), 1 deletion(-)
 create mode 100644 drivers/pci/host/pci-imx6.c
Signature · 1 line
1.7.9.5
author
#1 lore raw

PATCH v5 1/3 ARM: imx: Add LVDS general-purpose clocks to i.MX6Q

The i.MX6 has two general-purpose LVDS clocks that can be driven from a variety of sources. This patch adds a mux and a gate for both of these clocks.

---
 .../devicetree/bindings/clock/imx6q-clock.txt      |    4 ++++
 arch/arm/mach-imx/clk-imx6q.c                      |   22 +++++++++++++++++++-
 2 files changed, 25 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/clock/imx6q-clock.txt +4 -0
index 5a90a72..35e82c7 100644
@@ -215,6 +215,10 @@ clocks and IDs.
 	cko2      		200
 	cko      		201
 	vdoa      		202
+	lvds1_sel		203
+	lvds2_sel		204
+	lvds1_gate		205
+	lvds2_gate		206
 
 Examples:
 
arch/arm/mach-imx/clk-imx6q.c +21 -1
index 9181a24..971356b 100644
@@ -217,6 +217,11 @@ static const char *cko2_sels[] = {
 	"uart_serial", "spdif", "asrc", "hsi_tx",
 };
 static const char *cko_sels[] = { "cko1", "cko2", };
+static const char *lvds_sels[] = {
+	"dummy", "dummy", "dummy", "dummy", "dummy", "dummy",
+	"pll4_audio", "pll5_video", "pll8_mlb", "enet_ref",
+	"pcie_ref", "sata_ref",
+};
 
 enum mx6q_clks {
 	dummy, ckil, ckih, osc, pll2_pfd0_352m, pll2_pfd1_594m, pll2_pfd2_396m,
@@ -251,7 +256,8 @@ enum mx6q_clks {
 	ssi2_ipg, ssi3_ipg, rom, usbphy1, usbphy2, ldb_di0_div_3_5, ldb_di1_div_3_5,
 	sata_ref, sata_ref_100m, pcie_ref, pcie_ref_125m, enet_ref, usbphy1_gate,
 	usbphy2_gate, pll4_post_div, pll5_post_div, pll5_video_div, eim_slow,
-	spdif, cko2_sel, cko2_podf, cko2, cko, vdoa, clk_max
+	spdif, cko2_sel, cko2_podf, cko2, cko, vdoa,
+	lvds1_sel, lvds2_sel, lvds1_gate, lvds2_gate, clk_max
 };
 
 static struct clk *clk[clk_max];
@@ -342,6 +348,18 @@ static void __init imx6q_clocks_init(struct device_node *ccm_node)
 			base + 0xe0, 0, 2, 0, clk_enet_ref_table,
 			&imx_ccm_lock);
 
+	clk[lvds1_sel] = imx_clk_mux("lvds1_sel", base + 0x160, 0, 5, lvds_sels, ARRAY_SIZE(lvds_sels));
+	clk[lvds2_sel] = imx_clk_mux("lvds2_sel", base + 0x160, 5, 5, lvds_sels, ARRAY_SIZE(lvds_sels));
+
+	/*
+	 * lvds1_gate and lvds2_gate are pseudo-gates.  Both can be
+	 * independently configured as clock inputs or outputs.  We treat
+	 * the "output_enable" bit as a gate, even though it's really just
+	 * enabling clock output.
+	 */
+	clk[lvds1_gate] = imx_clk_gate("lvds1_gate", "dummy", base + 0x160, 10);
+	clk[lvds2_gate] = imx_clk_gate("lvds2_gate", "dummy", base + 0x160, 11);
+
 	/*                                name              parent_name        reg       idx */
 	clk[pll2_pfd0_352m] = imx_clk_pfd("pll2_pfd0_352m", "pll2_bus",     base + 0x100, 0);
 	clk[pll2_pfd1_594m] = imx_clk_pfd("pll2_pfd1_594m", "pll2_bus",     base + 0x100, 1);
@@ -569,6 +587,8 @@ static void __init imx6q_clocks_init(struct device_node *ccm_node)
 	clk_register_clkdev(clk[cko1_sel], "cko1_sel", NULL);
 	clk_register_clkdev(clk[ahb], "ahb", NULL);
 	clk_register_clkdev(clk[cko1], "cko1", NULL);
+	clk_register_clkdev(clk[lvds1_gate], "lvds1_gate", NULL);
+	clk_register_clkdev(clk[lvds2_gate], "lvds2_gate", NULL);
 	clk_register_clkdev(clk[arm], NULL, "cpu0");
 	clk_register_clkdev(clk[pll4_post_div], "pll4_post_div", NULL);
 	clk_register_clkdev(clk[pll4_audio], "pll4_audio", NULL);
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH v5 1/3 ARM: imx: Add LVDS general-purpose clocks to i.MX6Q

Quoted 71 lines · Sean Cross

The i.MX6 has two general-purpose LVDS clocks that can be driven from a variety of sources. This patch adds a mux and a gate for both of these clocks.

---
 .../devicetree/bindings/clock/imx6q-clock.txt      |    4 ++++
 arch/arm/mach-imx/clk-imx6q.c                      |   22 +++++++++++++++++++-
 2 files changed, 25 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/clock/imx6q-clock.txt +4 -0
index 5a90a72..35e82c7 100644
@@ -215,6 +215,10 @@ clocks and IDs.
 	cko2      		200
 	cko      		201
 	vdoa      		202
+	lvds1_sel		203
+	lvds2_sel		204
+	lvds1_gate		205
+	lvds2_gate		206
 
 Examples:
 
arch/arm/mach-imx/clk-imx6q.c +19 -1
index 9181a24..971356b 100644
@@ -217,6 +217,11 @@ static const char *cko2_sels[] = {
 	"uart_serial", "spdif", "asrc", "hsi_tx",
 };
 static const char *cko_sels[] = { "cko1", "cko2", };
+static const char *lvds_sels[] = {
+	"dummy", "dummy", "dummy", "dummy", "dummy", "dummy",
+	"pll4_audio", "pll5_video", "pll8_mlb", "enet_ref",
+	"pcie_ref", "sata_ref",
+};
 
 enum mx6q_clks {
 	dummy, ckil, ckih, osc, pll2_pfd0_352m, pll2_pfd1_594m, pll2_pfd2_396m,
@@ -251,7 +256,8 @@ enum mx6q_clks {
 	ssi2_ipg, ssi3_ipg, rom, usbphy1, usbphy2, ldb_di0_div_3_5, ldb_di1_div_3_5,
 	sata_ref, sata_ref_100m, pcie_ref, pcie_ref_125m, enet_ref, usbphy1_gate,
 	usbphy2_gate, pll4_post_div, pll5_post_div, pll5_video_div, eim_slow,
-	spdif, cko2_sel, cko2_podf, cko2, cko, vdoa, clk_max
+	spdif, cko2_sel, cko2_podf, cko2, cko, vdoa,
+	lvds1_sel, lvds2_sel, lvds1_gate, lvds2_gate, clk_max
 };
 
 static struct clk *clk[clk_max];
@@ -342,6 +348,18 @@ static void __init imx6q_clocks_init(struct device_node *ccm_node)
 			base + 0xe0, 0, 2, 0, clk_enet_ref_table,
 			&imx_ccm_lock);
 
+	clk[lvds1_sel] = imx_clk_mux("lvds1_sel", base + 0x160, 0, 5, lvds_sels, ARRAY_SIZE(lvds_sels));
+	clk[lvds2_sel] = imx_clk_mux("lvds2_sel", base + 0x160, 5, 5, lvds_sels, ARRAY_SIZE(lvds_sels));
+
+	/*
+	 * lvds1_gate and lvds2_gate are pseudo-gates.  Both can be
+	 * independently configured as clock inputs or outputs.  We treat
+	 * the "output_enable" bit as a gate, even though it's really just
+	 * enabling clock output.
+	 */
+	clk[lvds1_gate] = imx_clk_gate("lvds1_gate", "dummy", base + 0x160, 10);
+	clk[lvds2_gate] = imx_clk_gate("lvds2_gate", "dummy", base + 0x160, 11);
+
 	/*                                name              parent_name        reg       idx */
 	clk[pll2_pfd0_352m] = imx_clk_pfd("pll2_pfd0_352m", "pll2_bus",     base + 0x100, 0);
 	clk[pll2_pfd1_594m] = imx_clk_pfd("pll2_pfd1_594m", "pll2_bus",     base + 0x100, 1);

arch/arm/mach-imx/clk-imx6q.c static void __init imx6q_clocks_init(struct device_node *ccm_node) · line 591

Quoted 5 lines
arch/arm/mach-imx/clk-imx6q.c +2 -0
@@ -569,6 +587,8 @@ static void __init imx6q_clocks_init(struct device_node *ccm_node)
 	clk_register_clkdev(clk[cko1_sel], "cko1_sel", NULL);
 	clk_register_clkdev(clk[ahb], "ahb", NULL);
 	clk_register_clkdev(clk[cko1], "cko1", NULL);
+	clk_register_clkdev(clk[lvds1_gate], "lvds1_gate", NULL);
+	clk_register_clkdev(clk[lvds2_gate], "lvds2_gate", NULL);

Again, I do not think you need these clk lookups.

Shawn

Quoted 6 lines
arch/arm/mach-imx/clk-imx6q.c +0 -0
 	clk_register_clkdev(clk[arm], NULL, "cpu0");
 	clk_register_clkdev(clk[pll4_post_div], "pll4_post_div", NULL);
 	clk_register_clkdev(clk[pll4_audio], "pll4_audio", NULL);
Signature · 1 line
1.7.9.5
author
#3 lore raw

PATCH v5 2/3 ARM: imx6q: Add PCIe bits to GPR syscon definition

In reply to Sean Cross

PCIe requires additional bits be defined for GPR8 and GPR12.

---
 include/linux/mfd/syscon/imx6q-iomuxc-gpr.h |    8 ++++++++
 1 file changed, 8 insertions(+)
include/linux/mfd/syscon/imx6q-iomuxc-gpr.h +8 -0
index b6bdcd6..e00e9f3 100644
@@ -241,6 +241,12 @@
 
 #define IMX6Q_GPR5_L2_CLK_STOP			BIT(8)
 
+#define IMX6Q_GPR8_TX_SWING_LOW			(0x7f << 25)
+#define IMX6Q_GPR8_TX_SWING_FULL		(0x7f << 18)
+#define IMX6Q_GPR8_TX_DEEMPH_GEN2_6DB		(0x3f << 12)
+#define IMX6Q_GPR8_TX_DEEMPH_GEN2_3P5DB		(0x3f << 6)
+#define IMX6Q_GPR8_TX_DEEMPH_GEN1		(0x3f << 0)
+
 #define IMX6Q_GPR9_TZASC2_BYP			BIT(1)
 #define IMX6Q_GPR9_TZASC1_BYP			BIT(0)
 
@@ -273,7 +279,9 @@
 #define IMX6Q_GPR12_ARMP_AHB_CLK_EN		BIT(26)
 #define IMX6Q_GPR12_ARMP_ATB_CLK_EN		BIT(25)
 #define IMX6Q_GPR12_ARMP_APB_CLK_EN		BIT(24)
+#define IMX6Q_GPR12_DEVICE_TYPE			(0xf << 12)
 #define IMX6Q_GPR12_PCIE_CTL_2			BIT(10)
+#define IMX6Q_GPR12_LOS_LEVEL			(0x1f << 4)
 
 #define IMX6Q_GPR13_SDMA_STOP_REQ		BIT(30)
 #define IMX6Q_GPR13_CAN2_STOP_REQ		BIT(29)
Signature · 1 line
1.7.9.5
author
#4 lore raw

PATCH v5 3/3 PCI: imx6: Add support for i.MX6 PCIe controller

In reply to Sean Cross

Add support for the PCIe port present on the i.MX6 family of controllers. These use the Synopsis Designware core tied to their own PHY.

---
 .../devicetree/bindings/pci/designware-pcie.txt    |    5 +
 arch/arm/boot/dts/imx6qdl.dtsi                     |   16 +
 arch/arm/mach-imx/Kconfig                          |    2 +
 arch/arm/mach-imx/clk-imx6q.c                      |   12 +
 drivers/pci/host/Kconfig                           |    6 +
 drivers/pci/host/Makefile                          |    1 +
 drivers/pci/host/pci-imx6.c                        |  499 ++++++++++++++++++++
 7 files changed, 541 insertions(+)
 create mode 100644 drivers/pci/host/pci-imx6.c
Documentation/devicetree/bindings/pci/designware-pcie.txt +5 -0
index eabcb4b..41d8419 100644
@@ -21,6 +21,11 @@ Required properties:
 - num-lanes: number of lanes to use
 - reset-gpio: gpio pin number of power good signal
 
+Optional properties for fsl,imx6-pcie
+- power-on-gpio: gpio pin number of power-enable signal
+- wake-up-gpio: gpio pin number of incoming wakeup signal
+- disable-gpio: gpio pin number of outgoing rfkill/endpoint disable signal
+
 Example:
 
 SoC specific DT Entry:
arch/arm/boot/dts/imx6qdl.dtsi +16 -0
index ccd55c2..ec72271 100644
@@ -116,6 +116,22 @@
 			arm,data-latency = <4 2 3>;
 		};
 
+		pcie: pcie at 0x01000000 {
+			compatible = "fsl,imx6-pcie", "snps,dw-pcie";
+			reg = <0x01ffc000 0x4000>; /* DBI */
+
+			#address-cells = <3>;
+			#size-cells = <2>;
+			device_type = "pci";
+			ranges = <0x00000800 0 0x01f00000 0x01f00000 0 0x00080000 /* configuration space */
+				  0x81000000 0 0          0x01f80000 0 0x00010000 /* downstream I/O */
+				  0x82000000 0 0x01000000 0x01000000 0 0x00f00000>; /* non-prefetchable memory */
+
+			num-lanes = <1>;
+			interrupts = <0 123 0x04>;
+			status = "disabled";
+		};
+
 		pmu {
 			compatible = "arm,cortex-a9-pmu";
 			interrupts = <0 94 0x04>;
arch/arm/mach-imx/Kconfig +2 -0
index 29a8af6..e6ac281 100644
@@ -801,6 +801,8 @@ config SOC_IMX6Q
 	select HAVE_IMX_SRC
 	select HAVE_SMP
 	select MFD_SYSCON
+	select MIGHT_HAVE_PCI
+	select PCI_DOMAINS if PCI
 	select PINCTRL
 	select PINCTRL_IMX6Q
 	select PL310_ERRATA_588369 if CACHE_PL310
arch/arm/mach-imx/clk-imx6q.c +12 -0
index 971356b..d30ff63 100644
@@ -623,6 +623,18 @@ static void __init imx6q_clocks_init(struct device_node *ccm_node)
 	if (ret)
 		pr_warn("failed to set up CLKO: %d\n", ret);
 
+	/*
+	 * All existing boards with PCIe use LVDS1
+	 */
+	if (IS_ENABLED(CONFIG_PCI_IMX6)) {
+		clk_set_parent(clk[lvds1_sel], clk[sata_ref]);
+		clk_prepare_enable(clk[lvds1_gate]);
+		clk_prepare_enable(clk[pcie_ref_125m]);
+		clk_prepare_enable(clk[sata_ref_100m]);
+		clk_prepare_enable(clk[pcie_axi]);
+        }
+
+
 	/* Set initial power mode */
 	imx6q_set_lpm(WAIT_CLOCKED);
 
drivers/pci/host/Kconfig +6 -0
index 3d95048..efa24d9 100644
@@ -15,6 +15,12 @@ config PCI_EXYNOS
 	select PCIEPORTBUS
 	select PCIE_DW
 
+config PCI_IMX6
+	bool "Freescale i.MX6 PCIe controller"
+	depends on SOC_IMX6Q
+	select PCIEPORTBUS
+	select PCIE_DW
+
 config PCI_TEGRA
 	bool "NVIDIA Tegra PCIe controller"
 	depends on ARCH_TEGRA
drivers/pci/host/Makefile +1 -0
index c9a997b..287d6a0 100644
@@ -1,4 +1,5 @@
 obj-$(CONFIG_PCIE_DW) += pcie-designware.o
 obj-$(CONFIG_PCI_EXYNOS) += pci-exynos.o
+obj-$(CONFIG_PCI_IMX6) += pci-imx6.o
 obj-$(CONFIG_PCI_MVEBU) += pci-mvebu.o
 obj-$(CONFIG_PCI_TEGRA) += pci-tegra.o
drivers/pci/host/pci-imx6.c new file +499 -0

499 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#5 lore raw

PATCH v5 3/3 PCI: imx6: Add support for i.MX6 PCIe controller

Quoted 4 lines · Sean Cross

Add support for the PCIe port present on the i.MX6 family of controllers. These use the Synopsis Designware core tied to their own PHY.

Bjorn gave his ACK with asking us to apply the patch via arm-soc tree. You should add his ACK into your patch.

Shawn

maintainer
#6 lore raw

PATCH v5 3/3 PCI: imx6: Add support for i.MX6 PCIe controller

In reply to Sean Cross
Quoted 8 lines · Sean Cross

Add support for the PCIe port present on the i.MX6 family of controllers. These use the Synopsis Designware core tied to their own PHY.

arch/arm/mach-imx/clk-imx6q.c +0 -0
index 971356b..d30ff63 100644

arch/arm/mach-imx/clk-imx6q.c static void __init imx6q_clocks_init(struct device_node *ccm_node) · line 630

Quoted 8 lines
arch/arm/mach-imx/clk-imx6q.c +5 -0
@@ -623,6 +623,18 @@ static void __init imx6q_clocks_init(struct device_node *ccm_node)
 	if (ret)
 		pr_warn("failed to set up CLKO: %d\n", ret);
 
+	/*
+	 * All existing boards with PCIe use LVDS1
+	 */
+	if (IS_ENABLED(CONFIG_PCI_IMX6)) {
+		clk_set_parent(clk[lvds1_sel], clk[sata_ref]);

This is fine,

arch/arm/mach-imx/clk-imx6q.c static void __init imx6q_clocks_init(struct device_node *ccm_node) · line 634

Quoted 4 lines
arch/arm/mach-imx/clk-imx6q.c +4 -0
+		clk_prepare_enable(clk[lvds1_gate]);
+		clk_prepare_enable(clk[pcie_ref_125m]);
+		clk_prepare_enable(clk[sata_ref_100m]);
+		clk_prepare_enable(clk[pcie_axi]);

but the clocks should be really enabled in the driver that needs them.

arch/arm/mach-imx/clk-imx6q.c static void __init imx6q_clocks_init(struct device_node *ccm_node)

Quoted 10 lines
arch/arm/mach-imx/clk-imx6q.c +10 -0
+static int pcie_phy_poll_ack(void __iomem *dbi_base, int exp_val)
+{
+	u32 val;
+	u32 max_iterations = 10;
+	u32 wait_counter = 0;
+
+	do {
+		val = readl(dbi_base + PCIE_PHY_STAT);
+		val = (val >> PCIE_PHY_STAT_ACK_LOC) & 0x1;
+		wait_counter++;
		if (val == exp_val)
			return 0;

arch/arm/mach-imx/clk-imx6q.c

Quoted 1 line
arch/arm/mach-imx/clk-imx6q.c +1 -0
+		udelay(1);

Avoids the udelay when the value is correct during the first iteration.

Quoted 8 lines
arch/arm/mach-imx/clk-imx6q.c +8 -0
+	} while ((wait_counter < max_iterations) && (val != exp_val));
+
+	if (val != exp_val)
+		return -ETIMEDOUT;
+
+	return 0;
+}
+

...

Quoted 10 lines
arch/arm/mach-imx/clk-imx6q.c +10 -0
+/* Read from the 16-bit PCIe PHY control registers (not memory-mapped) */
+static int pcie_phy_read(void __iomem *dbi_base, int addr , int *data)
+{
+	u32 val, phy_ctl;
+	int ret;
+
+	ret = pcie_phy_wait_ack(dbi_base, addr);
+	if (ret)
+		return ret;
+

arch/arm/mach-imx/clk-imx6q.c

Quoted 10 lines
arch/arm/mach-imx/clk-imx6q.c +10 -0
+	/* assert Read signal */
+	phy_ctl = 0x1 << PCIE_PHY_CTRL_RD_LOC;
+	writel(phy_ctl, dbi_base + PCIE_PHY_CTRL);
+
+	ret = pcie_phy_poll_ack(dbi_base, 1);
+	if (ret)
+		return ret;
+
+	val = readl(dbi_base + PCIE_PHY_STAT);
+	*data = (val & (0xffff << PCIE_PHY_STAT_DATA_LOC));

This works because PCIE_PHY_STAT_DATA_LOC is 0. Otherwise you would have to do:

	*data = (val >> PCIE_PHY_STAT_DATA_LOC) & 0xfff;

I suggest to simply drop the bogus zero bit shift.

Sascha

Signature · 4 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |