From patchwork Mon Jun 19 09:59:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryder Lee X-Patchwork-Id: 9795717 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 403FE6020B for ; Mon, 19 Jun 2017 10:20:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16AEB27EE2 for ; Mon, 19 Jun 2017 10:20:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0B40F27FA5; Mon, 19 Jun 2017 10:20:33 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 892AF27EE2 for ; Mon, 19 Jun 2017 10:20:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=F4RU+NS5xemCTfeYHwq/EH2zxSR4si+K9h7aCSC1E2Y=; b=NCoAsex9MisfyJ 0jgGAYm0eg1M3isHS+HFDR9hHWPQ/iKnB14nBoRrFg+0KgibaFRK7/w0vy8jc/580SnD8Pkoa5fcI 0I5mh5mXoMb09KalCetuooqSs9Ji8OjIhVCJsN9r5wTHFXkMrNpujx0PAo4FLQ5BxZO01WYh5taQm UkyMcirJaeqtwgRfb0WAvSbVXwNwO0ps2e/wQj3WY1NOVIhH6+t1dJbspXrm4iGZg9/w2zbM5yVx2 xevmdCHZ8kcq4poEaX1gaxC8XT2Az+q4a6G6IlyB2s7ghaTFof3g3xzk2eGi/zXhn1w/tuo9L7FI5 1lwvtUIVvO0MkWirgomQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dMtnL-0004q3-CY; Mon, 19 Jun 2017 10:20:31 +0000 Received: from [210.61.82.184] (helo=mailgw02.mediatek.com) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dMtTw-000232-O3; Mon, 19 Jun 2017 10:00:31 +0000 Received: from mtkcas09.mediatek.inc [(172.21.101.178)] by mailgw02.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 1346174341; Mon, 19 Jun 2017 18:00:04 +0800 Received: from mtkexhb02.mediatek.inc (172.21.101.103) by mtkmbs08n2.mediatek.inc (172.21.101.56) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Mon, 19 Jun 2017 18:00:02 +0800 Received: from mtkslt306.mediatek.inc (10.21.14.136) by mtkexhb02.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1210.3 via Frontend Transport; Mon, 19 Jun 2017 18:00:02 +0800 From: Ryder Lee To: Bjorn Helgaas Subject: [PATCH 2/3] PCI: mediatek: turn off subsys power if no link up detected Date: Mon, 19 Jun 2017 17:59:59 +0800 Message-ID: <1497866400-41844-3-git-send-email-ryder.lee@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1497866400-41844-1-git-send-email-ryder.lee@mediatek.com> References: <1497866400-41844-1-git-send-email-ryder.lee@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170619_030028_944142_CCF43129 X-CRM114-Status: GOOD ( 15.05 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-pci@vger.kernel.org, Ryder Lee , linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP There is no need to keep controller power on if slots are all empty, so a check is added to turn it off. Besides, host controllers may not need PM domain in some SoCs, thus we add dev->pm_domain to check that. Signed-off-by: Ryder Lee --- drivers/pci/host/pcie-mediatek.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/drivers/pci/host/pcie-mediatek.c b/drivers/pci/host/pcie-mediatek.c index 165d82d..d256263 100644 --- a/drivers/pci/host/pcie-mediatek.c +++ b/drivers/pci/host/pcie-mediatek.c @@ -118,6 +118,18 @@ static inline bool mtk_pcie_link_is_up(struct mtk_pcie_port *port) return !!(readl(port->base + PCIE_LINK_STATUS) & PCIE_PORT_LINKUP); } +static void mtk_pcie_subsys_powerdown(struct mtk_pcie *pcie) +{ + struct device *dev = pcie->dev; + + clk_disable_unprepare(pcie->free_ck); + + if (dev->pm_domain) { + pm_runtime_put_sync(dev); + pm_runtime_disable(dev); + } +} + static void mtk_pcie_port_free(struct mtk_pcie_port *port) { struct mtk_pcie *pcie = port->pcie; @@ -130,7 +142,6 @@ static void mtk_pcie_port_free(struct mtk_pcie_port *port) static void mtk_pcie_put_resources(struct mtk_pcie *pcie) { - struct device *dev = pcie->dev; struct mtk_pcie_port *port, *tmp; list_for_each_entry_safe(port, tmp, &pcie->ports, list) { @@ -139,9 +150,7 @@ static void mtk_pcie_put_resources(struct mtk_pcie *pcie) mtk_pcie_port_free(port); } - clk_disable_unprepare(pcie->free_ck); - pm_runtime_put_sync(dev); - pm_runtime_disable(dev); + mtk_pcie_subsys_powerdown(pcie); } static void __iomem *mtk_pcie_map_bus(struct pci_bus *bus, @@ -340,10 +349,10 @@ static int mtk_pcie_subsys_powerup(struct mtk_pcie *pcie) return PTR_ERR(pcie->free_ck); } - pm_runtime_enable(dev); - err = pm_runtime_get_sync(dev); - if (err) - goto err_pm; + if (dev->pm_domain) { + pm_runtime_enable(dev); + pm_runtime_get_sync(dev); + } /* enable top level clock */ err = clk_prepare_enable(pcie->free_ck); @@ -355,9 +364,10 @@ static int mtk_pcie_subsys_powerup(struct mtk_pcie *pcie) return 0; err_free_ck: - pm_runtime_put_sync(dev); -err_pm: - pm_runtime_disable(dev); + if (dev->pm_domain) { + pm_runtime_put_sync(dev); + pm_runtime_disable(dev); + } return err; } @@ -439,6 +449,10 @@ static int mtk_pcie_setup(struct mtk_pcie *pcie) list_for_each_entry_safe(port, tmp, &pcie->ports, list) mtk_pcie_enable_ports(port); + /* power down PCIe subsys if slots are all empty(link down) */ + if (list_empty(&pcie->ports)) + mtk_pcie_subsys_powerdown(pcie); + return 0; } @@ -522,7 +536,9 @@ static int mtk_pcie_probe(struct platform_device *pdev) return 0; put_resources: - mtk_pcie_put_resources(pcie); + if (!list_empty(&pcie->ports)) + mtk_pcie_put_resources(pcie); + return err; }