Skip to contentSkip to conversation

*** SUBJECT HERE ***

PATCH Superseded Mike Rapoport 4 participants 10 messages Sep 21, 2010 – Sep 23, 2010

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover *** SUBJECT HERE ***

These patches enable PCI Express support on Tegra2.
The implementation is based on original NVidia code from (1), but it is heavily reworked to avoid custom PCI enumeration and make the code more Linux friendly.

This implementation assumes that the PCIe subsystem is fully powered and ungated by the bootloader.

[1] git://nv-tegra.nvidia.com/linux-2.6.git

v2 changes:
* Update PCIe clocks implementation as per Colin and Gary suggestions
* Update I/O space access as suggested by Arnd and Russell.
* Remove debug leftovers and unify error reporting

The following changes since commit b30a3f6257ed2105259b404d419b4964e363928c:
Linus Torvalds (1):

        Linux 2.6.36-rc5

Mike Rapoport (3):
[ARM] tegra: add PCI Express clocks
[ARM] tegra: add PCI Express support
[ARM] tegra: harmony: enable PCI Express

 arch/arm/mach-tegra/Kconfig                 |    4 +
 arch/arm/mach-tegra/Makefile                |    2 +
 arch/arm/mach-tegra/board-harmony-pcie.c    |   52 ++
 arch/arm/mach-tegra/board.h                 |    1 +
 arch/arm/mach-tegra/include/mach/hardware.h |    4 +
 arch/arm/mach-tegra/include/mach/io.h       |   12 +-
 arch/arm/mach-tegra/pcie.c                  |  915 +++++++++++++++++++++++++++
 arch/arm/mach-tegra/tegra2_clocks.c         |   46 ++
 8 files changed, 1035 insertions(+), 1 deletions(-)
 create mode 100644 arch/arm/mach-tegra/board-harmony-pcie.c
 create mode 100644 arch/arm/mach-tegra/pcie.c
#1 lore raw

PATCH v2 1/3 tegra: add PCI Express clocks

---
 arch/arm/mach-tegra/tegra2_clocks.c |   46 +++++++++++++++++++++++++++++++++++
 1 files changed, 46 insertions(+), 0 deletions(-)
arch/arm/mach-tegra/tegra2_clocks.c +46 -0
index 4261632..5ce4783 100644
@@ -92,6 +92,8 @@
 #define PLLD_MISC_DIV_RST		(1<<23)
 #define PLLD_MISC_DCCON_SHIFT		12
 
+#define PLLE_MISC_READY			(1 << 15)
+
 #define PERIPH_CLK_TO_ENB_REG(c)	((c->clk_num / 32) * 4)
 #define PERIPH_CLK_TO_ENB_SET_REG(c)	((c->clk_num / 32) * 8)
 #define PERIPH_CLK_TO_ENB_BIT(c)	(1 << (c->clk_num % 32))
@@ -482,6 +484,31 @@ static struct clk_ops tegra_pll_ops = {
 	.recalculate_rate	= tegra2_pll_clk_recalculate_rate,
 };
 
+static int tegra2_plle_clk_enable(struct clk *c)
+{
+	u32 val;
+
+	pr_debug("%s on clock %s\n", __func__, c->name);
+
+	mdelay(1);
+
+	val = clk_readl(c->reg + PLL_BASE);
+	if (!(val & PLLE_MISC_READY))
+		return -EBUSY;
+
+	val = clk_readl(c->reg + PLL_BASE);
+	val |= PLL_BASE_ENABLE | PLL_BASE_BYPASS;
+	clk_writel(val, c->reg + PLL_BASE);
+
+	return 0;
+}
+
+static struct clk_ops tegra_plle_ops = {
+	.init       = tegra2_pll_clk_init,
+	.enable     = tegra2_plle_clk_enable,
+	.set_rate   = tegra2_pll_clk_set_rate,
+};
+
 /* Clock divider ops */
 static void tegra2_pll_div_clk_init(struct clk *c)
 {
@@ -1030,6 +1057,21 @@ static struct clk tegra_pll_x = {
 	.pll_table = tegra_pll_x_table,
 };
 
+static struct clk_pll_table tegra_pll_e_table[] = {
+	{ 12000000, 100000000,  200,  24, 1, 0 },
+};
+
+static struct clk tegra_pll_e = {
+	.name      = "pll_e",
+	.flags	   = PLL_ALT_MISC_REG,
+	.ops       = &tegra_plle_ops,
+	.input_min = 12000000,
+	.input_max = 12000000,
+	.parent    = &tegra_clk_m,
+	.reg       = 0xe8,
+	.pll_table = tegra_pll_e_table,
+};
+
 static struct clk tegra_clk_d = {
 	.name      = "clk_d",
 	.flags     = PERIPH_NO_RESET,
@@ -1265,6 +1307,9 @@ struct clk tegra_periph_clks[] = {
 	PERIPH_CLK("usb3",	"usb.2",		NULL,	59,	0,	mux_clk_m,			0),
 	PERIPH_CLK("emc",	"emc",			NULL,	57,	0x19c,	mux_pllm_pllc_pllp_clkm,	MUX | DIV_U71 | PERIPH_EMC_ENB),
 	PERIPH_CLK("dsi",	"dsi",			NULL,	48,	0,	mux_plld,			0),
+	PERIPH_CLK("pex",       NULL,			"pex",  70,     0,	mux_clk_m,			PERIPH_MANUAL_RESET),
+	PERIPH_CLK("afi",       NULL,			"afi",  72,     0,	mux_clk_m,			PERIPH_MANUAL_RESET),
+	PERIPH_CLK("pcie_xclk", NULL,		  "pcie_xclk",  74,     0,	mux_clk_m,			PERIPH_MANUAL_RESET),
 };
 
 #define CLK_DUPLICATE(_name, _dev, _con)		\
@@ -1315,6 +1360,7 @@ struct clk_lookup tegra_clk_lookups[] = {
 	CLK(NULL,	"pll_d_out0",	&tegra_pll_d_out0),
 	CLK(NULL,	"pll_u",	&tegra_pll_u),
 	CLK(NULL,	"pll_x",	&tegra_pll_x),
+	CLK(NULL,	"pll_e",	&tegra_pll_e),
 	CLK(NULL,	"cpu",		&tegra_clk_cpu),
 	CLK(NULL,	"sys",		&tegra_clk_sys),
 	CLK(NULL,	"hclk",		&tegra_clk_hclk),
Signature · 1 line
1.6.6.2
#2 lore raw

PATCH v2 2/3 tegra: add PCI Express support

In reply to Mike Rapoport
CC Arnd Bergmann <[email protected]>
CC Russell King <[email protected]>
CC Colin Cross <[email protected]>
CC Gary King <[email protected]>
---
 arch/arm/mach-tegra/Kconfig                 |    4 +
 arch/arm/mach-tegra/Makefile                |    1 +
 arch/arm/mach-tegra/board.h                 |    1 +
 arch/arm/mach-tegra/include/mach/hardware.h |    4 +
 arch/arm/mach-tegra/include/mach/io.h       |   12 +-
 arch/arm/mach-tegra/pcie.c                  |  915 +++++++++++++++++++++++++++
 6 files changed, 936 insertions(+), 1 deletions(-)
 create mode 100644 arch/arm/mach-tegra/pcie.c
arch/arm/mach-tegra/Kconfig +4 -0
index a57713c..5f09846 100644
@@ -16,6 +16,10 @@ config ARCH_TEGRA_2x_SOC
 
 endchoice
 
+config TEGRA_PCI
+	bool "PCI Express support"
+	select PCI
+
 comment "Tegra board type"
 
 config MACH_HARMONY
arch/arm/mach-tegra/Makefile +1 -0
index 51e9370..23c9600 100644
@@ -9,6 +9,7 @@ obj-$(CONFIG_ARCH_TEGRA_2x_SOC)         += clock.o
 obj-$(CONFIG_ARCH_TEGRA_2x_SOC)         += tegra2_clocks.o
 obj-$(CONFIG_SMP)                       += platsmp.o localtimer.o headsmp.o
 obj-$(CONFIG_HOTPLUG_CPU)               += hotplug.o
+obj-$(CONFIG_TEGRA_PCI)			+= pcie.o
 
 obj-${CONFIG_MACH_HARMONY}              += board-harmony.o
 obj-${CONFIG_MACH_HARMONY}              += board-harmony-pinmux.o
arch/arm/mach-tegra/board.h +1 -0
index 3d06354..0de565c 100644
@@ -27,6 +27,7 @@ void __init tegra_common_init(void);
 void __init tegra_map_common_io(void);
 void __init tegra_init_irq(void);
 void __init tegra_init_clock(void);
+int __init tegra_pcie_init(bool init_port0, bool init_port1);
 
 extern struct sys_timer tegra_timer;
 #endif
arch/arm/mach-tegra/include/mach/hardware.h +4 -0
index 6014edf..56e43b3 100644
@@ -21,4 +21,8 @@
 #ifndef __MACH_TEGRA_HARDWARE_H
 #define __MACH_TEGRA_HARDWARE_H
 
+#define PCIBIOS_MIN_IO			0x1000
+#define PCIBIOS_MIN_MEM			0
+#define pcibios_assign_all_busses()	1
+
 #endif
arch/arm/mach-tegra/include/mach/io.h +11 -1
index 35edfc3..50f981a 100644
@@ -21,7 +21,7 @@
 #ifndef __MACH_TEGRA_IO_H
 #define __MACH_TEGRA_IO_H
 
-#define IO_SPACE_LIMIT 0xffffffff
+#define IO_SPACE_LIMIT 0xffff
 
 /* On TEGRA, many peripherals are very closely packed in
  * two 256MB io windows (that actually only use about 64KB
@@ -67,10 +67,20 @@ void tegra_iounmap(volatile void __iomem *addr);
 
 #define IO_ADDRESS(n) ((void __iomem *) IO_TO_VIRT(n))
 
+#ifdef CONFIG_TEGRA_PCI
+extern void __iomem *tegra_pcie_io_base;
+
+static inline void __iomem *__io(unsigned long addr)
+{
+	return tegra_pcie_io_base + (addr & IO_SPACE_LIMIT);
+}
+#else
 static inline void __iomem *__io(unsigned long addr)
 {
 	return (void __iomem *)addr;
 }
+#endif
+
 #define __io(a)         __io(a)
 #define __mem_pci(a)    (a)
 
arch/arm/mach-tegra/pcie.c new file +915 -0

915 lines not on this page · raw message

Signature · 1 line
1.6.6.2
#8 lore raw

PATCH v2 3/3 tegra: harmony: enable PCI Express

In reply to Mike Rapoport
---
 arch/arm/mach-tegra/Makefile             |    1 +
 arch/arm/mach-tegra/board-harmony-pcie.c |   52 ++++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/mach-tegra/board-harmony-pcie.c
arch/arm/mach-tegra/Makefile +1 -0
index 23c9600..60f73c7 100644
@@ -13,3 +13,4 @@ obj-$(CONFIG_TEGRA_PCI)			+= pcie.o
 
 obj-${CONFIG_MACH_HARMONY}              += board-harmony.o
 obj-${CONFIG_MACH_HARMONY}              += board-harmony-pinmux.o
+obj-${CONFIG_MACH_HARMONY}              += board-harmony-pcie.o
arch/arm/mach-tegra/board-harmony-pcie.c new file +52 -0

52 lines not on this page · raw message

Signature · 1 line
1.6.6.2
#3 lore raw

PATCH v2 2/3 tegra: add PCI Express support

In reply to Mike Rapoport
Quoted 5 lines
CC Arnd Bergmann <[email protected]>
CC Russell King <[email protected]>
CC Colin Cross <[email protected]>
CC Gary King <[email protected]>
Quoted 13 lines · Mike Rapoport

/* On TEGRA, many peripherals are very closely packed in
* two 256MB io windows (that actually only use about 64KB

arch/arm/mach-tegra/include/mach/io.h +6 -0
@@ -67,10 +67,20 @@ void tegra_iounmap(volatile void __iomem *addr);
 
 #define IO_ADDRESS(n) ((void __iomem *) IO_TO_VIRT(n))
 
+#ifdef CONFIG_TEGRA_PCI
+extern void __iomem *tegra_pcie_io_base;
+
+static inline void __iomem *__io(unsigned long addr)
+{
+       return tegra_pcie_io_base + (addr & IO_SPACE_LIMIT);

arch/arm/mach-tegra/include/mach/io.h void tegra_iounmap(volatile void __iomem *addr); · line 85

Quoted 10 lines
arch/arm/mach-tegra/include/mach/io.h +4 -0
+}
+#else
 static inline void __iomem *__io(unsigned long addr)
 {
        return (void __iomem *)addr;
 }
+#endif
+
 #define __io(a)         __io(a)
 #define __mem_pci(a)    (a)

I wonder what the #else path is for. If you don't have PCI, who would call __io? And wouldn't that result in a NULL pointer dereference?

Arnd

#4 lore raw

PATCH v2 2/3 tegra: add PCI Express support

Quoted 5 lines
Quoted 2 lines

#define __io(a) __io(a)
#define __mem_pci(a) (a)

I wonder what the #else path is for. If you don't have PCI, who would call __io? And wouldn't that result in a NULL pointer dereference?

If I remember correctly the legacy IDE (ATA) code is scanning "well known" IO port numbers...

Cheers!

PAwe?

#5 lore raw

PATCH v2 2/3 tegra: add PCI Express support

Quoted 8 lines · Pawel Moll
Quoted 5 lines
Quoted 2 lines

#define __io(a) __io(a)
#define __mem_pci(a) (a)

I wonder what the #else path is for. If you don't have PCI, who would call __io? And wouldn't that result in a NULL pointer dereference?

If I remember correctly the legacy IDE (ATA) code is scanning "well known" IO port numbers...

Right, that's the sort of thing I was worried about. I don't think IDE is a problem here though, because it would only get probed if you have a PCI/system/platform/of device registered to the system, which normally doesn't happen.

Arnd

#6 lore raw

PATCH v2 2/3 tegra: add PCI Express support

In reply to Arnd Bergmann
Quoted 26 lines · Arnd Bergmann
Quoted 5 lines
CC Arnd Bergmann <[email protected]>
CC Russell King <[email protected]>
CC Colin Cross <[email protected]>
CC Gary King <[email protected]>
Quoted 17 lines · Mike Rapoport

/* On TEGRA, many peripherals are very closely packed in
* two 256MB io windows (that actually only use about 64KB

arch/arm/mach-tegra/include/mach/io.h +8 -0
@@ -67,10 +67,20 @@ void tegra_iounmap(volatile void __iomem *addr);
 
 #define IO_ADDRESS(n) ((void __iomem *) IO_TO_VIRT(n))
 
+#ifdef CONFIG_TEGRA_PCI
+extern void __iomem *tegra_pcie_io_base;
+
+static inline void __iomem *__io(unsigned long addr)
+{
+       return tegra_pcie_io_base + (addr & IO_SPACE_LIMIT);
+}
+#else
 static inline void __iomem *__io(unsigned long addr)
 {
        return (void __iomem *)addr;
Quoted 8 lines

arch/arm/mach-tegra/include/mach/io.h void tegra_iounmap(volatile void __iomem *addr); · line 85

Quoted 5 lines
arch/arm/mach-tegra/include/mach/io.h +2 -0
 }
+#endif
+
 #define __io(a)         __io(a)
 #define __mem_pci(a)    (a)

I wonder what the #else path is for. If you don't have PCI, who would call __io?

No one should call __io without PCI. However, there are drivers that do not build without __io, e.g.:

CC drivers/serial/8250.o
drivers/serial/8250.c: In function 'hub6_serial_in':
drivers/serial/8250.c:397: error: implicit declaration of function 'outb' drivers/serial/8250.c:398: error: implicit declaration of function 'inb'

These references to inb and outb will not be called in runtime anyway, but they are required for the 8250 driver to build.
I believe there are other drivers except 8250 that require to have __io, although it will be never actually called on, e.g. Tegra-based platform.

Quoted 3 lines

And wouldn't that result in a NULL pointer dereference?

Arnd

Signature · 2 lines
Sincerely yours,
Mike.
#7 lore raw

PATCH v2 2/3 tegra: add PCI Express support

Quoted 8 lines · Mike Rapoport

No one should call __io without PCI. However, there are drivers that do not build without __io, e.g.:

CC drivers/serial/8250.o
drivers/serial/8250.c: In function 'hub6_serial_in':
drivers/serial/8250.c:397: error: implicit declaration of function 'outb' drivers/serial/8250.c:398: error: implicit declaration of function 'inb'

Quoted 4 lines

These references to inb and outb will not be called in runtime anyway, but they are required for the 8250 driver to build.
I believe there are other drivers except 8250 that require to have __io, although it will be never actually called on, e.g. Tegra-based platform.

Right, I've seen this before. I'll try to cook up a patch to fix it. The hub6 support depends on ISA anyway, so we shouldn't be building that code.

Arnd

#9 lore raw

PATCH v2 3/3 tegra: harmony: enable PCI Express

In reply to Mike Rapoport
Quoted 64 lines · Mike Rapoport
---
 arch/arm/mach-tegra/Makefile             |    1 +
 arch/arm/mach-tegra/board-harmony-pcie.c |   52 ++++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/mach-tegra/board-harmony-pcie.c
arch/arm/mach-tegra/Makefile +1 -0
index 23c9600..60f73c7 100644
@@ -13,3 +13,4 @@ obj-$(CONFIG_TEGRA_PCI)			+= pcie.o
 
 obj-${CONFIG_MACH_HARMONY}              += board-harmony.o
 obj-${CONFIG_MACH_HARMONY}              += board-harmony-pinmux.o
+obj-${CONFIG_MACH_HARMONY}              += board-harmony-pcie.o
arch/arm/mach-tegra/board-harmony-pcie.c new file +40 -0
new file mode 100644
index 0000000..824c0a1
@@ -0,0 +1,52 @@
+/*
+ * arch/arm/mach-tegra/board-harmony-pcie.c
+ *
+ * Copyright (C) 2010 CompuLab, Ltd.
+ * Mike Rapoport <[email protected]>
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/gpio.h>
+#include <linux/err.h>
+#include <linux/regulator/consumer.h>
+
+#include <mach/pinmux.h>
+#include "board.h"
+
+#ifdef CONFIG_TEGRA_PCI
+
+static int __init harmony_pcie_init(void)
+{
+	int err;
+
+	tegra_pinmux_set_tristate(TEGRA_PINGROUP_GPV, TEGRA_TRI_NORMAL);
+	tegra_pinmux_set_tristate(TEGRA_PINGROUP_SLXA, TEGRA_TRI_NORMAL);
+	tegra_pinmux_set_tristate(TEGRA_PINGROUP_SLXK, TEGRA_TRI_NORMAL);
+
+	err = tegra_pcie_init(true, true);
+	if (err)
+		goto err_pcie;
+
+	return 0;

arch/arm/mach-tegra/board-harmony-pcie.c line 50

Quoted 10 lines
arch/arm/mach-tegra/board-harmony-pcie.c new file +10 -0
+
+err_pcie:
+	tegra_pinmux_set_tristate(TEGRA_PINGROUP_GPV, TEGRA_TRI_TRISTATE);
+	tegra_pinmux_set_tristate(TEGRA_PINGROUP_SLXA, TEGRA_TRI_TRISTATE);
+	tegra_pinmux_set_tristate(TEGRA_PINGROUP_SLXK, TEGRA_TRI_TRISTATE);
+
+	return err;
+}
+
+subsys_initcall(harmony_pcie_init);

Hi,

This isn't multiboard-friendly, since this will run on all boards that are built-in. Please either check for the platform at the beginning and abort, or call this explicitly from another board init function.

-Olof