From patchwork Mon Jun 11 15:05:15 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 164212 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id AB1371007D8 for ; Tue, 12 Jun 2012 01:06:25 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755593Ab2FKPFs (ORCPT ); Mon, 11 Jun 2012 11:05:48 -0400 Received: from moutng.kundenserver.de ([212.227.17.10]:56231 "EHLO moutng.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755589Ab2FKPFk (ORCPT ); Mon, 11 Jun 2012 11:05:40 -0400 Received: from benhur.adnet.avionic-design.de (p548E0634.dip0.t-ipconnect.de [84.142.6.52]) by mrelayeu.kundenserver.de (node=mreu1) with ESMTP (Nemesis) id 0MC5LA-1Smvrz45bs-009Ssm; Mon, 11 Jun 2012 17:05:30 +0200 Received: from mailbox.adnet.avionic-design.de (add-virt-zarafa.adnet.avionic-design.de [172.20.129.9]) by benhur.adnet.avionic-design.de (Postfix) with ESMTP id ACFCD2C4123; Mon, 11 Jun 2012 17:05:30 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mailbox.adnet.avionic-design.de (Postfix) with ESMTP id EB64B2A28173; Mon, 11 Jun 2012 17:05:26 +0200 (CEST) X-Virus-Scanned: amavisd-new at avionic-design.de Received: from mailbox.adnet.avionic-design.de ([127.0.0.1]) by localhost (mailbox.avionic-design.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 3GbjObpZGb3w; Mon, 11 Jun 2012 17:05:25 +0200 (CEST) Received: from localhost (avionic-0098.adnet.avionic-design.de [172.20.31.233]) (Authenticated sender: thierry.reding) by mailbox.adnet.avionic-design.de (Postfix) with ESMTPA id 79E9D2A2802C; Mon, 11 Jun 2012 17:05:23 +0200 (CEST) From: Thierry Reding To: linux-tegra@vger.kernel.org Cc: Jesse Barnes , linux-pci@vger.kernel.org, Grant Likely , Rob Herring , devicetree-discuss@lists.ozlabs.org, Russell King , linux-arm-kernel@lists.infradead.org, Colin Cross , Olof Johansson , Stephen Warren Subject: [PATCH v2 07/10] ARM: tegra: pcie: Add device tree support Date: Mon, 11 Jun 2012 17:05:15 +0200 Message-Id: <1339427118-32263-8-git-send-email-thierry.reding@avionic-design.de> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1339427118-32263-1-git-send-email-thierry.reding@avionic-design.de> References: <1339427118-32263-1-git-send-email-thierry.reding@avionic-design.de> X-Provags-ID: V02:K0:z6qoEfdusnX/lcpxy2OZERlxhEgsLohWyounxU045MA nDidcw2yZM+ftH050cmObnQ4hiGzOYiD1BiqcaF9DJbX6cR/cf ALfwjJ3Zsyg+F/ZHqcfEDsUfKGd0/A1HBYeuB3xag1G/KvNURR 8Het/iqtd9oERLoFTZ80dp6/RrEGPCYP6t+pzXseih+Ck4wzAi uC8Ig4/xnF6g4BTGaLRekE/+BP5KGom4YRlGqHfQSB5AMEr/1W 43tRUUyaGx9ykOFff6A4nm0gVDk/61kpNezq3Z0L6ybZAh3/lX abUhhnSoTFyzrHnLDmkDwgas51QUkfSeykW6hgQi/ei/WoxL/I McYihByAvUMz7v5MHyD45aRkxDV/lnjocnH1DWobsNdTBIkM3g Yxy2OMvhOOSZhbQY0dYXzQsTI5qFQjLhUhnOsxTdPbUGeyrpsM sB13i Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org This commit adds support for instantiating the Tegra PCIe controller from a device tree. Signed-off-by: Thierry Reding --- Changes in v2: - increase compile coverage by using the IS_ENABLED() macro - disable node by default --- .../devicetree/bindings/pci/tegra-pcie.txt | 23 ++++ arch/arm/boot/dts/tegra20.dtsi | 9 ++ arch/arm/mach-tegra/pcie.c | 120 +++++++++++++++++++- 3 files changed, 149 insertions(+), 3 deletions(-) create mode 100644 Documentation/devicetree/bindings/pci/tegra-pcie.txt diff --git a/Documentation/devicetree/bindings/pci/tegra-pcie.txt b/Documentation/devicetree/bindings/pci/tegra-pcie.txt new file mode 100644 index 0000000..10bbc40 --- /dev/null +++ b/Documentation/devicetree/bindings/pci/tegra-pcie.txt @@ -0,0 +1,23 @@ +NVIDIA Tegra PCIe controller + +Required properties: +- compatible: "nvidia,tegra20-pcie" +- reg: physical base address and length of the controller's registers +- interrupts: the interrupt outputs of the controller + +Optional properties: +- pex-clk-supply: supply voltage for internal reference clock +- vdd-supply: power supply for controller (1.05V) + +Example: + + pci@80000000 { + compatible = "nvidia,tegra20-pcie", + reg = <0x80000000 0x400000 /* PCIe AFI registers */ + 0x80400000 0x010000>; /* PCI I/O space */ + interrupts = < 0 98 0x04 /* controller interrupt */ + 0 99 0x04 >; /* MSI interrupt */ + + pex-clk-supply = <&ldo0_reg>; + vdd-supply = <&pcie_reg>; + }; diff --git a/arch/arm/boot/dts/tegra20.dtsi b/arch/arm/boot/dts/tegra20.dtsi index fa56519..b212658 100644 --- a/arch/arm/boot/dts/tegra20.dtsi +++ b/arch/arm/boot/dts/tegra20.dtsi @@ -199,6 +199,15 @@ #size-cells = <0>; }; + pci { + compatible = "nvidia,tegra20-pcie"; + reg = <0x80000000 0x400000 /* PCIe AFI registers */ + 0x80400000 0x010000>; /* PCI I/O space */ + interrupts = < 0 98 0x04 /* controller interrupt */ + 0 99 0x04 >; /* MSI interrupt */ + status = "disable"; + }; + usb@c5000000 { compatible = "nvidia,tegra20-ehci", "usb-ehci"; reg = <0xc5000000 0x4000>; diff --git a/arch/arm/mach-tegra/pcie.c b/arch/arm/mach-tegra/pcie.c index 3c8c953..f24923b 100644 --- a/arch/arm/mach-tegra/pcie.c +++ b/arch/arm/mach-tegra/pcie.c @@ -37,6 +37,8 @@ #include #include #include +#include +#include #include #include @@ -242,6 +244,9 @@ struct tegra_pcie_info { struct clk *pll_e; struct tegra_pcie_msi *msi; + + struct regulator *pex_clk_supply; + struct regulator *vdd_supply; }; static inline struct tegra_pcie_info *sys_to_pcie(struct pci_sys_data *sys) @@ -1194,6 +1199,99 @@ static int tegra_pcie_disable_msi(struct platform_device *pdev) return 0; } +static int tegra_pcie_dt_init(struct platform_device *pdev) +{ + struct tegra_pcie_info *pcie = platform_get_drvdata(pdev); + int err; + + if (!IS_ERR_OR_NULL(pcie->vdd_supply)) { + err = regulator_enable(pcie->vdd_supply); + if (err < 0) { + dev_err(&pdev->dev, + "failed to enable VDD regulator: %d\n", err); + return err; + } + } + + if (!IS_ERR_OR_NULL(pcie->pex_clk_supply)) { + err = regulator_enable(pcie->pex_clk_supply); + if (err < 0) { + dev_err(&pdev->dev, + "failed to enable pex-clk regulator: %d\n", + err); + return err; + } + } + + return 0; +} + +static int tegra_pcie_dt_exit(struct platform_device *pdev) +{ + struct tegra_pcie_info *pcie = platform_get_drvdata(pdev); + int err; + + if (!IS_ERR_OR_NULL(pcie->pex_clk_supply)) { + err = regulator_disable(pcie->pex_clk_supply); + if (err < 0) { + dev_err(&pdev->dev, + "failed to disable pex-clk regulator: %d\n", + err); + return err; + } + } + + if (!IS_ERR_OR_NULL(pcie->vdd_supply)) { + err = regulator_disable(pcie->vdd_supply); + if (err < 0) { + dev_err(&pdev->dev, + "failed to disable VDD regulator: %d\n", err); + return err; + } + } + + return 0; +} + +static struct tegra_pcie_pdata *tegra_pcie_parse_dt(struct platform_device *pdev) +{ + struct tegra_pcie_info *pcie = platform_get_drvdata(pdev); + struct device_node *node = pdev->dev.of_node; + struct tegra_pcie_pdata *pdata; + unsigned int i; + + pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + if (!pdata) + return NULL; + + pdata->init = tegra_pcie_dt_init; + pdata->exit = tegra_pcie_dt_exit; + + if (of_find_property(node, "vdd-supply", NULL)) { + pcie->vdd_supply = regulator_get(&pdev->dev, "vdd"); + if (IS_ERR_OR_NULL(pcie->vdd_supply)) + return ERR_PTR(-EPROBE_DEFER); + } + + if (of_find_property(node, "pex-clk-supply", NULL)) { + pcie->pex_clk_supply = regulator_get(&pdev->dev, "pex-clk"); + if (IS_ERR_OR_NULL(pcie->pex_clk_supply)) + return ERR_PTR(-EPROBE_DEFER); + } + + for (i = 0; i < TEGRA_PCIE_MAX_PORTS; i++) + pdata->enable_ports[i] = true; + + return pdata; +} + +#ifdef CONFIG_OF +static const struct of_device_id tegra_pcie_of_match[] = { + { .compatible = "nvidia,tegra20-pcie", }, + { }, +}; +#endif + static int __devinit tegra_pcie_probe(struct platform_device *pdev) { struct tegra_pcie_pdata *pdata = pdev->dev.platform_data; @@ -1202,9 +1300,6 @@ static int __devinit tegra_pcie_probe(struct platform_device *pdev) struct hw_pci hw; int err; - if (!pdata->enable_ports[0] && !pdata->enable_ports[1]) - return -ENODEV; - pcie = devm_kzalloc(&pdev->dev, sizeof(*pcie), GFP_KERNEL); if (!pcie) return -ENOMEM; @@ -1212,6 +1307,20 @@ static int __devinit tegra_pcie_probe(struct platform_device *pdev) platform_set_drvdata(pdev, pcie); pcie->dev = &pdev->dev; + if (IS_ENABLED(CONFIG_OF)) { + if (!pdata && pdev->dev.of_node) { + pdata = tegra_pcie_parse_dt(pdev); + if (IS_ERR(pdata)) + return PTR_ERR(pdata); + } + } + + if (!pdata) + return -ENODEV; + + if (!pdata->enable_ports[0] && !pdata->enable_ports[1]) + return -ENODEV; + pcibios_min_mem = 0; err = tegra_pcie_get_resources(pdev); @@ -1266,6 +1375,7 @@ static int __devinit tegra_pcie_probe(struct platform_device *pdev) static int __devexit tegra_pcie_remove(struct platform_device *pdev) { + struct tegra_pcie_info *pcie = platform_get_drvdata(pdev); struct tegra_pcie_pdata *pdata = pdev->dev.platform_data; int err; @@ -1285,6 +1395,9 @@ static int __devexit tegra_pcie_remove(struct platform_device *pdev) return err; } + regulator_put(pcie->pex_clk_supply); + regulator_put(pcie->vdd_supply); + return 0; } @@ -1292,6 +1405,7 @@ static struct platform_driver tegra_pcie_driver = { .driver = { .name = "tegra-pcie", .owner = THIS_MODULE, + .of_match_table = of_match_ptr(tegra_pcie_of_match), }, .probe = tegra_pcie_probe, .remove = __devexit_p(tegra_pcie_remove),