From patchwork Tue Jan 23 01:04: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: 10179451 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 DC758600F5 for ; Tue, 23 Jan 2018 01:05:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC00022064 for ; Tue, 23 Jan 2018 01:05:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BFF09285A4; Tue, 23 Jan 2018 01:05:02 +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 4255F22064 for ; Tue, 23 Jan 2018 01:05:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751304AbeAWBE7 (ORCPT ); Mon, 22 Jan 2018 20:04:59 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:43232 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751293AbeAWBE6 (ORCPT ); Mon, 22 Jan 2018 20:04:58 -0500 Received: by mail-pg0-f66.google.com with SMTP id n17so8459142pgf.10 for ; Mon, 22 Jan 2018 17:04:58 -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; bh=uBCAP/x0+TDkyIyOWsAh4+jywEPNozMxMND/23Kb53U=; b=h1vOnwlxpuEEoZ7JCrVmap7gekPM/KeLWdvaurTVZ1NTIUnNvlMaxEggamFgWMigFN 0L9eix2QbmNbeBIR4lq+VQXDdv5bQEsw45V2ErIwG3x8QGz8cdeaLQjHIF8Mvy8efH2C 1B7txohI1v8qJl3KNXrwd/jpsW/G8iM5I/shQ= 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; bh=uBCAP/x0+TDkyIyOWsAh4+jywEPNozMxMND/23Kb53U=; b=oJJkjDSiGQ8Gz3sbYT49eGOxt2gH3u+XaM6sMHre0E84EcS5Rh/n2FTjkD1bWLx84E +/wq8j43Oc8S/unCgT3dUibYXYTlNXeKhtXF3tAuMmD9A2ewTVdeLVlx7ACGynw1rv3Z CtC5qb+HikR6+zSlReViF1Zin0VjO/+PJvNL+a9jo8QgszSUkIL9THPOHHcR7W54D6SF bXz5aH9jk6pJyeGszUECWUpp8E70M71KLnA8Co2P17uYAfkxb09o1Gexmk/mFbt6d6dy qeJ4c2xLJyKCY3Zh05CcjvQCqXb/ky6uEm0CmEBMrrge/zaD7852yTTMUzqfdnS2tKXR G5xQ== X-Gm-Message-State: AKwxytdek7gtdL9zCp+zuF0C9Ks4my7E45y6dzUn+OF7gA5PlOIVnyfB cJjBbi/E/f+ebPnErKAfogFENw== X-Google-Smtp-Source: AH8x226kQ6M0Jm90DiGPJ4hLZVczyi+oOp7VvgBus1PhNffp0tRL7oFsrZZnd3tcAnvx0BZhXE5/2Q== X-Received: by 10.101.77.208 with SMTP id q16mr7651706pgt.395.1516669497705; Mon, 22 Jan 2018 17:04:57 -0800 (PST) Received: from localhost.localdomain ([45.56.152.94]) by smtp.gmail.com with ESMTPSA id o20sm19294694pgv.85.2018.01.22.17.04.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 22 Jan 2018 17:04:56 -0800 (PST) From: Shawn Guo To: Bjorn Helgaas Cc: Rob Herring , linux-pci@vger.kernel.org, devicetree@vger.kernel.org, project-aspen-dev@linaro.org, Jianguo Sun , Shawn Guo Subject: [PATCH] PCI: histb: add power control GPIO for PCIe slot Date: Tue, 23 Jan 2018 09:04:37 +0800 Message-Id: <1516669477-20151-1-git-send-email-shawn.guo@linaro.org> X-Mailer: git-send-email 1.9.1 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 From: Jianguo Sun Besides the GPIO for controlling reset, there is also possibly another GPIO for turning on/off the power of PCIe slot. Let's add the support for that with another optional device tree property 'power-gpios'. Signed-off-by: Jianguo Sun Signed-off-by: Shawn Guo --- .../bindings/pci/hisilicon-histb-pcie.txt | 1 + drivers/pci/dwc/pcie-histb.c | 28 +++++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Documentation/devicetree/bindings/pci/hisilicon-histb-pcie.txt b/Documentation/devicetree/bindings/pci/hisilicon-histb-pcie.txt index c84bc027930b..597397a048f8 100644 --- a/Documentation/devicetree/bindings/pci/hisilicon-histb-pcie.txt +++ b/Documentation/devicetree/bindings/pci/hisilicon-histb-pcie.txt @@ -33,6 +33,7 @@ Required properties "bus": bus reset. Optional properties: +- power-gpios: The gpio to control the power of PCIe slot. - reset-gpios: The gpio to generate PCIe PERST# assert and deassert signal. - 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 33b01b734d7d..2a6b18619b25 100644 --- a/drivers/pci/dwc/pcie-histb.c +++ b/drivers/pci/dwc/pcie-histb.c @@ -63,6 +63,7 @@ struct histb_pcie { struct reset_control *sys_reset; struct reset_control *bus_reset; void __iomem *ctrl; + int power_gpio; int reset_gpio; }; @@ -230,6 +231,8 @@ 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 (gpio_is_valid(hipcie->power_gpio)) + gpio_set_value_cansleep(hipcie->power_gpio, 0); } static int histb_pcie_host_enable(struct pcie_port *pp) @@ -240,8 +243,14 @@ static int histb_pcie_host_enable(struct pcie_port *pp) int ret; /* power on PCIe device if have */ - if (gpio_is_valid(hipcie->reset_gpio)) + if (gpio_is_valid(hipcie->power_gpio)) + gpio_set_value_cansleep(hipcie->power_gpio, 1); + + if (gpio_is_valid(hipcie->reset_gpio)) { + gpio_set_value_cansleep(hipcie->reset_gpio, 0); + mdelay(10); gpio_set_value_cansleep(hipcie->reset_gpio, 1); + } ret = clk_prepare_enable(hipcie->bus_clk); if (ret) { @@ -335,15 +344,28 @@ static int histb_pcie_probe(struct platform_device *pdev) return PTR_ERR(pci->dbi_base); } + hipcie->power_gpio = of_get_named_gpio_flags(np, + "power-gpios", 0, &of_flags); + if (of_flags & OF_GPIO_ACTIVE_LOW) + flag |= GPIOF_ACTIVE_LOW; + if (gpio_is_valid(hipcie->power_gpio)) { + ret = devm_gpio_request_one(dev, hipcie->power_gpio, + flag, "PCIe device power control"); + if (ret) { + dev_err(dev, "unable to request power gpio\n"); + return ret; + } + } + hipcie->reset_gpio = of_get_named_gpio_flags(np, "reset-gpios", 0, &of_flags); if (of_flags & OF_GPIO_ACTIVE_LOW) flag |= GPIOF_ACTIVE_LOW; if (gpio_is_valid(hipcie->reset_gpio)) { ret = devm_gpio_request_one(dev, hipcie->reset_gpio, - flag, "PCIe device power control"); + flag, "PCIe device reset control"); if (ret) { - dev_err(dev, "unable to request gpio\n"); + dev_err(dev, "unable to request reset gpio\n"); return ret; } }