From patchwork Fri Jun 21 14:48:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 13707735 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BA5B5C2BBCA for ; Fri, 21 Jun 2024 14:49:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=qcgRT6J7wC414Y9vh8O8T/2Y7BfPzj9BpWBdf/k3LDQ=; b=OyNAyJLe+FiuYE7tIZOwo07O/D gn5/JeANpeRrYzwxnGt4mIVnMtfMTb3unde2ziLKOFYWgyWcz1TD1WAXJ7qjYpNTCiQ3i2FK4KgtV OMkVhiVsi3TXPTj01URyAsqNZT7R24PxrpYtaHw+Wom82WR+zO7PSxXdPqZB1c/0T9z6Tw2nLhuYu N+5/uMpQ8jlCS3y1C/6oWnHkko3yHTkZkkpholpCzmNgrKMrEO9nqpK7dBHCEJTogkddHYvcA/na6 /GZ550i4B/Joa9IPNznKKBmcQHVXMQELePkPPGFlW9g/gBUqgjTv9XgwuF6OFER1mISfwwEgyAYKT acpqXWfg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKfZx-00000009aSc-0xx6; Fri, 21 Jun 2024 14:49:29 +0000 Received: from sin.source.kernel.org ([2604:1380:40e1:4800::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKfZn-00000009aNZ-3Dx6; Fri, 21 Jun 2024 14:49:21 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 48939CE2DCA; Fri, 21 Jun 2024 14:49:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3BF17C2BBFC; Fri, 21 Jun 2024 14:49:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718981356; bh=u2HF2BfpyUNmuOCq2K29l3mxTzrcir390lZ7LUajRi4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qd9uhgLdRfFD1KPKC+duj+/haw+NcpLoZteMIPEgJKfbZMPIO8yV0/LnKPMzlptrw R4rHee8GSY/j7VAd0k+LRl7OiKFyHQxqWVW7ytug1jXadzyFYkVpKvT3xxz9KqNGJV 6uy16QZIO7kuqqU+43GKA/DKvb7vqf3vcy0txtKoqPdPciakFA52oiyr1JsKQL/GwO YWhzMOsOjUE/ozZYcbpz96x0yOxTg5RQPCOZwoaUxqmRO695/LowRY5jJx2ap3XMSk kE63Mg70vEGp4H8hYOtp1cKm09u6l4vtUhz4e0+Zwr2yfMNCLLHliiDwLLyHQdcEWj Z7U60X42FwZtA== From: Lorenzo Bianconi To: linux-pci@vger.kernel.org Cc: ryder.lee@mediatek.com, lpieralisi@kernel.org, kw@linux.com, robh@kernel.org, bhelgaas@google.com, linux-mediatek@lists.infradead.org, lorenzo.bianconi83@gmail.com, linux-arm-kernel@lists.infradead.org, krzysztof.kozlowski+dt@linaro.org, devicetree@vger.kernel.org, nbd@nbd.name, dd@embedd.com, upstream@airoha.com, angelogioacchino.delregno@collabora.com Subject: [PATCH 1/4] dt-bindings: PCI: mediatek-gen3: add support for Airoha EN7581 Date: Fri, 21 Jun 2024 16:48:47 +0200 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240621_074920_089942_8315FF71 X-CRM114-Status: UNSURE ( 8.27 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Introduce Airoha EN7581 entry in mediatek-gen3 PCIe controller binding Signed-off-by: Lorenzo Bianconi --- .../bindings/pci/mediatek-pcie-gen3.yaml | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/Documentation/devicetree/bindings/pci/mediatek-pcie-gen3.yaml b/Documentation/devicetree/bindings/pci/mediatek-pcie-gen3.yaml index 76d742051f73..0f35cf49de63 100644 --- a/Documentation/devicetree/bindings/pci/mediatek-pcie-gen3.yaml +++ b/Documentation/devicetree/bindings/pci/mediatek-pcie-gen3.yaml @@ -53,6 +53,7 @@ properties: - mediatek,mt8195-pcie - const: mediatek,mt8192-pcie - const: mediatek,mt8192-pcie + - const: airoha,en7581-pcie reg: maxItems: 1 @@ -76,20 +77,20 @@ properties: resets: minItems: 1 - maxItems: 2 + maxItems: 3 reset-names: minItems: 1 - maxItems: 2 + maxItems: 3 items: - enum: [ phy, mac ] + enum: [ phy, mac, phy-lane0, phy-lane1, phy-lane2 ] clocks: - minItems: 4 + minItems: 1 maxItems: 6 clock-names: - minItems: 4 + minItems: 1 maxItems: 6 assigned-clocks: @@ -186,6 +187,20 @@ allOf: - const: tl_26m - const: peri_26m - const: top_133m + - if: + properties: + compatible: + const: airoha,en7581-pcie + then: + properties: + clock-names: + items: + - const: sys_ck + reset-names: + items: + - const: phy-lane0 + - const: phy-lane1 + - const: phy-lane2 unevaluatedProperties: false From patchwork Fri Jun 21 14:48:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 13707734 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 523DAC27C4F for ; Fri, 21 Jun 2024 14:49:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=/fFWBpCAn0Jie3Oqpa/Ap7R9lB1ZHat+MP4AI63OWC4=; b=UAaokuxw/VDSmTvbpQqyT3KAab yTwRhXv1HOXdFjpzJa2iyzGH4BNZL2kgU4ZbQQAFsl5iFj49kgU5VyYH2r14P0S9Y1usjWMW0Jppc dQQ6CzYMWIio76aU9QaUtUY6xtudcqZ9aIqHlpSSwOPfXRiGlVQfqdMXh3kKnFUTZj23C4HC9I8lQ 7/XbAVZsXxf0fX2IKignUhDVkLaElekxP8Juz0WuH7hPrfwVhZfk1E4hip/aLMLcFL8XgDRSthVXo frcTHDyLDHZeLQb2r6LOx95jsimTX0Cm2JnKnGkhAa8sXwHU9dF6uLFQ1IAqKVeGoJuy1AQkY6UBN vVYH/G5Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKfZy-00000009aTO-23kJ; Fri, 21 Jun 2024 14:49:30 +0000 Received: from sin.source.kernel.org ([2604:1380:40e1:4800::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKfZq-00000009aPO-3YpO; Fri, 21 Jun 2024 14:49:24 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 49F9CCE2E57; Fri, 21 Jun 2024 14:49:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A7D1C2BBFC; Fri, 21 Jun 2024 14:49:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718981360; bh=9F7O07gma7ZSq8wSpr6tX5daMjGrvBoRc8UPNXsrYD8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Sbzw3ErxbdSmwwH0qh3xUwnR7Vi04Kqb9+BjIm+OMZC0exdo3t9spThEQNYOWDN15 mujoSNXoQZbwazoIGqiFrNvpF/GJItFEGMsPpNJGjTiV4rKwAaBN4QmYlNMGZpVwfy tlHeNzREPhz2pUxTKEfaLjclv4Ux71ymvwMeMfw4omuaMpl0PQVOS5fJVZBLhqFjZF ibBrc2zKHSOkDEA+mcDEvoFo65snDMa2IHp3TuGwbvqfE5cTrnQEl5g63nBjecHql3 zwpesg7GIVpjQygZr2FRCfzw01n4/62lDxzlUt2zsVG6gZvtHwvDSRAIGF9ilBLNCu MDNqArK07SY7w== From: Lorenzo Bianconi To: linux-pci@vger.kernel.org Cc: ryder.lee@mediatek.com, lpieralisi@kernel.org, kw@linux.com, robh@kernel.org, bhelgaas@google.com, linux-mediatek@lists.infradead.org, lorenzo.bianconi83@gmail.com, linux-arm-kernel@lists.infradead.org, krzysztof.kozlowski+dt@linaro.org, devicetree@vger.kernel.org, nbd@nbd.name, dd@embedd.com, upstream@airoha.com, angelogioacchino.delregno@collabora.com Subject: [PATCH 2/4] PCI: mediatek-gen3: Add mtk_pcie_soc data structure Date: Fri, 21 Jun 2024 16:48:48 +0200 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240621_074923_268971_D11E0367 X-CRM114-Status: GOOD ( 14.84 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Introduce mtk_pcie_soc data structure in order to define multiple callbacks for each supported SoC. This is a preliminary patch to introduce EN7581 pcie support. Tested-by: Zhengping Zhang Signed-off-by: Lorenzo Bianconi --- drivers/pci/controller/pcie-mediatek-gen3.c | 24 ++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/drivers/pci/controller/pcie-mediatek-gen3.c b/drivers/pci/controller/pcie-mediatek-gen3.c index 975b3024fb08..4859bd875bc4 100644 --- a/drivers/pci/controller/pcie-mediatek-gen3.c +++ b/drivers/pci/controller/pcie-mediatek-gen3.c @@ -100,6 +100,16 @@ #define PCIE_ATR_TLP_TYPE_MEM PCIE_ATR_TLP_TYPE(0) #define PCIE_ATR_TLP_TYPE_IO PCIE_ATR_TLP_TYPE(2) +struct mtk_gen3_pcie; + +/** + * struct mtk_pcie_soc - differentiate between host generations + * @power_up: pcie power_up callback + */ +struct mtk_pcie_soc { + int (*power_up)(struct mtk_gen3_pcie *pcie); +}; + /** * struct mtk_msi_set - MSI information for each set * @base: IO mapped register base @@ -131,6 +141,7 @@ struct mtk_msi_set { * @msi_sets: MSI sets information * @lock: lock protecting IRQ bit map * @msi_irq_in_use: bit map for assigned MSI IRQ + * @soc: pointer to SoC-dependent operations */ struct mtk_gen3_pcie { struct device *dev; @@ -151,6 +162,8 @@ struct mtk_gen3_pcie { struct mtk_msi_set msi_sets[PCIE_MSI_SET_NUM]; struct mutex lock; DECLARE_BITMAP(msi_irq_in_use, PCIE_MSI_IRQS_NUM); + + const struct mtk_pcie_soc *soc; }; /* LTSSM state in PCIE_LTSSM_STATUS_REG bit[28:24] */ @@ -904,7 +917,7 @@ static int mtk_pcie_setup(struct mtk_gen3_pcie *pcie) usleep_range(10, 20); /* Don't touch the hardware registers before power up */ - err = mtk_pcie_power_up(pcie); + err = pcie->soc->power_up(pcie); if (err) return err; @@ -939,6 +952,7 @@ static int mtk_pcie_probe(struct platform_device *pdev) pcie = pci_host_bridge_priv(host); pcie->dev = dev; + pcie->soc = of_device_get_match_data(dev); platform_set_drvdata(pdev, pcie); err = mtk_pcie_setup(pcie); @@ -1054,7 +1068,7 @@ static int mtk_pcie_resume_noirq(struct device *dev) struct mtk_gen3_pcie *pcie = dev_get_drvdata(dev); int err; - err = mtk_pcie_power_up(pcie); + err = pcie->soc->power_up(pcie); if (err) return err; @@ -1074,8 +1088,12 @@ static const struct dev_pm_ops mtk_pcie_pm_ops = { mtk_pcie_resume_noirq) }; +static const struct mtk_pcie_soc mtk_pcie_soc_mt8192 = { + .power_up = mtk_pcie_power_up, +}; + static const struct of_device_id mtk_pcie_of_match[] = { - { .compatible = "mediatek,mt8192-pcie" }, + { .compatible = "mediatek,mt8192-pcie", .data = &mtk_pcie_soc_mt8192 }, {}, }; MODULE_DEVICE_TABLE(of, mtk_pcie_of_match); From patchwork Fri Jun 21 14:48:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 13707736 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D110AC2BBCA for ; Fri, 21 Jun 2024 14:49:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=rEWgrHE8+kkC7RaWyQH0DKc69SirXXQDH93s2tukjko=; b=pwRDmQnlvMY3A4/uAz1WlMxahy lOt2M6qGJHLLn9U616iaiCPSO650kn0yiGBF7zAz2xAn5DCCxHlWcDl5CIhdr+0m6VlEucaZgHkwg 5SBZ2qz7xajuBFfD/syVqbUeoLGNcmBh+wAl0DuP1rTYbEe8W+vR6oAdQNcIKn+nExcwKXF7YLIO6 EuZGgz8NMm1mKGCeRimJfM0dYfmAmpHz2r5jP65yaLn5c09elZE0ONq08eL6LQ0jPonybfBWFLLbn rAU36ktho1QbW5o4twlB6UR/1l6Y5ags377etINNcG+ESpDrnAv1rmfhFf4gc4JIw2bLDRNwi512h RMpmuL0A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKfa0-00000009aUi-065q; Fri, 21 Jun 2024 14:49:32 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKfZu-00000009aQy-1mPJ; Fri, 21 Jun 2024 14:49:28 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id C06E96178D; Fri, 21 Jun 2024 14:49:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 00B49C2BBFC; Fri, 21 Jun 2024 14:49:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718981365; bh=3VLI8OQdCKrhE9tY0hosw/h2d6zYp15wqf38orILu+g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gf1Lt1AVeQliImIOvD9+SbH6NUZx3gtZLg0AQrcNKq/lpAHLJ4th+RX5B9U9+ChnY 4abQlcJcDGhNOINIxZEndckSCU001V4z33j2tqF9skMpTkrvC62AyDYIUErf6ioAt1 csJ7VA77Ptw5Y9yxAAoyqCP8SH6xzhGyNilDzxjKtApJanwkc0uNiD0LYdyT/AnyTO LynQ4KbKpY8gvaoHz8pjxDXDkbw9JhylakSXZKvIl0KAHGl0oVKf2JdLzx8ZoS012C AF+9WGM9xDjzREfE31d+/CezPMz98gRqvmQJFR4Sewh3t7PSjB/dOF7S62Lxh3eccl GfP72lVnlwy1Q== From: Lorenzo Bianconi To: linux-pci@vger.kernel.org Cc: ryder.lee@mediatek.com, lpieralisi@kernel.org, kw@linux.com, robh@kernel.org, bhelgaas@google.com, linux-mediatek@lists.infradead.org, lorenzo.bianconi83@gmail.com, linux-arm-kernel@lists.infradead.org, krzysztof.kozlowski+dt@linaro.org, devicetree@vger.kernel.org, nbd@nbd.name, dd@embedd.com, upstream@airoha.com, angelogioacchino.delregno@collabora.com Subject: [PATCH 3/4] PCI: mediatek-gen3: rely on reset_bulk APIs for phy reset lines Date: Fri, 21 Jun 2024 16:48:49 +0200 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240621_074926_629931_91634534 X-CRM114-Status: GOOD ( 17.30 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Use reset_bulk APIs to manage phy reset lines. This is a preliminary patch in order to add Airoha EN7581 pcie support. Tested-by: Zhengping Zhang Signed-off-by: Lorenzo Bianconi --- drivers/pci/controller/pcie-mediatek-gen3.c | 49 ++++++++++++++++----- 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/drivers/pci/controller/pcie-mediatek-gen3.c b/drivers/pci/controller/pcie-mediatek-gen3.c index 4859bd875bc4..9842617795a9 100644 --- a/drivers/pci/controller/pcie-mediatek-gen3.c +++ b/drivers/pci/controller/pcie-mediatek-gen3.c @@ -100,14 +100,21 @@ #define PCIE_ATR_TLP_TYPE_MEM PCIE_ATR_TLP_TYPE(0) #define PCIE_ATR_TLP_TYPE_IO PCIE_ATR_TLP_TYPE(2) +#define MAX_NUM_PHY_RSTS 1 + struct mtk_gen3_pcie; /** * struct mtk_pcie_soc - differentiate between host generations * @power_up: pcie power_up callback + * @phy_resets: phy reset lines SoC data. */ struct mtk_pcie_soc { int (*power_up)(struct mtk_gen3_pcie *pcie); + struct { + const char *id[MAX_NUM_PHY_RSTS]; + int num_rsts; + } phy_resets; }; /** @@ -128,7 +135,7 @@ struct mtk_msi_set { * @base: IO mapped register base * @reg_base: physical register base * @mac_reset: MAC reset control - * @phy_reset: PHY reset control + * @phy_resets: PHY reset controllers * @phy: PHY controller block * @clks: PCIe clocks * @num_clks: PCIe clocks count for this port @@ -148,7 +155,7 @@ struct mtk_gen3_pcie { void __iomem *base; phys_addr_t reg_base; struct reset_control *mac_reset; - struct reset_control *phy_reset; + struct reset_control_bulk_data phy_resets[MAX_NUM_PHY_RSTS]; struct phy *phy; struct clk_bulk_data *clks; int num_clks; @@ -790,8 +797,8 @@ static int mtk_pcie_parse_port(struct mtk_gen3_pcie *pcie) { struct device *dev = pcie->dev; struct platform_device *pdev = to_platform_device(dev); + int i, ret, num_rsts = pcie->soc->phy_resets.num_rsts; struct resource *regs; - int ret; regs = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcie-mac"); if (!regs) @@ -804,12 +811,13 @@ static int mtk_pcie_parse_port(struct mtk_gen3_pcie *pcie) pcie->reg_base = regs->start; - pcie->phy_reset = devm_reset_control_get_optional_exclusive(dev, "phy"); - if (IS_ERR(pcie->phy_reset)) { - ret = PTR_ERR(pcie->phy_reset); - if (ret != -EPROBE_DEFER) - dev_err(dev, "failed to get PHY reset\n"); + for (i = 0; i < num_rsts; i++) + pcie->phy_resets[i].id = pcie->soc->phy_resets.id[i]; + ret = devm_reset_control_bulk_get_optional_shared(dev, num_rsts, + pcie->phy_resets); + if (ret) { + dev_err(dev, "failed to get PHY bulk reset\n"); return ret; } @@ -846,7 +854,12 @@ static int mtk_pcie_power_up(struct mtk_gen3_pcie *pcie) int err; /* PHY power on and enable pipe clock */ - reset_control_deassert(pcie->phy_reset); + err = reset_control_bulk_deassert(pcie->soc->phy_resets.num_rsts, + pcie->phy_resets); + if (err) { + dev_err(dev, "failed to deassert PHYs\n"); + return err; + } err = phy_init(pcie->phy); if (err) { @@ -882,7 +895,8 @@ static int mtk_pcie_power_up(struct mtk_gen3_pcie *pcie) err_phy_on: phy_exit(pcie->phy); err_phy_init: - reset_control_assert(pcie->phy_reset); + reset_control_bulk_assert(pcie->soc->phy_resets.num_rsts, + pcie->phy_resets); return err; } @@ -897,7 +911,8 @@ static void mtk_pcie_power_down(struct mtk_gen3_pcie *pcie) phy_power_off(pcie->phy); phy_exit(pcie->phy); - reset_control_assert(pcie->phy_reset); + reset_control_bulk_assert(pcie->soc->phy_resets.num_rsts, + pcie->phy_resets); } static int mtk_pcie_setup(struct mtk_gen3_pcie *pcie) @@ -912,7 +927,13 @@ static int mtk_pcie_setup(struct mtk_gen3_pcie *pcie) * The controller may have been left out of reset by the bootloader * so make sure that we get a clean start by asserting resets here. */ - reset_control_assert(pcie->phy_reset); + reset_control_bulk_deassert(pcie->soc->phy_resets.num_rsts, + pcie->phy_resets); + usleep_range(5000, 10000); + reset_control_bulk_assert(pcie->soc->phy_resets.num_rsts, + pcie->phy_resets); + msleep(100); + reset_control_assert(pcie->mac_reset); usleep_range(10, 20); @@ -1090,6 +1111,10 @@ static const struct dev_pm_ops mtk_pcie_pm_ops = { static const struct mtk_pcie_soc mtk_pcie_soc_mt8192 = { .power_up = mtk_pcie_power_up, + .phy_resets = { + .id[0] = "phy", + .num_rsts = 1, + }, }; static const struct of_device_id mtk_pcie_of_match[] = { From patchwork Fri Jun 21 14:48:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 13707737 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0D893C27C4F for ; Fri, 21 Jun 2024 14:49:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ejD9THN3n6PBSj7Kcr3I/5gAkrcUHEbCpPA4ahOADdA=; b=ZOcM0dUfwZFINcAzhArNu/WfL+ y2KenyAj1JEximahmvsOKepN1RxUIK/eVbft7vVxaheF7jrZ+wUV0rOLkGEXMUowqm7vvdvW6nKjc be4UcODkP8pQznMdPMt/QMBqzVgPJj3ITlm21KoDVTXULe87db6iryotgHI7Jh3o/lmW5JqOZaCZ7 LpwossdAGihHK0CgOIHUH1g6oS52T89RjkVOkz/JJlrJuCnCjmXrG/NLYD/V18ipdN+26prb5VG41 V6rHS3kZmT8Q0/LxCoXrBwpKFAdLmHttEnz55pL1lzlx0tc0vsoZhVWICdt2bTxS96uWcsyQANHiC aOaB5kag==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKfaE-00000009afA-39JH; Fri, 21 Jun 2024 14:49:46 +0000 Received: from sin.source.kernel.org ([2604:1380:40e1:4800::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKfa0-00000009aTU-0sRv; Fri, 21 Jun 2024 14:49:35 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 299CCCE2E3B; Fri, 21 Jun 2024 14:49:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C65A0C2BBFC; Fri, 21 Jun 2024 14:49:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718981369; bh=Zf8oDaaRN4fc057eHxK8XWV3Bfsxm5d5LDYfo3qGYHE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lMxhzbIoz84mA+lEL2oLRJeGSOfPaoH/U/RG1WOMrCl7swDx6H+RxDcSrfrC8IHaE DyoFJi8ZlDJMHatr5XGqgPDNB42mzHhQqO43XIHl1QHfm8b5QIJTnocvdG+Cgzvqfw sr7kZim6NEYblFGmOZIDEy6HF6IGlJZK5yJDX3TMTEX9aYGsZgEHM/BnGkJWAElM38 PVnFDKZet8WtvhL+iiqxle7r35FGMrXEHBVf1oqDN/fB+HdoBgH+Mvo6yzgi+XSxLH PX92+UzY94FEVJmzlc8pU6SzLNfD2I/4etaqiHjZIiIJ2hfyK6O7VS4ygrJ1U2AywU J/zn/imC0VtyA== From: Lorenzo Bianconi To: linux-pci@vger.kernel.org Cc: ryder.lee@mediatek.com, lpieralisi@kernel.org, kw@linux.com, robh@kernel.org, bhelgaas@google.com, linux-mediatek@lists.infradead.org, lorenzo.bianconi83@gmail.com, linux-arm-kernel@lists.infradead.org, krzysztof.kozlowski+dt@linaro.org, devicetree@vger.kernel.org, nbd@nbd.name, dd@embedd.com, upstream@airoha.com, angelogioacchino.delregno@collabora.com Subject: [PATCH 4/4] PCI: mediatek-gen3: Add Airoha EN7581 support Date: Fri, 21 Jun 2024 16:48:50 +0200 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240621_074932_953348_D82AAB7A X-CRM114-Status: GOOD ( 16.16 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Introduce support for Airoha EN7581 pcie controller to mediatek-gen3 pcie controller driver. Tested-by: Zhengping Zhang Signed-off-by: Lorenzo Bianconi --- drivers/pci/controller/Kconfig | 2 +- drivers/pci/controller/pcie-mediatek-gen3.c | 84 ++++++++++++++++++++- 2 files changed, 84 insertions(+), 2 deletions(-) diff --git a/drivers/pci/controller/Kconfig b/drivers/pci/controller/Kconfig index e534c02ee34f..3bd6c9430010 100644 --- a/drivers/pci/controller/Kconfig +++ b/drivers/pci/controller/Kconfig @@ -196,7 +196,7 @@ config PCIE_MEDIATEK config PCIE_MEDIATEK_GEN3 tristate "MediaTek Gen3 PCIe controller" - depends on ARCH_MEDIATEK || COMPILE_TEST + depends on ARCH_AIROHA || ARCH_MEDIATEK || COMPILE_TEST depends on PCI_MSI help Adds support for PCIe Gen3 MAC controller for MediaTek SoCs. diff --git a/drivers/pci/controller/pcie-mediatek-gen3.c b/drivers/pci/controller/pcie-mediatek-gen3.c index 9842617795a9..2dacfed665c6 100644 --- a/drivers/pci/controller/pcie-mediatek-gen3.c +++ b/drivers/pci/controller/pcie-mediatek-gen3.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -21,6 +22,8 @@ #include #include #include +#include +#include #include "../pci.h" @@ -29,6 +32,7 @@ #define PCI_CLASS(class) (class << 8) #define PCIE_RC_MODE BIT(0) +#define PCIE_EQ_PRESET_01_REF 0x100 #define PCIE_CFGNUM_REG 0x140 #define PCIE_CFG_DEVFN(devfn) ((devfn) & GENMASK(7, 0)) #define PCIE_CFG_BUS(bus) (((bus) << 8) & GENMASK(15, 8)) @@ -68,6 +72,7 @@ #define PCIE_MSI_SET_ENABLE_REG 0x190 #define PCIE_MSI_SET_ENABLE GENMASK(PCIE_MSI_SET_NUM - 1, 0) +#define PCIE_PIPE4_PIE8_REG 0x338 #define PCIE_MSI_SET_BASE_REG 0xc00 #define PCIE_MSI_SET_OFFSET 0x10 #define PCIE_MSI_SET_STATUS_OFFSET 0x04 @@ -100,7 +105,7 @@ #define PCIE_ATR_TLP_TYPE_MEM PCIE_ATR_TLP_TYPE(0) #define PCIE_ATR_TLP_TYPE_IO PCIE_ATR_TLP_TYPE(2) -#define MAX_NUM_PHY_RSTS 1 +#define MAX_NUM_PHY_RSTS 3 struct mtk_gen3_pcie; @@ -848,6 +853,72 @@ static int mtk_pcie_parse_port(struct mtk_gen3_pcie *pcie) return 0; } +static int mtk_pcie_en7581_power_up(struct mtk_gen3_pcie *pcie) +{ + struct device *dev = pcie->dev; + int err; + + writel_relaxed(0x23020133, pcie->base + 0x10044); + writel_relaxed(0x50500032, pcie->base + 0x15030); + writel_relaxed(0x50500032, pcie->base + 0x15130); + + err = phy_init(pcie->phy); + if (err) { + dev_err(dev, "failed to initialize PHY\n"); + return err; + } + mdelay(30); + + err = phy_power_on(pcie->phy); + if (err) { + dev_err(dev, "failed to power on PHY\n"); + goto err_phy_on; + } + + err = reset_control_bulk_deassert(pcie->soc->phy_resets.num_rsts, + pcie->phy_resets); + if (err) { + dev_err(dev, "failed to deassert PHYs\n"); + goto err_phy_deassert; + } + usleep_range(5000, 10000); + + pm_runtime_enable(dev); + pm_runtime_get_sync(dev); + + err = clk_bulk_prepare(pcie->num_clks, pcie->clks); + if (err) { + dev_err(dev, "failed to prepare clock\n"); + goto err_clk_prepare; + } + + writel_relaxed(0x41474147, pcie->base + PCIE_EQ_PRESET_01_REF); + writel_relaxed(0x1018020f, pcie->base + PCIE_PIPE4_PIE8_REG); + mdelay(10); + + err = clk_bulk_enable(pcie->num_clks, pcie->clks); + if (err) { + dev_err(dev, "failed to prepare clock\n"); + goto err_clk_enable; + } + + return 0; + +err_clk_enable: + clk_bulk_unprepare(pcie->num_clks, pcie->clks); +err_clk_prepare: + pm_runtime_put_sync(dev); + pm_runtime_disable(dev); + reset_control_bulk_assert(pcie->soc->phy_resets.num_rsts, + pcie->phy_resets); +err_phy_deassert: + phy_power_off(pcie->phy); +err_phy_on: + phy_exit(pcie->phy); + + return err; +} + static int mtk_pcie_power_up(struct mtk_gen3_pcie *pcie) { struct device *dev = pcie->dev; @@ -1117,8 +1188,19 @@ static const struct mtk_pcie_soc mtk_pcie_soc_mt8192 = { }, }; +static const struct mtk_pcie_soc mtk_pcie_soc_en7581 = { + .power_up = mtk_pcie_en7581_power_up, + .phy_resets = { + .id[0] = "phy-lane0", + .id[1] = "phy-lane1", + .id[2] = "phy-lane2", + .num_rsts = 3, + }, +}; + static const struct of_device_id mtk_pcie_of_match[] = { { .compatible = "mediatek,mt8192-pcie", .data = &mtk_pcie_soc_mt8192 }, + { .compatible = "airoha,en7581-pcie", .data = &mtk_pcie_soc_en7581 }, {}, }; MODULE_DEVICE_TABLE(of, mtk_pcie_of_match);