From patchwork Thu Jun 8 08:07:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Schulz X-Patchwork-Id: 103342 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp2323282qgd; Thu, 8 Jun 2017 01:08:01 -0700 (PDT) X-Received: by 10.98.218.25 with SMTP id c25mr28959941pfh.118.1496909281318; Thu, 08 Jun 2017 01:08:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496909281; cv=none; d=google.com; s=arc-20160816; b=rPBAbT/eVDQlCW92aOD6qtmjITCBo01iySHLV5ySb2pea8E0ZbTt+vI1yn3lqSadv3 nvgLGY1IcD3sALYKk5RewfYhehqDDfr1XW2498KXxzlEnNjiu8iBB7nTdEb5oEmq/ReP YMr8JfKeamXjhjrn8w/8AKadZ8isZ80O9Tu9uOc6iQdNR7m6O6H0out1XQSwamYOYfcQ ltoDJKTlEh2rUpZwunmr8AMqKPpaevZQXIcVHVwgCHjyY4+DHc/SIIUjU5ShS7L9Unjr 2ZBr/ppKlZv72END6XF8jZbSWxSersBQtBEpl/QtAEU79zBmFgM0WSBZqCJTamo9bGLC 1uvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=58tdehuZCZPnBfbMnDA9C6ZX2ugteDrOESNeeG8/bM4=; b=WAeFKkzbkH2Z37H71xhep578ALU9j1GMnemBZderLbuu53tFw2Fx7CgC3izDl9bHbq h55UcTnP46fcTzhGl7sLjwXxhgdcWedQDCyjQQoWPrF0SjD9l7WxKSUvgX06qvS99XhX p3Uhv4iNo1lU4GSyAcS9ruaDUzt/egv0ag9aiSLXy0k2W9fPHEdjN30j1/sx53UEyRcL 91l95fpEgzQc+Cg3ibIUz7/Lmn9ZnSTc5kuZ5znnuadVNmpDUgGvYE8IhnAWMqBEvp8Y 3fhXFhXl/oNBpGUCyHGzajlkoUpG+cm8O44RPXT7R3OPQNrVIbZBblWQczVhU7XDThp4 uyuA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 59si3741039plb.446.2017.06.08.01.08.01; Thu, 08 Jun 2017 01:08:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751393AbdFHIIA (ORCPT + 7 others); Thu, 8 Jun 2017 04:08:00 -0400 Received: from mail.free-electrons.com ([62.4.15.54]:45912 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751454AbdFHIH6 (ORCPT ); Thu, 8 Jun 2017 04:07:58 -0400 Received: by mail.free-electrons.com (Postfix, from userid 110) id 95DE320F38; Thu, 8 Jun 2017 10:07:56 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost.localdomain (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.free-electrons.com (Postfix) with ESMTPSA id 53E9320823; Thu, 8 Jun 2017 10:07:46 +0200 (CEST) From: Quentin Schulz To: hongxing.zhu@nxp.com, l.stach@pengutronix.de, bhelgaas@google.com, robh+dt@kernel.org, mark.rutland@arm.com Cc: Quentin Schulz , linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@free-electrons.com Subject: [PATCH] PCI: imx6: add regulator support Date: Thu, 8 Jun 2017 10:07:42 +0200 Message-Id: <20170608080742.3910-1-quentin.schulz@free-electrons.com> X-Mailer: git-send-email 2.11.0 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Some boards might require to control a regulator to power the PCIe port. This adds support for an optional regulator defined in Device Tree linked in the PCIe controller under `vpcie-supply`. If present, the regulator will be disabled and then enabled as part of the PCIe host initialization process and will be disabled when shutting down. Signed-off-by: Quentin Schulz --- .../devicetree/bindings/pci/fsl,imx6q-pcie.txt | 4 +++ drivers/pci/dwc/pci-imx6.c | 34 +++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) -- 2.11.0 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Acked-by: Richard Zhu diff --git a/Documentation/devicetree/bindings/pci/fsl,imx6q-pcie.txt b/Documentation/devicetree/bindings/pci/fsl,imx6q-pcie.txt index e3d5680875b1..cf92d3ba5a26 100644 --- a/Documentation/devicetree/bindings/pci/fsl,imx6q-pcie.txt +++ b/Documentation/devicetree/bindings/pci/fsl,imx6q-pcie.txt @@ -33,6 +33,10 @@ Optional properties: - reset-gpio-active-high: If present then the reset sequence using the GPIO specified in the "reset-gpio" property is reversed (H=reset state, L=operation state). +- vpcie-supply: Should specify the regulator in charge of PCIe port power. + The regulator will be enabled when initializing the PCIe host and + disabled either as part of the init process or when shutting down the + host. Additional required properties for imx6sx-pcie: - clock names: Must include the following additional entries: diff --git a/drivers/pci/dwc/pci-imx6.c b/drivers/pci/dwc/pci-imx6.c index 19a289b8cc94..f9b7500c9aff 100644 --- a/drivers/pci/dwc/pci-imx6.c +++ b/drivers/pci/dwc/pci-imx6.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -59,6 +60,7 @@ struct imx6_pcie { u32 tx_swing_full; u32 tx_swing_low; int link_gen; + struct regulator *vpcie; }; /* Parameters for the waiting for PCIe PHY PLL to lock on i.MX7 */ @@ -310,6 +312,13 @@ static void imx6_pcie_assert_core_reset(struct imx6_pcie *imx6_pcie) IMX6Q_GPR1_PCIE_REF_CLK_EN, 0 << 16); break; } + + if (imx6_pcie->vpcie && regulator_is_enabled(imx6_pcie->vpcie) > 0) { + int ret = regulator_disable(imx6_pcie->vpcie); + + if (ret) + pr_err("failed to disable vpcie regulator: %d\n", ret); + } } static int imx6_pcie_enable_ref_clk(struct imx6_pcie *imx6_pcie) @@ -376,10 +385,19 @@ static void imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie) struct device *dev = pci->dev; int ret; + if (imx6_pcie->vpcie && !regulator_is_enabled(imx6_pcie->vpcie)) { + ret = regulator_enable(imx6_pcie->vpcie); + if (ret) { + dev_err(dev, "failed to enable vpcie regulator: %d\n", + ret); + return; + } + } + ret = clk_prepare_enable(imx6_pcie->pcie_phy); if (ret) { dev_err(dev, "unable to enable pcie_phy clock\n"); - return; + goto err_pcie_phy; } ret = clk_prepare_enable(imx6_pcie->pcie_bus); @@ -439,6 +457,13 @@ static void imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie) clk_disable_unprepare(imx6_pcie->pcie_bus); err_pcie_bus: clk_disable_unprepare(imx6_pcie->pcie_phy); +err_pcie_phy: + if (imx6_pcie->vpcie && regulator_is_enabled(imx6_pcie->vpcie) > 0) { + ret = regulator_disable(imx6_pcie->vpcie); + if (ret) + dev_err(dev, "failed to disable vpcie regulator: %d\n", + ret); + } } static void imx6_pcie_init_phy(struct imx6_pcie *imx6_pcie) @@ -802,6 +827,13 @@ static int imx6_pcie_probe(struct platform_device *pdev) if (ret) imx6_pcie->link_gen = 1; + imx6_pcie->vpcie = devm_regulator_get_optional(&pdev->dev, "vpcie"); + if (IS_ERR(imx6_pcie->vpcie)) { + if (PTR_ERR(imx6_pcie->vpcie) == -EPROBE_DEFER) + return -EPROBE_DEFER; + imx6_pcie->vpcie = NULL; + } + platform_set_drvdata(pdev, imx6_pcie); ret = imx6_add_pcie_port(imx6_pcie, pdev);