mediatek: backport latest pci/e driver from upstream
[openwrt/staging/rmilecki.git] / target / linux / mediatek / patches-5.4 / 0992-PCI-mediatek-Use-regmap-to-get-shared-pcie-cfg-base.patch
1 From patchwork Thu May 28 06:16:46 2020
2 Content-Type: text/plain; charset="utf-8"
3 MIME-Version: 1.0
4 Content-Transfer-Encoding: 7bit
5 X-Patchwork-Submitter: Chuanjia Liu <chuanjia.liu@mediatek.com>
6 X-Patchwork-Id: 11574781
7 Return-Path:
8 <SRS0=ftSA=7K=lists.infradead.org=linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@kernel.org>
9 Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org
10 [172.30.200.123])
11 by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0A99B60D
12 for <patchwork-linux-mediatek@patchwork.kernel.org>;
13 Thu, 28 May 2020 06:19:04 +0000 (UTC)
14 Received: from bombadil.infradead.org (bombadil.infradead.org
15 [198.137.202.133])
16 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
17 (No client certificate requested)
18 by mail.kernel.org (Postfix) with ESMTPS id DCC99208FE
19 for <patchwork-linux-mediatek@patchwork.kernel.org>;
20 Thu, 28 May 2020 06:19:03 +0000 (UTC)
21 Authentication-Results: mail.kernel.org;
22 dkim=pass (2048-bit key) header.d=lists.infradead.org
23 header.i=@lists.infradead.org header.b="SpOi0ueF";
24 dkim=fail reason="signature verification failed" (1024-bit key)
25 header.d=mediatek.com header.i=@mediatek.com header.b="UGIBoIEG"
26 DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DCC99208FE
27 Authentication-Results: mail.kernel.org;
28 dmarc=fail (p=none dis=none) header.from=mediatek.com
29 Authentication-Results: mail.kernel.org;
30 spf=none
31 smtp.mailfrom=linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org
32 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;
33 d=lists.infradead.org; s=bombadil.20170209; h=Sender:
34 Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post:
35 List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:
36 Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description:
37 Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:
38 List-Owner; bh=LIr5poLUT/UdH6/akh/pnICGGa3rUBkN+4FhE1DyOrU=; b=SpOi0ueFcoJ/ka
39 4esa6cDd5oU4fp0z684ZVPaVvvhm/azSZBBMYinHaAW6EvzKcMNYIX9grP8eg/728lEPNTKVq0I8H
40 PQZ9KvD4uTu8Opo1hD8LsRSLr+YLpNKt3KPOY/4gpwQ97uU9rI5PwkuAxPBgR949Vh5EiG0Vaww1H
41 Ep+I5BFRn2LVVQZP1Z7U0A0VUcOTLJ4znoWRLEXxtM9/Wd4hwQsrEPQszeDFti/RbwGfJ5efOb5UL
42 fhwBzSxELEzAAgH7env/XD2sSSpVf2Qsn6WO8D3ZepMtWrRtARiaRKSNxSBQTg2SSHcjmBSJSzcX+
43 w8wqWaUMs0crlBuZWS1g==;
44 Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org)
45 by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux))
46 id 1jeBsc-0001tI-88; Thu, 28 May 2020 06:19:02 +0000
47 Received: from mailgw01.mediatek.com ([216.200.240.184])
48 by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux))
49 id 1jeBsZ-0001rp-6g; Thu, 28 May 2020 06:19:01 +0000
50 X-UUID: beeaf5765357439c91eab1f67ca7ef43-20200527
51 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;
52 d=mediatek.com;
53 s=dk;
54 h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From;
55 bh=+IjWjsF/DhknqZB+lLSZ50cyvxDap+8w4tvqhp8Dv68=;
56 b=UGIBoIEGJUuq5pEvYEad1HVGpiv6yma+94hva83D2gD8lYmihRWkpJxB2yn+dVtNm7ZXXoQBf+jvvULOmslJgs1HZTLJTnjpdvLmQqo42OXRXSVpTE49HdRkJZDAIWIAReBfOEkFgNxcIX3uedrtnww/NLJ2lagrYPG5ET4lI2E=;
57 X-UUID: beeaf5765357439c91eab1f67ca7ef43-20200527
58 Received: from mtkcas68.mediatek.inc [(172.29.94.19)] by mailgw01.mediatek.com
59 (envelope-from <chuanjia.liu@mediatek.com>)
60 (musrelay.mediatek.com ESMTP with TLS)
61 with ESMTP id 603406343; Wed, 27 May 2020 22:19:17 -0800
62 Received: from mtkmbs07n1.mediatek.inc (172.21.101.16) by
63 MTKMBS62DR.mediatek.inc (172.29.94.18) with Microsoft SMTP Server (TLS) id
64 15.0.1497.2; Wed, 27 May 2020 23:18:47 -0700
65 Received: from mtkcas07.mediatek.inc (172.21.101.84) by
66 mtkmbs07n1.mediatek.inc (172.21.101.16) with Microsoft SMTP Server (TLS) id
67 15.0.1497.2; Thu, 28 May 2020 14:18:51 +0800
68 Received: from localhost.localdomain (10.17.3.153) by mtkcas07.mediatek.inc
69 (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend
70 Transport; Thu, 28 May 2020 14:18:49 +0800
71 From: <chuanjia.liu@mediatek.com>
72 To: <robh+dt@kernel.org>, <ryder.lee@mediatek.com>, <matthias.bgg@gmail.com>
73 Subject: [PATCH v2 2/4] PCI: mediatek: Use regmap to get shared pcie-cfg base
74 Date: Thu, 28 May 2020 14:16:46 +0800
75 Message-ID: <20200528061648.32078-3-chuanjia.liu@mediatek.com>
76 X-Mailer: git-send-email 2.18.0
77 In-Reply-To: <20200528061648.32078-1-chuanjia.liu@mediatek.com>
78 References: <20200528061648.32078-1-chuanjia.liu@mediatek.com>
79 MIME-Version: 1.0
80 X-MTK: N
81 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3
82 X-CRM114-CacheID: sfid-20200527_231859_251275_BED2B1E2
83 X-CRM114-Status: GOOD ( 11.62 )
84 X-Spam-Score: -0.2 (/)
85 X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary:
86 Content analysis details: (-0.2 points)
87 pts rule name description
88 ---- ----------------------
89 --------------------------------------------------
90 -0.0 SPF_PASS SPF: sender matches SPF record
91 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record
92 0.0 MIME_BASE64_TEXT RAW: Message text disguised using base64
93 encoding
94 -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from
95 author's domain
96 0.1 DKIM_SIGNED Message has a DKIM or DK signature,
97 not necessarily
98 valid
99 -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature
100 -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from
101 envelope-from domain
102 0.0 UNPARSEABLE_RELAY Informational: message has unparseable relay
103 lines
104 X-BeenThere: linux-mediatek@lists.infradead.org
105 X-Mailman-Version: 2.1.29
106 Precedence: list
107 List-Id: <linux-mediatek.lists.infradead.org>
108 List-Unsubscribe: <http://lists.infradead.org/mailman/options/linux-mediatek>,
109 <mailto:linux-mediatek-request@lists.infradead.org?subject=unsubscribe>
110 List-Archive: <http://lists.infradead.org/pipermail/linux-mediatek/>
111 List-Post: <mailto:linux-mediatek@lists.infradead.org>
112 List-Help: <mailto:linux-mediatek-request@lists.infradead.org?subject=help>
113 List-Subscribe: <http://lists.infradead.org/mailman/listinfo/linux-mediatek>,
114 <mailto:linux-mediatek-request@lists.infradead.org?subject=subscribe>
115 Cc: devicetree@vger.kernel.org, lorenzo.pieralisi@arm.com,
116 srv_heupstream@mediatek.com, "chuanjia.liu" <Chuanjia.Liu@mediatek.com>,
117 linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
118 jianjun.wang@mediatek.com, linux-mediatek@lists.infradead.org,
119 yong.wu@mediatek.com, bhelgaas@google.com,
120 linux-arm-kernel@lists.infradead.org, amurray@thegoodpenguin.co.uk
121 Sender: "Linux-mediatek" <linux-mediatek-bounces@lists.infradead.org>
122 Errors-To:
123 linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org
124
125 From: "chuanjia.liu" <Chuanjia.Liu@mediatek.com>
126
127 Use regmap to get shared pcie-cfg base and change
128 the method to get pcie irq.
129
130 Signed-off-by: chuanjia.liu <Chuanjia.Liu@mediatek.com>
131 ---
132 drivers/pci/controller/pcie-mediatek.c | 25 ++++++++++++++++++-------
133 1 file changed, 18 insertions(+), 7 deletions(-)
134
135 diff --git a/drivers/pci/controller/pcie-mediatek.c b/drivers/pci/controller/pcie-mediatek.c
136 index cb982891b22b..2268d6073eb6 100644
137 --- a/drivers/pci/controller/pcie-mediatek.c
138 +++ b/drivers/pci/controller/pcie-mediatek.c
139 @@ -14,6 +14,7 @@
140 #include <linux/irqchip/chained_irq.h>
141 #include <linux/irqdomain.h>
142 #include <linux/kernel.h>
143 +#include <linux/mfd/syscon.h>
144 #include <linux/msi.h>
145 #include <linux/module.h>
146 #include <linux/of_address.h>
147 @@ -23,6 +24,7 @@
148 #include <linux/phy/phy.h>
149 #include <linux/platform_device.h>
150 #include <linux/pm_runtime.h>
151 +#include <linux/regmap.h>
152 #include <linux/reset.h>
153
154 #include "../pci.h"
155 @@ -205,6 +207,7 @@ struct mtk_pcie_port {
156 * struct mtk_pcie - PCIe host information
157 * @dev: pointer to PCIe device
158 * @base: IO mapped register base
159 + * @cfg: IO mapped register map for PCIe config
160 * @free_ck: free-run reference clock
161 * @mem: non-prefetchable memory resource
162 * @ports: pointer to PCIe port information
163 @@ -214,6 +217,7 @@ struct mtk_pcie_port {
164 struct mtk_pcie {
165 struct device *dev;
166 void __iomem *base;
167 + struct regmap *cfg;
168 struct clk *free_ck;
169
170 struct list_head ports;
171 @@ -650,7 +654,7 @@ static int mtk_pcie_setup_irq(struct mtk_pcie_port *port,
172 return err;
173 }
174
175 - port->irq = platform_get_irq(pdev, port->slot);
176 + port->irq = platform_get_irq_byname(pdev, "pcie_irq");
177 irq_set_chained_handler_and_data(port->irq,
178 mtk_pcie_intr_handler, port);
179
180 @@ -673,12 +677,11 @@ static int mtk_pcie_startup_port_v2(struct mtk_pcie_port *port)
181 if (!mem)
182 return -EINVAL;
183
184 - /* MT7622 platforms need to enable LTSSM and ASPM from PCIe subsys */
185 - if (pcie->base) {
186 - val = readl(pcie->base + PCIE_SYS_CFG_V2);
187 - val |= PCIE_CSR_LTSSM_EN(port->slot) |
188 - PCIE_CSR_ASPM_L1_EN(port->slot);
189 - writel(val, pcie->base + PCIE_SYS_CFG_V2);
190 + /* MT7622/MT7629 platforms need to enable LTSSM and ASPM. */
191 + if (pcie->cfg) {
192 + val = PCIE_CSR_LTSSM_EN(port->slot) |
193 + PCIE_CSR_ASPM_L1_EN(port->slot);
194 + regmap_update_bits(pcie->cfg, PCIE_SYS_CFG_V2, val, val);
195 }
196
197 /* Assert all reset signals */
198 @@ -984,6 +987,7 @@ static int mtk_pcie_subsys_powerup(struct mtk_pcie *pcie)
199 struct device *dev = pcie->dev;
200 struct platform_device *pdev = to_platform_device(dev);
201 struct resource *regs;
202 + struct device_node *cfg_node;
203 int err;
204
205 /* get shared registers, which are optional */
206 @@ -996,6 +1000,13 @@ static int mtk_pcie_subsys_powerup(struct mtk_pcie *pcie)
207 }
208 }
209
210 + cfg_node = of_parse_phandle(dev->of_node, "mediatek,pcie-cfg", 0);
211 + if (cfg_node) {
212 + pcie->cfg = syscon_node_to_regmap(cfg_node);
213 + if (IS_ERR(pcie->cfg))
214 + return PTR_ERR(pcie->cfg);
215 + }
216 +
217 pcie->free_ck = devm_clk_get(dev, "free_ck");
218 if (IS_ERR(pcie->free_ck)) {
219 if (PTR_ERR(pcie->free_ck) == -EPROBE_DEFER)