Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3476044pxv; Mon, 19 Jul 2021 00:37:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJybMDsLlklqo9W7/ahOEBD+OAvQE17ucGYUqrzGTb82zKtBy9dSuyg/GnZ31tNiniTVSOn0 X-Received: by 2002:a05:6402:1d4d:: with SMTP id dz13mr32889132edb.67.1626680276482; Mon, 19 Jul 2021 00:37:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626680276; cv=none; d=google.com; s=arc-20160816; b=Aj29Yv5aY4D/LVidbQNwLlhMUjaWq2ZsQqEgVGLaW8PEpBssCXh4uVvd+zBkBfk5Ob uyJQILY7cYIqXSduGaxaNJxwT53BMgmw27M2se788HKhCFlwjSous1yUH7NdlpE04BpO ZlmGwKVCuybvCkZCBcIthz/h8fcg24HG3Dzi7aD1sonAz8xmV+41HGQM/ODjgkUhZrwU tLQbhq267ohgm1FXbZO1xMB6AKcEDPnhzdIgr3lql7+Do3gRB+Y3mh7OPT4qtiwjxgUp 8BrVUjAZ0+a6Js/QrV0H6R6XurYkvzbJ5Z7LpV7PLp4n2rci+Bii9p4vFYXbTKWw8siB kszw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=43sAE328Lw72LuyCo8TW3cG5dcdi/vlf1DGvVkzWLBQ=; b=IzYUk/qH0WthSzWI2mIbqT9GJ64fUcknuYe7FebtuaAFY1On7wQ9tsIc0E0NchvxNi QHOJugJPu5HaI50rs8sY51r0NhBap178MgYsw3V5ruudZIxanLjdpRewzOEGkKVivWtK Zpj+5GYc1Xm1tPh/WSFS6aYUMVwbppBT8JnDOiurz/AEgEnmfuaPe5zE12nF7jeULvfI 1fGoBQ8NRP60X4wz8H0rvTkujx03+jCqwW+SAaaARsanIT4l02XGTV+YhhZin3YYGCoc z00/N/xw2T7E4pOSOUGinxJAowOcdUuiTSYUMb8qD243T6lAGhZKMU1lVi+kppZCwZG0 aHVA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x9si13026663ejs.90.2021.07.19.00.37.34; Mon, 19 Jul 2021 00:37:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234923AbhGSHjV (ORCPT + 99 others); Mon, 19 Jul 2021 03:39:21 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:51718 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S234932AbhGSHjQ (ORCPT ); Mon, 19 Jul 2021 03:39:16 -0400 X-UUID: 4b35b5eab87a446e8ee2467ad1738dad-20210719 X-UUID: 4b35b5eab87a446e8ee2467ad1738dad-20210719 Received: from mtkexhb02.mediatek.inc [(172.21.101.103)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 686826628; Mon, 19 Jul 2021 15:36:13 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs02n1.mediatek.inc (172.21.101.77) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 19 Jul 2021 15:36:11 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 19 Jul 2021 15:36:10 +0800 From: Chuanjia Liu To: , , , CC: , , , Frank Wunderlich , , , , , , Subject: [PATCH v11 2/4] PCI: mediatek: Add new method to get shared pcie-cfg base address and parse node Date: Mon, 19 Jul 2021 15:34:54 +0800 Message-ID: <20210719073456.28666-3-chuanjia.liu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20210719073456.28666-1-chuanjia.liu@mediatek.com> References: <20210719073456.28666-1-chuanjia.liu@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For the new dts format, add a new method to get shared pcie-cfg base address and parse node. Signed-off-by: Chuanjia Liu Acked-by: Ryder Lee --- drivers/pci/controller/pcie-mediatek.c | 52 +++++++++++++++++++------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/drivers/pci/controller/pcie-mediatek.c b/drivers/pci/controller/pcie-mediatek.c index 25bee693834f..928e0983a900 100644 --- a/drivers/pci/controller/pcie-mediatek.c +++ b/drivers/pci/controller/pcie-mediatek.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -23,6 +24,7 @@ #include #include #include +#include #include #include "../pci.h" @@ -207,6 +209,7 @@ struct mtk_pcie_port { * struct mtk_pcie - PCIe host information * @dev: pointer to PCIe device * @base: IO mapped register base + * @cfg: IO mapped register map for PCIe config * @free_ck: free-run reference clock * @mem: non-prefetchable memory resource * @ports: pointer to PCIe port information @@ -215,6 +218,7 @@ struct mtk_pcie_port { struct mtk_pcie { struct device *dev; void __iomem *base; + struct regmap *cfg; struct clk *free_ck; struct list_head ports; @@ -650,7 +654,11 @@ static int mtk_pcie_setup_irq(struct mtk_pcie_port *port, return err; } - port->irq = platform_get_irq(pdev, port->slot); + if (of_find_property(dev->of_node, "interrupt-names", NULL)) + port->irq = platform_get_irq_byname(pdev, "pcie_irq"); + else + port->irq = platform_get_irq(pdev, port->slot); + if (port->irq < 0) return port->irq; @@ -682,6 +690,10 @@ static int mtk_pcie_startup_port_v2(struct mtk_pcie_port *port) val |= PCIE_CSR_LTSSM_EN(port->slot) | PCIE_CSR_ASPM_L1_EN(port->slot); writel(val, pcie->base + PCIE_SYS_CFG_V2); + } else if (pcie->cfg) { + val = PCIE_CSR_LTSSM_EN(port->slot) | + PCIE_CSR_ASPM_L1_EN(port->slot); + regmap_update_bits(pcie->cfg, PCIE_SYS_CFG_V2, val, val); } /* Assert all reset signals */ @@ -985,6 +997,7 @@ static int mtk_pcie_subsys_powerup(struct mtk_pcie *pcie) struct device *dev = pcie->dev; struct platform_device *pdev = to_platform_device(dev); struct resource *regs; + struct device_node *cfg_node; int err; /* get shared registers, which are optional */ @@ -995,6 +1008,14 @@ static int mtk_pcie_subsys_powerup(struct mtk_pcie *pcie) return PTR_ERR(pcie->base); } + cfg_node = of_find_compatible_node(NULL, NULL, + "mediatek,generic-pciecfg"); + if (cfg_node) { + pcie->cfg = syscon_node_to_regmap(cfg_node); + if (IS_ERR(pcie->cfg)) + return PTR_ERR(pcie->cfg); + } + pcie->free_ck = devm_clk_get(dev, "free_ck"); if (IS_ERR(pcie->free_ck)) { if (PTR_ERR(pcie->free_ck) == -EPROBE_DEFER) @@ -1027,22 +1048,27 @@ static int mtk_pcie_setup(struct mtk_pcie *pcie) struct device *dev = pcie->dev; struct device_node *node = dev->of_node, *child; struct mtk_pcie_port *port, *tmp; - int err; + int err, slot; + + slot = of_get_pci_domain_nr(dev->of_node); + if (slot < 0) { + for_each_available_child_of_node(node, child) { + err = of_pci_get_devfn(child); + if (err < 0) { + dev_err(dev, "failed to get devfn: %d\n", err); + goto error_put_node; + } - for_each_available_child_of_node(node, child) { - int slot; + slot = PCI_SLOT(err); - err = of_pci_get_devfn(child); - if (err < 0) { - dev_err(dev, "failed to parse devfn: %d\n", err); - goto error_put_node; + err = mtk_pcie_parse_port(pcie, child, slot); + if (err) + goto error_put_node; } - - slot = PCI_SLOT(err); - - err = mtk_pcie_parse_port(pcie, child, slot); + } else { + err = mtk_pcie_parse_port(pcie, node, slot); if (err) - goto error_put_node; + return err; } err = mtk_pcie_subsys_powerup(pcie); -- 2.18.0