Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp352590imu; Wed, 7 Nov 2018 18:57:52 -0800 (PST) X-Google-Smtp-Source: AJdET5fxXK+AFKFJ2shCnZQsD1Cl2bMuPflGnAufDZ2G/dhQ/ohz7v+n3D++uH/2HhSKvBoeUPFa X-Received: by 2002:a17:902:f097:: with SMTP id go23mr2766030plb.328.1541645872627; Wed, 07 Nov 2018 18:57:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541645872; cv=none; d=google.com; s=arc-20160816; b=eH8V+IAQde8ei66I6OWxBv6cSzRBk3/Q7MXyHSLQvdyyIPyumt1JemAjxlSel7Uo7u nYGP4/qbiMA2pzF32w7Oj8e5gTGCjlaeLLVtYHNNoeTwvdTcfH99ghSBi4qOSDFL/ofW W35aQ+o6QESs+7nK+NBngKe/2DlOrdwXJFJ6jopqxeBcu8zSujsJCQ1P2578unDn+Odq t9OoEWrUNL9TxUx0jpdauFpX9SxlrOx0R8GzW7wI+KlvjvFQlD1jMbJLHjYMPy62g+5o GEh07UXh8BTrcq+MV9AMEN4GHHb2HG1uqCTQ59qYF7DjHe63zhxqs1PIYo1zgAHtQPIv 3lbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=UzeQiHanwtd8sYg+XwswRHotw2CQ5Lha8A4zF4lxHgA=; b=D9rJXKItQFLHNAwOoSGaOCt+R75j1o06bO2RKM8/0WPhtqkbqv2vNITsY06ypRChMI S7yqDI0ej7Agmpx6mwQM35WEQMPB/WIya5J0Gq2DCMqmL8LdElF+soHu79Bdw8MedXYl pG8FwD1SIgAHz0dVv935VOx5j/OitcJp2iCNJoaVeaejmy5t0a1ftCzxqRfP1KBMr2wM wBiuWN+RQLLyjhWSkZA7Qn3xHCQAbgbuapggMsE5RXpFi+8yhbFrGg5KJ1t3zzgXdbDy 4PpiD9v/vDWnj3lmDcLvK3AUZBq92KwiA+zi25+Bi6vXo+hsXeQMtM1XvnowQkm9WBvA y1Yw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 101-v6si2899384pld.398.2018.11.07.18.57.36; Wed, 07 Nov 2018 18:57:52 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728653AbeKHMaW (ORCPT + 99 others); Thu, 8 Nov 2018 07:30:22 -0500 Received: from mailgw02.mediatek.com ([210.61.82.184]:33378 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726726AbeKHMaW (ORCPT ); Thu, 8 Nov 2018 07:30:22 -0500 X-UUID: 357e8821132a482f821320a5868d0e12-20181108 X-UUID: 357e8821132a482f821320a5868d0e12-20181108 Received: from mtkexhb02.mediatek.inc [(172.21.101.103)] by mailgw02.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 370850293; Thu, 08 Nov 2018 10:56:59 +0800 Received: from mtkcas08.mediatek.inc (172.21.101.126) by mtkmbs08n1.mediatek.inc (172.21.101.55) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Thu, 8 Nov 2018 10:56:58 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas08.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Thu, 8 Nov 2018 10:56:57 +0800 From: To: , , , , , , CC: , , , Subject: [PATCH v2] PCI: mediatek: Use devm_of_pci_get_host_bridge_resources() to parse DT Date: Thu, 8 Nov 2018 10:56:55 +0800 Message-ID: <1541645815-30340-1-git-send-email-honghui.zhang@mediatek.com> X-Mailer: git-send-email 2.6.4 MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Honghui Zhang Use the devm_of_pci_get_host_bridge_resources() API in place of the PCI OF DT parser. Signed-off-by: Honghui Zhang --- drivers/pci/controller/pcie-mediatek.c | 98 +++++++++------------------------- 1 file changed, 24 insertions(+), 74 deletions(-) diff --git a/drivers/pci/controller/pcie-mediatek.c b/drivers/pci/controller/pcie-mediatek.c index 2a1f97c..0590a93 100644 --- a/drivers/pci/controller/pcie-mediatek.c +++ b/drivers/pci/controller/pcie-mediatek.c @@ -197,11 +197,7 @@ struct mtk_pcie_port { * @dev: pointer to PCIe device * @base: IO mapped register base * @free_ck: free-run reference clock - * @io: IO resource - * @pio: PIO resource * @mem: non-prefetchable memory resource - * @busn: bus range - * @offset: IO / Memory offset * @ports: pointer to PCIe port information * @soc: pointer to SoC-dependent operations */ @@ -210,14 +206,7 @@ struct mtk_pcie { void __iomem *base; struct clk *free_ck; - struct resource io; - struct resource pio; struct resource mem; - struct resource busn; - struct { - resource_size_t mem; - resource_size_t io; - } offset; struct list_head ports; const struct mtk_pcie_soc *soc; }; @@ -1045,55 +1034,43 @@ 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; + struct pci_host_bridge *host = pci_host_bridge_from_priv(pcie); + struct list_head *windows = &host->windows; + struct resource_entry *win, *tmp_win; + resource_size_t io_base; int err; - if (of_pci_range_parser_init(&parser, node)) { - dev_err(dev, "missing \"ranges\" property\n"); - return -EINVAL; - } + err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, + windows, &io_base); + if (err) + return err; - for_each_of_pci_range(&parser, &range) { - err = of_pci_range_to_resource(&range, node, &res); - if (err < 0) - return err; + err = devm_request_pci_bus_resources(dev, windows); + if (err < 0) + return err; - switch (res.flags & IORESOURCE_TYPE_BITS) { + /* Get the I/O and memory ranges from DT */ + resource_list_for_each_entry_safe(win, tmp_win, windows) { + switch (resource_type(win->res)) { case IORESOURCE_IO: - pcie->offset.io = res.start - range.pci_addr; - - memcpy(&pcie->pio, &res, sizeof(res)); - pcie->pio.name = node->full_name; - - pcie->io.start = range.cpu_addr; - pcie->io.end = range.cpu_addr + range.size - 1; - pcie->io.flags = IORESOURCE_MEM; - pcie->io.name = "I/O"; - - memcpy(&res, &pcie->io, sizeof(res)); + err = devm_pci_remap_iospace(dev, win->res, io_base); + if (err) { + dev_warn(dev, "error %d: failed to map resource %pR\n", + err, win->res); + resource_list_destroy_entry(win); + } break; - case IORESOURCE_MEM: - pcie->offset.mem = res.start - range.pci_addr; - - memcpy(&pcie->mem, &res, sizeof(res)); + memcpy(&pcie->mem, win->res, sizeof(*win->res)); pcie->mem.name = "non-prefetchable"; break; + case IORESOURCE_BUS: + host->busnr = win->res->start; + break; } } - err = of_pci_parse_bus_range(node, &pcie->busn); - if (err < 0) { - dev_err(dev, "failed to parse bus ranges property: %d\n", err); - pcie->busn.name = node->name; - pcie->busn.start = 0; - pcie->busn.end = 0xff; - pcie->busn.flags = IORESOURCE_BUS; - } - for_each_available_child_of_node(node, child) { int slot; @@ -1125,28 +1102,6 @@ static int mtk_pcie_setup(struct mtk_pcie *pcie) return 0; } -static int mtk_pcie_request_resources(struct mtk_pcie *pcie) -{ - struct pci_host_bridge *host = pci_host_bridge_from_priv(pcie); - struct list_head *windows = &host->windows; - struct device *dev = pcie->dev; - int err; - - pci_add_resource_offset(windows, &pcie->pio, pcie->offset.io); - pci_add_resource_offset(windows, &pcie->mem, pcie->offset.mem); - pci_add_resource(windows, &pcie->busn); - - err = devm_request_pci_bus_resources(dev, windows); - if (err < 0) - return err; - - err = devm_pci_remap_iospace(dev, &pcie->pio, pcie->io.start); - if (err < 0) - return err; - - return 0; -} - static int mtk_pcie_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -1169,11 +1124,6 @@ static int mtk_pcie_probe(struct platform_device *pdev) if (err) return err; - err = mtk_pcie_request_resources(pcie); - if (err) - goto put_resources; - - host->busnr = pcie->busn.start; host->dev.parent = pcie->dev; host->ops = pcie->soc->ops; host->map_irq = of_irq_parse_and_map_pci; -- 2.6.4