From nobody Thu Apr 9 08:52:39 2026 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 875AD43E4AE for ; Tue, 10 Mar 2026 09:20:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773134412; cv=none; b=Fjf5S9Hr4Gcd2XMNWeMSIxUsxTRxgMq786+JwVM3LN+rvtBcttcVMD60+XhNFXceukuH4IgLHbJJXUrmjF5H6Maf8kGqxVxj8trGX759ecVrTiKb7qq8NdSXW8ZTqya+Pn+vMiy6kOQw3110inn2dX7VJJoAXenONVg7aWJIQYc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773134412; c=relaxed/simple; bh=gFJMTFEy+nnpV33A5U3bQxqrBPcmvAng71SZZE7y1fI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BetLd/zbJ4gBd6PZv9J2OtGoUi5BuwkIJIXF1lsgjxHiQFbDuGqyv0g9L5GDZ/grK9kJKnRBLsl/bafMgS8GfNxHpZQdRYz3TOJXMGRLNQLuFDHM/R4g1WFWsPz4VI6XnkTOXBdAxtIghmSsxVCY160AfsSn47y7Pjd0wiDqBXU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=EXOiyolu; arc=none smtp.client-ip=209.85.210.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="EXOiyolu" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-829928e512aso2747285b3a.2 for ; Tue, 10 Mar 2026 02:20:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1773134411; x=1773739211; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rM88DzClemQjIwSD9XmXpaA4dBGL6dPMUDYPBc87GuI=; b=EXOiyoluDjBUCYTkc4etLuLV+nVdrtg5BWw0hHlkPJl9Pe79f9m7BPmUhXX9hIRa+G QNC8WpNP2k5gOc805jtqIS64bntxlV63nAcdjJTug/kP8ZqniqZlX0A81d0PsEl7b+ii 2CHo+91MlAWkBVl4aV4hRz6ZRnTdr2NSAJLUw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773134411; x=1773739211; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=rM88DzClemQjIwSD9XmXpaA4dBGL6dPMUDYPBc87GuI=; b=OGq5ciXzjNu6b6Koy3YSWOdu5RvLvvWPOT8xyA2vP6Ozou2Ikqh1hQ7lOdvcZe6Io3 nW1QiXYcEk0X7VReLrbcX+lMl3oNVqh3VqFD14gGFLWUX5agIL0U5FrW2aaRLa/DyFtZ lueVQ5bIi2femkDcAc5RzBTay45g9bYO6OAejx0D6SGEPCYublna4Rt9NgVHLqPgRFc3 mJjLJmiZY3z6i/vT7Zl9Dzf0dnCERAI3qDHs5SXrQdzXasvQQaH2Tgd/7tCRYDbE4PLW ItDRRdafSKa4Nj9zo7Pp5Olbeig6znmFZ3TuEF2920pWI6c+O/k1FPOCotOsg2UXPhyw VR9A== X-Forwarded-Encrypted: i=1; AJvYcCUsS9O5gILW1jH2vJ5RJAL1yIHSPh3MieaaT30hOFn5qxzIDKNjOksjFiTL2xE8jdu4oeoQgvTTi/tO48A=@vger.kernel.org X-Gm-Message-State: AOJu0YyB6V14BWDRzmfCujCm7iAPe3aWWEIxUP+hYUNpAPGZ34tC9hM6 lg6aF+QLbTZXIsv61ajVcPHviTbSZRi6Q3AoIxAzuF+ezV+IBIequW+lr7yQh9Rlqg== X-Gm-Gg: ATEYQzzPUKwWDFXia7zRT9eTChc+CP1eoIY40Cfip/MpTmbvfAuJyejd0Wl5a55LgwB WuXyVfLOxERg8f7BrNwLSDNrR4hDy2f2RJ0d7g5hZbzFMUZE0EP6zA9t+4eZxr9XyJwF+f/yS/x Zp2TZkf2NvfmZJK5CvCCrfF3sQgZbM6Vj7Kxc2xOj9qS8bSQoUseUlc7dbbApPhe4eWe8UbxeTA EKCU64w1i96sX7WrSzRTqelPaJInN1LiaAT2QufSdB6+BxDfexxHzovR20B0SvfuDo8ngcZbDWY JzhN5fNX/OpYh7U1VGlQA6RaRdSu4i6BDFZknzRtfjAcYduaQzWqYyEIhHel9/+AEifbCweU8cd rmbHscUeRpW/dJFTnY4jUvfebiHJfoTn+FJ8zrlpsrwajdwdC71WCmH/tjamNugXGenbVtkVw42 wMSvJPoNdY5VbMrYaijZir6D3q8+F7fFtEocRahmDMOWiDj8M+oS+Nw5BxpAk4/CaIGPUnI/cQI /vnEL7o X-Received: by 2002:a05:6a00:882:b0:829:7187:1a80 with SMTP id d2e1a72fcca58-829a2f80e50mr13446197b3a.45.1773134410893; Tue, 10 Mar 2026 02:20:10 -0700 (PDT) Received: from wenstp920.tpe.corp.google.com ([2a00:79e0:201d:8:ee38:e01e:e888:6900]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-829a48a3b74sm16965190b3a.45.2026.03.10.02.20.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Mar 2026 02:20:10 -0700 (PDT) From: Chen-Yu Tsai To: Matthias Brugger , AngeloGioacchino Del Regno , Ryder Lee , Lorenzo Pieralisi , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Manivannan Sadhasivam , Rob Herring , Bjorn Helgaas Cc: Chen-Yu Tsai , Bartosz Golaszewski , linux-pci@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v4 5/7] PCI: mediatek-gen3: Split out device power helpers Date: Tue, 10 Mar 2026 17:19:44 +0800 Message-ID: <20260310091947.2742004-6-wenst@chromium.org> X-Mailer: git-send-email 2.53.0.473.g4a7958ca14-goog In-Reply-To: <20260310091947.2742004-1-wenst@chromium.org> References: <20260310091947.2742004-1-wenst@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In preparation for adding full power on/off control with the pwrctrl API, split out the existing code that only partially deals with device power sequencing into separate helper functions. The existing code only handles PERST#. This is purely moving code around, and brings no functional changes. Reviewed-by: AngeloGioacchino Del Regno Reviewed-by: Bartosz Golaszewski Reviewed-by: Manivannan Sadhasivam Signed-off-by: Chen-Yu Tsai --- Changes since v3: - Adapted to movement of existing setup code Changes since v1: - Updated commit message --- 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/cont= roller/pcie-mediatek-gen3.c index 22a16e4ebc76..3e5386c4cb35 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); } =20 +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 =3D readl_relaxed(pcie->base + PCIE_RST_CTRL_REG); + val |=3D 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 &=3D ~(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 =3D readl_relaxed(pcie->base + PCIE_RST_CTRL_REG); + val |=3D 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; @@ -489,33 +537,9 @@ static int mtk_pcie_startup_port(struct mtk_gen3_pcie = *pcie) return err; } =20 - /* - * 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 =3D readl_relaxed(pcie->base + PCIE_RST_CTRL_REG); - val |=3D 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 &=3D ~(PCIE_MAC_RSTB | PCIE_PHY_RSTB | PCIE_BRG_RSTB | - PCIE_PE_RSTB); - writel_relaxed(val, pcie->base + PCIE_RST_CTRL_REG); - } + err =3D mtk_pcie_device_power_up(pcie); + if (err) + return err; =20 /* Check if the link is up or not */ err =3D readl_poll_timeout(pcie->base + PCIE_LINK_STATUS_REG, val, @@ -1270,7 +1294,6 @@ static int mtk_pcie_suspend_noirq(struct device *dev) { struct mtk_gen3_pcie *pcie =3D dev_get_drvdata(dev); int err; - u32 val; =20 /* Trigger link to L2 state */ err =3D mtk_pcie_turn_off_link(pcie); @@ -1279,13 +1302,7 @@ static int mtk_pcie_suspend_noirq(struct device *dev) return err; } =20 - if (!(pcie->soc->flags & SKIP_PCIE_RSTB)) { - /* Assert the PERST# pin */ - val =3D readl_relaxed(pcie->base + PCIE_RST_CTRL_REG); - val |=3D 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"); =20 mtk_pcie_irq_save(pcie); --=20 2.53.0.473.g4a7958ca14-goog