From: Chen-Yu Tsai <wenst@chromium.org>
To: "Matthias Brugger" <matthias.bgg@gmail.com>,
"AngeloGioacchino Del Regno"
<angelogioacchino.delregno@collabora.com>,
"Ryder Lee" <ryder.lee@mediatek.com>,
"Jianjun Wang" <jianjun.wang@mediatek.com>,
"Lorenzo Pieralisi" <lpieralisi@kernel.org>,
"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
"Manivannan Sadhasivam" <mani@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Bjorn Helgaas" <bhelgaas@google.com>
Cc: devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
Chen-Yu Tsai <wenst@chromium.org>,
Bartosz Golaszewski <brgl@bgdev.pl>,
linux-pci@vger.kernel.org, linux-mediatek@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 3/7] PCI: mediatek-gen3: Split out device power helpers
Date: Wed, 25 Feb 2026 15:22:20 +0800 [thread overview]
Message-ID: <20260225072225.3345307-4-wenst@chromium.org> (raw)
In-Reply-To: <20260225072225.3345307-1-wenst@chromium.org>
Split out existing code that deals with device power sequencing into
into helpers to allow cleaning up the error paths and integrating the
new PCI pwrctrl API,
This change is purely code movement.
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
---
drivers/pci/controller/pcie-mediatek-gen3.c | 87 ++++++++++++---------
1 file changed, 52 insertions(+), 35 deletions(-)
diff --git a/drivers/pci/controller/pcie-mediatek-gen3.c b/drivers/pci/controller/pcie-mediatek-gen3.c
index f2bf4afbdc2f..870d3b3db11d 100644
--- a/drivers/pci/controller/pcie-mediatek-gen3.c
+++ b/drivers/pci/controller/pcie-mediatek-gen3.c
@@ -403,6 +403,54 @@ static void mtk_pcie_enable_msi(struct mtk_gen3_pcie *pcie)
writel_relaxed(val, pcie->base + PCIE_INT_ENABLE_REG);
}
+static int mtk_pcie_device_power_up(struct mtk_gen3_pcie *pcie)
+{
+ int err;
+ u32 val;
+
+ /*
+ * Airoha EN7581 has a hw bug asserting/releasing PCIE_PE_RSTB signal
+ * causing occasional PCIe link down. In order to overcome the issue,
+ * PCIE_RSTB signals are not asserted/released at this stage and the
+ * PCIe block is reset using en7523_reset_assert() and
+ * en7581_pci_enable().
+ */
+ if (!(pcie->soc->flags & SKIP_PCIE_RSTB)) {
+ /* Assert all reset signals */
+ val = readl_relaxed(pcie->base + PCIE_RST_CTRL_REG);
+ val |= PCIE_MAC_RSTB | PCIE_PHY_RSTB | PCIE_BRG_RSTB |
+ PCIE_PE_RSTB;
+ writel_relaxed(val, pcie->base + PCIE_RST_CTRL_REG);
+
+ /*
+ * Described in PCIe CEM specification revision 6.0.
+ *
+ * The deassertion of PERST# should be delayed 100ms (TPVPERL)
+ * for the power and clock to become stable.
+ */
+ msleep(PCIE_T_PVPERL_MS);
+
+ /* De-assert reset signals */
+ val &= ~(PCIE_MAC_RSTB | PCIE_PHY_RSTB | PCIE_BRG_RSTB |
+ PCIE_PE_RSTB);
+ writel_relaxed(val, pcie->base + PCIE_RST_CTRL_REG);
+ }
+
+ return 0;
+}
+
+static void mtk_pcie_device_power_down(struct mtk_gen3_pcie *pcie)
+{
+ u32 val;
+
+ if (!(pcie->soc->flags & SKIP_PCIE_RSTB)) {
+ /* Assert the PERST# pin */
+ val = readl_relaxed(pcie->base + PCIE_RST_CTRL_REG);
+ val |= PCIE_PE_RSTB;
+ writel_relaxed(val, pcie->base + PCIE_RST_CTRL_REG);
+ }
+}
+
static int mtk_pcie_startup_port(struct mtk_gen3_pcie *pcie)
{
struct resource_entry *entry;
@@ -464,33 +512,9 @@ static int mtk_pcie_startup_port(struct mtk_gen3_pcie *pcie)
val |= PCIE_DISABLE_DVFSRC_VLT_REQ;
writel_relaxed(val, pcie->base + PCIE_MISC_CTRL_REG);
- /*
- * Airoha EN7581 has a hw bug asserting/releasing PCIE_PE_RSTB signal
- * causing occasional PCIe link down. In order to overcome the issue,
- * PCIE_RSTB signals are not asserted/released at this stage and the
- * PCIe block is reset using en7523_reset_assert() and
- * en7581_pci_enable().
- */
- if (!(pcie->soc->flags & SKIP_PCIE_RSTB)) {
- /* Assert all reset signals */
- val = readl_relaxed(pcie->base + PCIE_RST_CTRL_REG);
- val |= PCIE_MAC_RSTB | PCIE_PHY_RSTB | PCIE_BRG_RSTB |
- PCIE_PE_RSTB;
- writel_relaxed(val, pcie->base + PCIE_RST_CTRL_REG);
-
- /*
- * Described in PCIe CEM specification revision 6.0.
- *
- * The deassertion of PERST# should be delayed 100ms (TPVPERL)
- * for the power and clock to become stable.
- */
- msleep(PCIE_T_PVPERL_MS);
-
- /* De-assert reset signals */
- val &= ~(PCIE_MAC_RSTB | PCIE_PHY_RSTB | PCIE_BRG_RSTB |
- PCIE_PE_RSTB);
- writel_relaxed(val, pcie->base + PCIE_RST_CTRL_REG);
- }
+ err = mtk_pcie_device_power_up(pcie);
+ if (err)
+ return err;
/* Check if the link is up or not */
err = readl_poll_timeout(pcie->base + PCIE_LINK_STATUS_REG, val,
@@ -1269,7 +1293,6 @@ static int mtk_pcie_suspend_noirq(struct device *dev)
{
struct mtk_gen3_pcie *pcie = dev_get_drvdata(dev);
int err;
- u32 val;
/* Trigger link to L2 state */
err = mtk_pcie_turn_off_link(pcie);
@@ -1278,13 +1301,7 @@ static int mtk_pcie_suspend_noirq(struct device *dev)
return err;
}
- if (!(pcie->soc->flags & SKIP_PCIE_RSTB)) {
- /* Assert the PERST# pin */
- val = readl_relaxed(pcie->base + PCIE_RST_CTRL_REG);
- val |= PCIE_PE_RSTB;
- writel_relaxed(val, pcie->base + PCIE_RST_CTRL_REG);
- }
-
+ mtk_pcie_device_power_down(pcie);
dev_dbg(pcie->dev, "entered L2 states successfully");
mtk_pcie_irq_save(pcie);
--
2.53.0.414.gf7e9f6c205-goog
next prev parent reply other threads:[~2026-02-25 7:22 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-25 7:22 [PATCH 0/7] PCI: mediatek-gen3: add power control support Chen-Yu Tsai
2026-02-25 7:22 ` [PATCH 1/7] PCI: mediatek-gen3: Clean up mtk_pcie_parse_port() with dev_err_probe() Chen-Yu Tsai
2026-02-25 8:11 ` Bartosz Golaszewski
2026-02-25 13:13 ` AngeloGioacchino Del Regno
2026-02-25 7:22 ` [PATCH 2/7] PCI: mediatek-gen3: Add error path for probe and resume driver callbacks Chen-Yu Tsai
2026-02-25 8:19 ` Bartosz Golaszewski
2026-02-25 13:13 ` AngeloGioacchino Del Regno
2026-02-25 7:22 ` Chen-Yu Tsai [this message]
2026-02-25 8:13 ` [PATCH 3/7] PCI: mediatek-gen3: Split out device power helpers Bartosz Golaszewski
2026-02-25 13:13 ` AngeloGioacchino Del Regno
2026-02-25 7:22 ` [PATCH 4/7] PCI: mediatek-gen3: Disable device if further setup fails Chen-Yu Tsai
2026-02-25 8:19 ` Bartosz Golaszewski
2026-02-25 13:13 ` AngeloGioacchino Del Regno
2026-02-25 7:22 ` [PATCH 5/7] PCI: mediatek-gen3: Integrate new pwrctrl API Chen-Yu Tsai
2026-02-25 9:30 ` Bartosz Golaszewski
2026-02-25 9:37 ` Chen-Yu Tsai
2026-02-25 13:13 ` AngeloGioacchino Del Regno
2026-02-25 13:20 ` Manivannan Sadhasivam
2026-02-25 7:22 ` [PATCH 6/7] arm64: dts: mediatek: mt8195-cherry: add WiFi PCIe and BT USB power supplies Chen-Yu Tsai
2026-02-25 13:12 ` AngeloGioacchino Del Regno
2026-02-25 7:22 ` [PATCH 7/7] arm64: dts: mediatek: mt8195-cherry-dojo: Describe M.2 M-key NVMe slot Chen-Yu Tsai
2026-02-25 13:12 ` AngeloGioacchino Del Regno
2026-02-25 13:25 ` [PATCH 0/7] PCI: mediatek-gen3: add power control support Manivannan Sadhasivam
2026-02-26 6:12 ` Chen-Yu Tsai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260225072225.3345307-4-wenst@chromium.org \
--to=wenst@chromium.org \
--cc=angelogioacchino.delregno@collabora.com \
--cc=bhelgaas@google.com \
--cc=brgl@bgdev.pl \
--cc=devicetree@vger.kernel.org \
--cc=jianjun.wang@mediatek.com \
--cc=kwilczynski@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-pci@vger.kernel.org \
--cc=lpieralisi@kernel.org \
--cc=mani@kernel.org \
--cc=matthias.bgg@gmail.com \
--cc=robh@kernel.org \
--cc=ryder.lee@mediatek.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®