From nobody Thu Apr 9 05:48:11 2026 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (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 948B73B4EA3 for ; Wed, 11 Mar 2026 07:52:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773215578; cv=none; b=aLcqGHaU61jm8X/WW+L08ZW0smvLeInx0e7Q4lWwmPlGJsO+Be922kNmT+wRUjP7hBHJEPmJITjPGOE5Vhn8aGnYxjjI8jWWMSqrgmHaW+E8OpyNf6nXsEs2RDMpNAYtPDGxEqixqgGaLGwjFMt9gZzkm3Q7LiiFmZ42UC7GKY0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773215578; c=relaxed/simple; bh=cn+F8kFPmGqoisb3+M/JAw0Jua0Yeg6NgwrOsB4mvZ4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WWVRnhLhlqxG14qEWwo/wxkJgek/CALo67G64nHLM6AQePMR5Ww19WBooGFA3Dm0a+lxvB2iNW2aN2txmbCfss1hbbsdkndr9XAdViH8qrONFft5x1lK02Cx1UYiwgse+xJD1pmPlZtBOc3gJVHyghwdUN1q5yVEx7BXJvFmmO4= 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=dMQ7iUOk; arc=none smtp.client-ip=209.85.216.42 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="dMQ7iUOk" Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-3590042fa8eso8784955a91.1 for ; Wed, 11 Mar 2026 00:52:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1773215575; x=1773820375; 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=N6fVptWLhJR70eZVTOtUJtoUJ1orUez68YYQc4veVMA=; b=dMQ7iUOkqSeWO7VZHq/P63BqsDy7zCq5wu5Zuo8R895tx9NDBXOFSqw5+6d7tXnX9+ A6iqQqRTxEUHvQNm5jipmsp2LRdHpsZyo1u84TyfsEn4HstrGKvzYzj8s1JsNcLXPca4 Lz9CrXm/nadQcqhHfVa3d5Uar8HgdfdjjLyVc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773215575; x=1773820375; 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=N6fVptWLhJR70eZVTOtUJtoUJ1orUez68YYQc4veVMA=; b=sKbe9nFD+sNIepgXDZPMXW7wWeQIyPJxjxGDU8AEu6UT49Qmh2ZHmVkIjYhT46GQsS hISYjub5Lz2LXs/5tJc0QWeuNnHggswO7B4TF8bkN++DIFdHZMMndxUfDC7UtGlQ4dZW AXAlRhNI+nSjAj+qYGWdD17b6HVEi0wLE2fDL1dp2FyWcNiIL19PkUiDP+r38fH4Dxpc jBVvZbhvfzeZ6lYEJQZfozPS2rE7at+nN1ZyVpzLNbk5esyifGt4cRtuLg9Tel5P0q35 B6I4VJG0rwUUn0Jpi6EcFp9aO8iOarOesUFIAyyiOLZYyIdh6jzrIIZ/gwkG4yBdwrLY c2uA== X-Forwarded-Encrypted: i=1; AJvYcCXz1Qfr2h1hpCvBzxiyUdJKZho1yj+ReVcFbqmt1MtKzr60Q85Cs+yV8wrAYMLeV8mVmRhqFPj3eDSNS58=@vger.kernel.org X-Gm-Message-State: AOJu0YyXEET5xnwt7NIaFWkWLOC6Ib0plnmMzGTA+UnJzf03kGNg7A7z T2LggPT4Z+LCiPVhgv/UIopAVw+VSiRSTTyjEosvvRFB8p/WsNwyOa1x2f/If4VqaQ== X-Gm-Gg: ATEYQzyqR/am4NVcdPWxzGZyuc+q6qlj18Gu0ZNQLRkCcar4LQkGxtn1sQzx4PdC3iL W6Jxhhx3kWOzXxKfKPwZp5nZOerx8u5GSJWissfTnDawzK0SEMXWNGNR3zWQE3Qp8/QPZzFGGsB XPp5VO4396AMqKHqLhcGVYlDG0q5A6lU93JE8j2aR7+zgOC/IqooPkz6A8kGvkUgIM63rgp2I2n KGo/0q1P2pE636PXB1enRgWKiU8md075z5WJav+/nby9fI3y+FEY4HkbLvAy+qbAM+kQapyiim8 c+FlQ1giAOe7AUbsPtBMxNK96zrMaDSW7u9yjQbhf2+2aSqU/KsitAGeGinNIj+ISTOIhvLaSyi DONWZ/aky//oGHhU2Fw15d5rHYm0qpZyMv7JF/zfPufKZoky+xC+nMwvjiDfWB2CrBa1esn+bQo LAqDMCmRkvtt0kWunHQYa9e/VmAV/cxY8xzhf0BTLaixcLSvKA2F04PGP6fzVO04mUhOmzr4GAS z7mhOcH+pgGK5VBcJs= X-Received: by 2002:a17:90b:1e46:b0:359:8f7e:d34a with SMTP id 98e67ed59e1d1-35a011d2c77mr1684100a91.9.1773215574812; Wed, 11 Mar 2026 00:52:54 -0700 (PDT) Received: from wenstp920.tpe.corp.google.com ([2a00:79e0:201d:8:805b:14e9:f783:bcae]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35a0236f79asm727816a91.6.2026.03.11.00.52.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Mar 2026 00:52:54 -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 v5 5/7] PCI: mediatek-gen3: Split out device power helpers Date: Wed, 11 Mar 2026 15:52:20 +0800 Message-ID: <20260311075223.3303497-6-wenst@chromium.org> X-Mailer: git-send-email 2.53.0.473.g4a7958ca14-goog In-Reply-To: <20260311075223.3303497-1-wenst@chromium.org> References: <20260311075223.3303497-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 v4: - s/mtk_pcie_device_power_(up|down)/mtk_pcie_devices_power_(up|down)/ (Bjorn) 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..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.473.g4a7958ca14-goog