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: 9795655 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 C6AC460381 for ; Mon, 19 Jun 2017 10:00:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D272226D08 for ; Mon, 19 Jun 2017 10:00:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C73BA27F91; Mon, 19 Jun 2017 10:00:45 +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 7809826D08 for ; Mon, 19 Jun 2017 10:00:45 +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=4Fgd8SkJ2kCDGgWfTEiiMLfaj1Ze1mXho86uDdSFGGM=; b=UgmFmD9EnXW9Ad ljDfx+de6/UUv1vYEtnzqRuoy6IGUXCoG5GA99jkIEX9/HZaOL5rvu24l+Wd2UNWQXgUyGKFHYXXX Qer17VBDBh5pLYLWUUJgUCHUEBdr2FyeXOUZznYIoVzTp8XFpy7KX+1xQxGc4azHSXzSE0us9Zzz+ JMberAGSz0hQWmgjT2BK3QiD+wRyFDp7e1b/+WbqzRbGWSGmmAMxhsJstL/S1FZGweD1uwFRRKTYE TXDg5pkZlvACXWn6dme5AygL7bRi/jycWuFD9Jrulak4GTuOCb7Pw6H7vsa5jafHrDuW3Mx2kRd86 W6JscR5TdoNpNc39V4yg==; 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 1dMtUC-0002OX-Or; Mon, 19 Jun 2017 10:00:44 +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-mediatek@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-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=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;