From patchwork Mon Jun 19 09:59:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryder Lee X-Patchwork-Id: 9795669 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 7C177600C5 for ; Mon, 19 Jun 2017 10:06:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 67FB51FF2D for ; Mon, 19 Jun 2017 10:06:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5BC3E20410; Mon, 19 Jun 2017 10:06:01 +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 EE3E71FF2D for ; Mon, 19 Jun 2017 10:06:00 +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=Xx7P6JeW4F/Xu0iT22WaYYP1LY/a3ACdBilTRnO+CPc=; b=TtPgNfQDhbNE9b zfh4fO/2O9BHm03rovvWGFlrKkhaM02eIKqWBK8FWyJqkzmEUv5nb8H70Pmqnzb+dlJ3IR+sdtmHb 1pTQk5P4l0CByqjsKf8QzpHpei1Y7Dom2EOmNkgJ2L/4qmcCqOWnN1cgwtA1I8JOAxBeIpqo8Tvn0 PXihm/LLfwi4F09X0XeEtcqHFzwi5JZTap/4Q9wkryrArcLxq36rcZuVUjH81mn14m3ZPvnLVG4gz 65MC6eo6tYcDqd29dgIiAyvqjYL4aolIPeOQZXjEXfH0Kw1pEwZ2pjj0HZh2ze6QhN490DqCSMkkC 1MdCcbOwEyg2sXrXx5vA==; 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 1dMtZ3-0004iI-T0; Mon, 19 Jun 2017 10:05:45 +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-00022v-PG; Mon, 19 Jun 2017 10:00:32 +0000 Received: from mtkexhb02.mediatek.inc [(172.21.101.103)] by mailgw02.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 363289332; Mon, 19 Jun 2017 18:00:03 +0800 Received: from mtkexhb02.mediatek.inc (172.21.101.103) by mtkmbs08n1.mediatek.inc (172.21.101.55) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Mon, 19 Jun 2017 18:00:01 +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:01 +0800 From: Ryder Lee To: Bjorn Helgaas Subject: [PATCH 1/3] PCI: mediatek: modify controller powerup logic Date: Mon, 19 Jun 2017 17:59:58 +0800 Message-ID: <1497866400-41844-2-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_030029_135655_62BE7265 X-CRM114-Status: GOOD ( 17.06 ) 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 The current powerup logic may lead to unbalanced pm_runtime_enable() if the earlier probe failed due to -EPROBE_DEFER. Hence we do a little flow adjustment to avoid that: Parse standard PCI resources firstly, then check properties for each port, power on controller finally. Also, this patch removes unused registers and renames funtions properly. Signed-off-by: Ryder Lee --- drivers/pci/host/pcie-mediatek.c | 51 +++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/drivers/pci/host/pcie-mediatek.c b/drivers/pci/host/pcie-mediatek.c index 3baafa8..165d82d 100644 --- a/drivers/pci/host/pcie-mediatek.c +++ b/drivers/pci/host/pcie-mediatek.c @@ -34,8 +34,6 @@ /* PCIe per port registers */ #define PCIE_BAR0_SETUP 0x10 -#define PCIE_BAR1_SETUP 0x14 -#define PCIE_BAR0_MEM_BASE 0x18 #define PCIE_CLASS 0x34 #define PCIE_LINK_STATUS 0x50 @@ -224,7 +222,7 @@ static void mtk_pcie_assert_ports(struct mtk_pcie_port *port) msleep(100); } -static int mtk_pcie_enable_ports(struct mtk_pcie_port *port) +static void mtk_pcie_enable_ports(struct mtk_pcie_port *port) { struct device *dev = port->pcie->dev; int err; @@ -249,7 +247,7 @@ static int mtk_pcie_enable_ports(struct mtk_pcie_port *port) /* if link up, then setup root port configuration space */ if (mtk_pcie_link_is_up(port)) { mtk_pcie_configure_rc(port); - return 0; + return; } dev_info(dev, "Port%d link down\n", port->index); @@ -257,13 +255,13 @@ static int mtk_pcie_enable_ports(struct mtk_pcie_port *port) phy_power_off(port->phy); err_phy_on: clk_disable_unprepare(port->sys_ck); - mtk_pcie_port_free(port); err_sys_clk: - return err; + mtk_pcie_port_free(port); + + return; } static int mtk_pcie_parse_ports(struct mtk_pcie *pcie, - struct mtk_pcie_port **p, struct device_node *node, int index) { @@ -274,12 +272,10 @@ static int mtk_pcie_parse_ports(struct mtk_pcie *pcie, char name[10]; int err; - *p = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL); - if (!*p) + port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL); + if (!port) return -ENOMEM; - port = *p; - err = of_property_read_u32(node, "num-lanes", &port->lane); if (err) { dev_err(dev, "missing num-lanes property\n"); @@ -323,7 +319,7 @@ static int mtk_pcie_parse_ports(struct mtk_pcie *pcie, return 0; } -static int mtk_pcie_handle_shared_resource(struct mtk_pcie *pcie) +static int mtk_pcie_subsys_powerup(struct mtk_pcie *pcie) { struct device *dev = pcie->dev; struct platform_device *pdev = to_platform_device(dev); @@ -366,20 +362,16 @@ static int mtk_pcie_handle_shared_resource(struct mtk_pcie *pcie) return err; } -static int mtk_pcie_parse_and_add_res(struct mtk_pcie *pcie) +static int mtk_pcie_setup(struct mtk_pcie *pcie) { struct device *dev = pcie->dev; struct device_node *node = dev->of_node, *child; struct of_pci_range_parser parser; struct of_pci_range range; struct resource res; + struct mtk_pcie_port *port, *tmp; int err; - /* parse shared resources */ - err = mtk_pcie_handle_shared_resource(pcie); - if (err) - return err; - if (of_pci_range_parser_init(&parser, node)) { dev_err(dev, "missing \"ranges\" property\n"); return -EINVAL; @@ -423,8 +415,7 @@ static int mtk_pcie_parse_and_add_res(struct mtk_pcie *pcie) pcie->busn.flags = IORESOURCE_BUS; } - for_each_child_of_node(node, child) { - struct mtk_pcie_port *port; + for_each_available_child_of_node(node, child) { int index; err = of_pci_get_devfn(child); @@ -435,19 +426,19 @@ static int mtk_pcie_parse_and_add_res(struct mtk_pcie *pcie) index = PCI_SLOT(err); - if (!of_device_is_available(child)) - continue; - - err = mtk_pcie_parse_ports(pcie, &port, child, index); - if (err) - return err; - - /* enable each port, and then check link status */ - err = mtk_pcie_enable_ports(port); + err = mtk_pcie_parse_ports(pcie, child, index); if (err) return err; } + err = mtk_pcie_subsys_powerup(pcie); + if (err) + return err; + + /* enable each port, and then check link status */ + list_for_each_entry_safe(port, tmp, &pcie->ports, list) + mtk_pcie_enable_ports(port); + return 0; } @@ -516,7 +507,7 @@ static int mtk_pcie_probe(struct platform_device *pdev) platform_set_drvdata(pdev, pcie); INIT_LIST_HEAD(&pcie->ports); - err = mtk_pcie_parse_and_add_res(pcie); + err = mtk_pcie_setup(pcie); if (err) return err;