From nobody Fri Apr 3 17:57:48 2026 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) (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 68F8E29B228 for ; Tue, 24 Mar 2026 05:20:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774329630; cv=none; b=WY81qv90zfDfT/2TSJogH99dHe//3VrGvQsuzSZaHXGNEEuQxmgm37ecqrxU6W4l2h0lnEBfDk4Ira4C8r9FvU/IcJFSOavyu7cRNb32LgkVhtUV/GHg7rXYDqlDmrdEzGGxSW30PU+D1ApNFiCkL33LUEmbCaXvbvMtMYHp/DU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774329630; c=relaxed/simple; bh=KExZ1uFY5D1jLsHcrlxWGkAsKI6SDYhHbGW/69FV8ac=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tDSpbmnvUEeHjFK9j0hCH9BPuU8NkJYTbYseLAadIA5J8+eudW6SScdS4monkVYHyi+3musPLua2u59R2xSRRrnXM0Bh2dyDrOZ/tj59Px2TCC2/nnALCBj1Eb4koaOe7iVnsm9NaA3DBWx3vsqNwWVPHhR2SqBF7zW/iJEXvQE= 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=SUtEOmRy; arc=none smtp.client-ip=209.85.216.52 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="SUtEOmRy" Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-35b905e9dc0so541442a91.3 for ; Mon, 23 Mar 2026 22:20:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1774329629; x=1774934429; 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=tBBocE8wHIzrURZ8u70flcyVVr5FTdBTVpVQUI9JEgQ=; b=SUtEOmRy6FpQY1Iny3LnWt1oAMv2TrjbztBzF5zT54FeRURVUyN4ho2FqGKpIg1ZWG 88ZFanW6lNm4uf9PbrlcFnKXsQWDSVFFSKa2yPsg3/QAYGtUvv4wyrAdw+lfNUp5abpn rBgXYaNQ5zvcrysO+zOq8L7FzB4u89ljAoydw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774329629; x=1774934429; 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=tBBocE8wHIzrURZ8u70flcyVVr5FTdBTVpVQUI9JEgQ=; b=SaSi7L5facQeszLNnqku/iwO6iGpGbPWTNN7qNYilne3NSZaipNKA2Yd5DUvFHqnMm ZfbKSCb3jnm/o4PJrkG2vUyaVFgzZmbm2hdVLVbRq4Ls+10nrZuU3FnNbKVu4Ld/jsjT HsjtLPKyLuZYScnAtr/dA5IJDd2/hx73dU/YxlXX0oXGIPCGIJChWKaRXmIWjSInWRVN wqVnaO8aBSJsrAb5SBvO7V0piAIp4PL2sEQSH8HRlzHf+d+D4q+J7EatTdSUUsfbecJC c2BXwOhKj3Rx4rMSToIYo1AJYJ3usviVGLIP8DTAhN7NleJHd3RttNzvOuZFNr4yjfXZ c/1g== X-Forwarded-Encrypted: i=1; AJvYcCUmEjrBB25fHPdil0N7bp47I26cCPALagElmCc030lZplsGBBZIna86ZAYt6ZxYKq0uh3q8ONZlGxcWUGc=@vger.kernel.org X-Gm-Message-State: AOJu0YxfSf6NGHqlXC16UJ/0YT65A0f+BQQBEh4U+fO7m11mymb1oYgQ kWhJwBY99eCv/+PSirgEgu0lDgxM0VA9VQOla1u6Vk/RrxxewC6nkgjaAEab+hnOnw== X-Gm-Gg: ATEYQzzeg93GHrx/3s/Q1Fu3BVgT1ejJQZiDU/GeJv00RuhrJ+cw1pgkvyYmjf81Ddm ckrLXLiRDHjLazlO6eBhCt77nIlV1/moeoBepEllldFI8qcG2B1GdMVRil4niOduct2nKGKn76G 57Vo7QvAHTumsCUxj4sP/o4vD/WuMr0i2HYlpaWesqq5XRQYXEqc4y+ODKZZ/0uAkMZmzYcW1D7 nyxCBInjqzhwb9IZbtjII0/757W0bd4aEOMuPJZzZPU4m38Kk3FLbt1lvHOFeBx8b6HKHo+6vGE sEIwA8VPLmBk7toLPalmZibgoUqen6jqGqsWLoHTBVNvkJxFJ3tzyvfZbwQmIThjnXjPZRc1f8O rn2S1gNrhztloVMD/DRrJ0paclztj9GYljjBRXCM0RpkN9hs805XvZnYZiv9U/UGBUScdVAn2ZN me9NBXXJ0vK80vpZAT0A0fiwKxoI6z5HRg1Y1Agu1SMLTnUp7GgZCb532krh/TlgmHSZc5xhmz3 7GZ8QSqMnLeT4GwmaI= X-Received: by 2002:a17:90b:510a:b0:359:3426:c60a with SMTP id 98e67ed59e1d1-35bd2bd6af9mr13589107a91.4.1774329628786; Mon, 23 Mar 2026 22:20:28 -0700 (PDT) Received: from wenstp920.tpe.corp.google.com ([2a00:79e0:201d:8:19a5:8f2f:d584:8078]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35c03124a87sm1068647a91.3.2026.03.23.22.20.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2026 22:20:28 -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 v6 5/7] PCI: mediatek-gen3: Split out device power helpers Date: Tue, 24 Mar 2026 13:19:57 +0800 Message-ID: <20260324052002.4072430-6-wenst@chromium.org> X-Mailer: git-send-email 2.53.0.983.g0bb29b3bc5-goog In-Reply-To: <20260324052002.4072430-1-wenst@chromium.org> References: <20260324052002.4072430-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 --- 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..526db8815401 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_devices_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_devices_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_devices_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_devices_power_down(pcie); dev_dbg(pcie->dev, "entered L2 states successfully"); =20 mtk_pcie_irq_save(pcie); --=20 2.53.0.983.g0bb29b3bc5-goog