From patchwork Fri Mar 2 01:12:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Guo X-Patchwork-Id: 10252995 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 2701C602B5 for ; Fri, 2 Mar 2018 01:12:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 161C8203B9 for ; Fri, 2 Mar 2018 01:12:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0B26F219AC; Fri, 2 Mar 2018 01:12:47 +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 97ADA203B9 for ; Fri, 2 Mar 2018 01:12:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1163387AbeCBBMo (ORCPT ); Thu, 1 Mar 2018 20:12:44 -0500 Received: from mail-pl0-f67.google.com ([209.85.160.67]:43316 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1163354AbeCBBMn (ORCPT ); Thu, 1 Mar 2018 20:12:43 -0500 Received: by mail-pl0-f67.google.com with SMTP id f23-v6so4704705plr.10 for ; Thu, 01 Mar 2018 17:12:43 -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=KNbIZ1J21VEN3dP21fHyUZ8Xc2OpfYBzPaI21LhPJIc=; b=QgE5+yWKcD+VeCmFvIb3S42BarMy+suB0KfMZans224gkGrO+UQfX0iez6nnWClJvQ ri5bje+dZnwpaLrtiNoXKWVZ4/rOEMNZoJD9Mqtq83rADMK0lblRQMnd+SLEMPwkhZFV Fxj2lrLNIaUlteDaCP6rIDZG0mvEm/mkzOhUQ= 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=KNbIZ1J21VEN3dP21fHyUZ8Xc2OpfYBzPaI21LhPJIc=; b=iwvOG8hFF66logLrCTqEwKH93LdCSp+apfjp2OkPLlOQeiEwmioAZ89/9+gQdGIRfK F9fH2juTrCHJ9jiBIxThPLukBx1mJU1ngruHGPOo8QIWX1QLsZuLa1EKpRqq78xKEejW laY8Xwhs5bJDELmQOUGIafAMPqOQDodItRm+PVb/sD4XwwynxNswzcQK+vthdG9vwp/p Y8gH3tFq2ChANnGcYGTftTu2IrfhB/D1clKb13NVLYi2VlmWxzZmuiBRw5BGVI4nXgpt RBG3ES5ZUokJcpJqh+hgpjWEnmBZPRAK0775VpFeDyU7EnjsKRR22PqQQ0GHP2kOY7z4 RHOg== X-Gm-Message-State: APf1xPCTKbEvaAGL/taSRlusGBT9H94AfzvtCU9+doZajTw6d8SwAvqb tOMJgPKQInHEBJIDbExe0vts2Q== X-Google-Smtp-Source: AG47ELv1dW8XkxIaSyGQM2U0a1vxIIJxcDGSL+4N3IRRxJ7dN3KX8qbGVJoOnxLGRX8JQZOB3pYsyg== X-Received: by 2002:a17:902:8d93:: with SMTP id v19-v6mr3593821plo.371.1519953162756; Thu, 01 Mar 2018 17:12:42 -0800 (PST) Received: from localhost.localdomain ([45.56.152.106]) by smtp.gmail.com with ESMTPSA id z22sm2186864pfd.158.2018.03.01.17.12.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Mar 2018 17:12:41 -0800 (PST) From: Shawn Guo To: Lorenzo Pieralisi Cc: Bjorn Helgaas , Rob Herring , Fabio Estevam , Jianguo Sun , Jiancheng Xue , linux-pci@vger.kernel.org, devicetree@vger.kernel.org, Shawn Guo Subject: [PATCH v3 2/2] PCI: histb: Add an optional regulator for PCIe port power control Date: Fri, 2 Mar 2018 09:12:01 +0800 Message-Id: <1519953121-28218-3-git-send-email-shawn.guo@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1519953121-28218-1-git-send-email-shawn.guo@linaro.org> References: <1519953121-28218-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..760b4d740616 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: 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 17ed604f5741..4cef0a514944 100644 --- a/drivers/pci/dwc/pcie-histb.c +++ b/drivers/pci/dwc/pcie-histb.c @@ -61,6 +61,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) @@ -227,6 +228,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) @@ -237,6 +241,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); @@ -282,6 +294,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; } @@ -331,6 +345,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)