From patchwork Tue Jan 23 15:45:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Guo X-Patchwork-Id: 10180607 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 69121601D5 for ; Tue, 23 Jan 2018 15:46:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 442472842A for ; Tue, 23 Jan 2018 15:46:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 371CF287B7; Tue, 23 Jan 2018 15:46:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BFAE32842A for ; Tue, 23 Jan 2018 15:46:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752377AbeAWPqJ (ORCPT ); Tue, 23 Jan 2018 10:46:09 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:34421 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751721AbeAWPqF (ORCPT ); Tue, 23 Jan 2018 10:46:05 -0500 Received: by mail-pg0-f67.google.com with SMTP id r19so549705pgn.1 for ; Tue, 23 Jan 2018 07:46:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=mjM1DSiIUACd4y5QE0/9w5qgYKMlONEy8x+OQOLz/Eo=; b=CbZ1MtFpFHGazrov5CLewu08pJNV4LIR0OexPKPQoNektNqVEmpOrvzogTWtxMQeWV n0ikQrkLf+rus3n5CQ75wS+am8/baycLBAVMgeWcPnjvoudSTUFeTWegq+IXEaf2hcgt qrb8990tRyDeVyYTh/nkAvRCg1xSm5mawZ/Hs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mjM1DSiIUACd4y5QE0/9w5qgYKMlONEy8x+OQOLz/Eo=; b=udltDui1syNKt8qaPg5QsCucZCTW1EE4PuuoF6FxeETkg4mwtI6n/suB2H0FgP27uj fEp6mzrG/DPw1A51rxE7P7aHWPa47iKilCcFSfWEbqaJxHQrY38f57D4r2kpE3hLS6DR sTbkFIfVAgWJGbYMgPjO7/BZhPTAgLSQpB35+J/vxNSFM6wSJxBGypVBtNjtDEYtrzBg xktwLhpB208bZbjWwMD21jM6sTX4xIlwsTQdy78gprdJYbn41AlJ9tl4drWbvocR0tfl mQz78XwDheF1wAE/2Pm2BxPEmd4/fUcWxMS60N7L2yV4RrOZuH2DMLOg/kjoGjqQL8+7 /3rw== X-Gm-Message-State: AKwxytfKYQDAcuB6mHtIky1pUcfcdR2Di/jik/b57MFFTo7umwYvumfk C8QX+Y0oBTnjL/XUqbcunWIqJg== X-Google-Smtp-Source: AH8x226kDbrvYAGmBbPBtCMMC6CJ/ovtGGdLkuxZA7sOg1/CaVffXZnYWI+JBL6OJDEDX19qyO1L/w== X-Received: by 10.98.192.10 with SMTP id x10mr10915767pff.27.1516722364900; Tue, 23 Jan 2018 07:46:04 -0800 (PST) Received: from localhost.localdomain ([45.56.152.94]) by smtp.gmail.com with ESMTPSA id v15sm7229037pfa.68.2018.01.23.07.46.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 23 Jan 2018 07:46:04 -0800 (PST) From: Shawn Guo To: Bjorn Helgaas Cc: Rob Herring , Fabio Estevam , Jianguo Sun , linux-pci@vger.kernel.org, devicetree@vger.kernel.org, project-aspen-dev@linaro.org, Shawn Guo Subject: [PATCH v2 2/2] PCI: histb: add an optional regulator for PCIe port power control Date: Tue, 23 Jan 2018 23:45:37 +0800 Message-Id: <1516722337-1533-3-git-send-email-shawn.guo@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1516722337-1533-1-git-send-email-shawn.guo@linaro.org> References: <1516722337-1533-1-git-send-email-shawn.guo@linaro.org> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The power supply to PCIe port are often controlled by GPIO on some board designs. Let's add an optional regulator which can be backed by GPIO to control the power. Signed-off-by: Shawn Guo Acked-by: Rob Herring --- .../bindings/pci/hisilicon-histb-pcie.txt | 1 + drivers/pci/dwc/pcie-histb.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/Documentation/devicetree/bindings/pci/hisilicon-histb-pcie.txt b/Documentation/devicetree/bindings/pci/hisilicon-histb-pcie.txt index c84bc027930b..f995664e6d7f 100644 --- a/Documentation/devicetree/bindings/pci/hisilicon-histb-pcie.txt +++ b/Documentation/devicetree/bindings/pci/hisilicon-histb-pcie.txt @@ -34,6 +34,7 @@ Required properties Optional properties: - reset-gpios: The gpio to generate PCIe PERST# assert and deassert signal. +- vpcie-supply: Should specify the regulator in charge of PCIe port power. - phys: List of phandle and phy mode specifier, should be 0. - phy-names: Must be "phy". diff --git a/drivers/pci/dwc/pcie-histb.c b/drivers/pci/dwc/pcie-histb.c index 6395394be5b4..8eb3028432b3 100644 --- a/drivers/pci/dwc/pcie-histb.c +++ b/drivers/pci/dwc/pcie-histb.c @@ -64,6 +64,7 @@ struct histb_pcie { struct reset_control *bus_reset; void __iomem *ctrl; int reset_gpio; + struct regulator *vpcie; }; static u32 histb_pcie_readl(struct histb_pcie *histb_pcie, u32 reg) @@ -230,6 +231,9 @@ static void histb_pcie_host_disable(struct histb_pcie *hipcie) if (gpio_is_valid(hipcie->reset_gpio)) gpio_set_value_cansleep(hipcie->reset_gpio, 0); + + if (hipcie->vpcie) + regulator_disable(hipcie->vpcie); } static int histb_pcie_host_enable(struct pcie_port *pp) @@ -240,6 +244,14 @@ static int histb_pcie_host_enable(struct pcie_port *pp) int ret; /* power on PCIe device if have */ + if (hipcie->vpcie) { + ret = regulator_enable(hipcie->vpcie); + if (ret) { + dev_err(dev, "failed to enable regulator: %d\n", ret); + return ret; + } + } + if (gpio_is_valid(hipcie->reset_gpio)) gpio_set_value_cansleep(hipcie->reset_gpio, 1); @@ -285,6 +297,8 @@ static int histb_pcie_host_enable(struct pcie_port *pp) err_sys_clk: clk_disable_unprepare(hipcie->bus_clk); err_bus_clk: + if (hipcie->vpcie) + regulator_disable(hipcie->vpcie); return ret; } @@ -334,6 +348,13 @@ static int histb_pcie_probe(struct platform_device *pdev) return PTR_ERR(pci->dbi_base); } + hipcie->vpcie = devm_regulator_get_optional(dev, "vpcie"); + if (IS_ERR(hipcie->vpcie)) { + if (PTR_ERR(hipcie->vpcie) == -EPROBE_DEFER) + return -EPROBE_DEFER; + hipcie->vpcie = NULL; + } + hipcie->reset_gpio = of_get_named_gpio_flags(np, "reset-gpios", 0, &of_flags); if (of_flags & OF_GPIO_ACTIVE_LOW)