Devicetree
 help / color / mirror / Atom feed
From: Koichiro Den <den@valinux.co.jp>
To: "Marek Vasut" <marek.vasut+renesas@mailbox.org>,
	"Yoshihiro Shimoda" <yoshihiro.shimoda.uh@renesas.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>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Geert Uytterhoeven" <geert+renesas@glider.be>,
	"Magnus Damm" <magnus.damm@gmail.com>,
	"Jingoo Han" <jingoohan1@gmail.com>
Cc: Philipp Zabel <p.zabel@pengutronix.de>,
	Frank Li <Frank.Li@nxp.com>, Niklas Cassel <cassel@kernel.org>,
	Wilfred Mallawa <wilfred.mallawa@wdc.com>,
	Serge Semin <fancer.lancer@gmail.com>,
	linux-pci@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 05/11] PCI: rcar-gen4: Split reusable hardware initialization
Date: Fri, 18 Sep 2026 12:20:32 +0900	[thread overview]
Message-ID: <20260918032038.2216471-6-den@valinux.co.jp> (raw)
In-Reply-To: <20260918032038.2216471-1-den@valinux.co.jp>

Prepare for Root Port recovery, which is going to reset and reinitialize
the controller with the same sequence probe uses, minus the steps that
must only run once.

Move clock enabling out of rcar_gen4_pcie_common_init() into
rcar_gen4_pcie_clk_enable(), so the power reset and mode setup in
common_init() can be re-run with the clocks already on. Gating the
clocks as well would add nothing: the "pwr" reset is the controller's
cold reset (power_up_rst_n) and resets all PCIEC registers by itself.

Split rcar_gen4_pcie_host_init() into rcar_gen4_pcie_host_hw_init(),
the part Root Port reset will reuse, and a probe-only wrapper.

The power reset is now asserted unconditionally, since recovery calls
common_init() with the controller running. At probe the block is
usually held in reset already, so this only adds a 1 ms wait there.

Propagate reset-controller errors while at it.

Signed-off-by: Koichiro Den <den@valinux.co.jp>
---
 drivers/pci/controller/dwc/pcie-rcar-gen4.c | 88 +++++++++++++--------
 1 file changed, 57 insertions(+), 31 deletions(-)

diff --git a/drivers/pci/controller/dwc/pcie-rcar-gen4.c b/drivers/pci/controller/dwc/pcie-rcar-gen4.c
index fe1f1940e809..8a85f5f45cda 100644
--- a/drivers/pci/controller/dwc/pcie-rcar-gen4.c
+++ b/drivers/pci/controller/dwc/pcie-rcar-gen4.c
@@ -178,23 +178,18 @@ static int rcar_gen4_pcie_common_init(struct rcar_gen4_pcie *rcar)
 	u32 val;
 	int ret;
 
-	ret = clk_bulk_prepare_enable(DW_PCIE_NUM_CORE_CLKS, dw->core_clks);
-	if (ret) {
-		dev_err(dw->dev, "Enabling core clocks failed\n");
+	ret = reset_control_assert(dw->core_rsts[DW_PCIE_PWR_RST].rstc);
+	if (ret)
 		return ret;
-	}
 
-	if (!reset_control_status(dw->core_rsts[DW_PCIE_PWR_RST].rstc)) {
-		reset_control_assert(dw->core_rsts[DW_PCIE_PWR_RST].rstc);
-		/*
-		 * R-Car V4H Reference Manual R19UH0186EJ0130 Rev.1.30 Apr.
-		 * 21, 2025 page 585 Figure 9.3.2 Software Reset flow (B)
-		 * indicates that for peripherals in HSC domain, after
-		 * reset has been asserted by writing a matching reset bit
-		 * into register SRCR, it is mandatory to wait 1ms.
-		 */
-		fsleep(1000);
-	}
+	/*
+	 * R-Car V4H Reference Manual R19UH0186EJ0130 Rev.1.30 Apr.
+	 * 21, 2025 page 585 Figure 9.3.2 Software Reset flow (B)
+	 * indicates that for peripherals in HSC domain, after
+	 * reset has been asserted by writing a matching reset bit
+	 * into register SRCR, it is mandatory to wait 1ms.
+	 */
+	fsleep(1000);
 
 	val = readl(rcar->base + PCIEMSR0);
 	if (rcar->drvdata->mode == DW_PCIE_RC_TYPE) {
@@ -202,8 +197,7 @@ static int rcar_gen4_pcie_common_init(struct rcar_gen4_pcie *rcar)
 	} else if (rcar->drvdata->mode == DW_PCIE_EP_TYPE) {
 		val |= DEVICE_TYPE_EP;
 	} else {
-		ret = -EINVAL;
-		goto err_unprepare;
+		return -EINVAL;
 	}
 
 	if (dw->num_lanes < 4)
@@ -213,7 +207,7 @@ static int rcar_gen4_pcie_common_init(struct rcar_gen4_pcie *rcar)
 
 	ret = reset_control_deassert(dw->core_rsts[DW_PCIE_PWR_RST].rstc);
 	if (ret)
-		goto err_unprepare;
+		return ret;
 
 	/*
 	 * Assure the reset is latched and the core is ready for DBI access.
@@ -225,18 +219,16 @@ static int rcar_gen4_pcie_common_init(struct rcar_gen4_pcie *rcar)
 	 * synchronous one, and wait a little over 1ms to add additional
 	 * safety margin.
 	 */
-	reset_control_status(dw->core_rsts[DW_PCIE_PWR_RST].rstc);
+	ret = reset_control_status(dw->core_rsts[DW_PCIE_PWR_RST].rstc);
+	if (ret < 0)
+		return ret;
+
 	fsleep(1000);
 
 	if (rcar->drvdata->additional_common_init)
 		rcar->drvdata->additional_common_init(rcar);
 
 	return 0;
-
-err_unprepare:
-	clk_bulk_disable_unprepare(DW_PCIE_NUM_CORE_CLKS, dw->core_clks);
-
-	return ret;
 }
 
 static void rcar_gen4_pcie_common_deinit(struct rcar_gen4_pcie *rcar)
@@ -247,6 +239,18 @@ static void rcar_gen4_pcie_common_deinit(struct rcar_gen4_pcie *rcar)
 	clk_bulk_disable_unprepare(DW_PCIE_NUM_CORE_CLKS, dw->core_clks);
 }
 
+static int rcar_gen4_pcie_clk_enable(struct rcar_gen4_pcie *rcar)
+{
+	struct dw_pcie *dw = &rcar->dw;
+	int ret;
+
+	ret = clk_bulk_prepare_enable(DW_PCIE_NUM_CORE_CLKS, dw->core_clks);
+	if (ret)
+		dev_err(dw->dev, "Enabling core clocks failed\n");
+
+	return ret;
+}
+
 static int rcar_gen4_pcie_prepare(struct rcar_gen4_pcie *rcar)
 {
 	struct device *dev = rcar->dw.dev;
@@ -449,15 +453,12 @@ static int rcar_gen4_pcie_enable_device(struct pci_host_bridge *bridge,
 }
 
 /* Host mode */
-static int rcar_gen4_pcie_host_init(struct dw_pcie_rp *pp)
+static int rcar_gen4_pcie_host_hw_init(struct dw_pcie_rp *pp)
 {
 	struct dw_pcie *dw = to_dw_pcie_from_pp(pp);
 	struct rcar_gen4_pcie *rcar = to_rcar_gen4_pcie(dw);
 	int ret;
 
-	if (pp->bridge)
-		pp->bridge->enable_device = rcar_gen4_pcie_enable_device;
-
 	gpiod_set_value_cansleep(dw->pe_rst, 1);
 
 	ret = rcar_gen4_pcie_common_init(rcar);
@@ -475,13 +476,32 @@ static int rcar_gen4_pcie_host_init(struct dw_pcie_rp *pp)
 
 	ret = rcar_gen4_pcie_host_msi_init(pp);
 	if (ret)
-		goto err;
+		return ret;
 
 	msleep(PCIE_T_PVPERL_MS);	/* pe_rst requires 100msec delay */
-
 	gpiod_set_value_cansleep(dw->pe_rst, 0);
 
 	return 0;
+}
+
+static int rcar_gen4_pcie_host_init(struct dw_pcie_rp *pp)
+{
+	struct dw_pcie *dw = to_dw_pcie_from_pp(pp);
+	struct rcar_gen4_pcie *rcar = to_rcar_gen4_pcie(dw);
+	int ret;
+
+	if (pp->bridge)
+		pp->bridge->enable_device = rcar_gen4_pcie_enable_device;
+
+	ret = rcar_gen4_pcie_clk_enable(rcar);
+	if (ret)
+		return ret;
+
+	ret = rcar_gen4_pcie_host_hw_init(pp);
+	if (ret)
+		goto err;
+
+	return 0;
 
 err:
 	rcar_gen4_pcie_common_deinit(rcar);
@@ -529,10 +549,16 @@ static int rcar_gen4_pcie_ep_pre_init(struct dw_pcie_ep *ep)
 
 	writel(0, rcar->base + PCIEDMAINTSTSEN);
 
-	ret = rcar_gen4_pcie_common_init(rcar);
+	ret = rcar_gen4_pcie_clk_enable(rcar);
 	if (ret)
 		return ret;
 
+	ret = rcar_gen4_pcie_common_init(rcar);
+	if (ret) {
+		rcar_gen4_pcie_common_deinit(rcar);
+		return ret;
+	}
+
 	writel(PCIEDMAINTSTSEN_INIT, rcar->base + PCIEDMAINTSTSEN);
 
 	return 0;
-- 
2.51.0


  parent reply	other threads:[~2026-09-18  3:20 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-18  3:20 [PATCH 00/11] PCI: rcar-gen4: Recover from link down and route Root Port interrupts Koichiro Den
2026-09-18  3:20 ` [PATCH 01/11] PCI: dwc: Add Renesas to the RAS DES VSEC list Koichiro Den
2026-09-18  3:24   ` sashiko-bot
2026-09-22 19:40   ` Marek Vasut
2026-09-18  3:20 ` [PATCH 02/11] PCI: rcar-gen4: Drop the APP-based link_up check Koichiro Den
2026-09-18  3:25   ` sashiko-bot
2026-09-22 20:56   ` Marek Vasut
2026-09-23 14:56     ` Koichiro Den
2026-09-27 19:59       ` Marek Vasut
2026-09-28  4:20         ` Koichiro Den
2026-09-28 15:07           ` Marek Vasut
2026-09-18  3:20 ` [PATCH 03/11] dt-bindings: PCI: rcar-gen4: Add optional "aer" interrupt Koichiro Den
2026-09-18  3:25   ` sashiko-bot
2026-09-22 20:59   ` Marek Vasut
2026-09-28 18:32   ` Rob Herring (Arm)
2026-09-18  3:20 ` [PATCH 04/11] PCI: dwc: Add a host op to run before iMSI-RX status is read Koichiro Den
2026-09-18  3:32   ` sashiko-bot
2026-09-18  3:20 ` Koichiro Den [this message]
2026-09-18  3:27   ` [PATCH 05/11] PCI: rcar-gen4: Split reusable hardware initialization sashiko-bot
2026-09-22 21:15   ` Marek Vasut
2026-09-23 15:24     ` Koichiro Den
2026-09-27 20:43       ` Marek Vasut
2026-09-18  3:20 ` [PATCH 06/11] PCI: rcar-gen4: Add Root Port reset support Koichiro Den
2026-09-18  3:29   ` sashiko-bot
2026-09-22 21:22   ` Marek Vasut
2026-09-23 16:12     ` Koichiro Den
2026-09-27 22:25       ` Marek Vasut
2026-09-28  3:50         ` Koichiro Den
2026-09-28 17:47           ` Marek Vasut
2026-09-18  3:20 ` [PATCH 07/11] PCI: rcar-gen4: Recover the Root Port on link down Koichiro Den
2026-09-18  3:33   ` sashiko-bot
2026-09-22 21:44   ` Marek Vasut
2026-09-24 16:15     ` Koichiro Den
2026-09-27 22:37       ` Marek Vasut
2026-09-28  4:06         ` Koichiro Den
2026-09-28 17:36           ` Marek Vasut
2026-09-18  3:20 ` [PATCH 08/11] PCI: dwc: Let glue drivers hide the Root Port MSI capabilities Koichiro Den
2026-09-18  3:24   ` sashiko-bot
2026-09-18  3:20 ` [PATCH 09/11] PCI: rcar-gen4: Route Root Port AER to a virtual Root Port IRQ Koichiro Den
2026-09-18  3:32   ` sashiko-bot
2026-09-18  3:20 ` [PATCH 10/11] PCI: rcar-gen4: Route Root Port PME and bandwidth notifications Koichiro Den
2026-09-18  3:30   ` sashiko-bot
2026-09-18  3:20 ` [PATCH 11/11] arm64: dts: renesas: r8a779f0: Describe the PCIe AER interrupts Koichiro Den
2026-09-18  3:27   ` sashiko-bot
2026-09-22 21:31   ` Marek Vasut

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=20260918032038.2216471-6-den@valinux.co.jp \
    --to=den@valinux.co.jp \
    --cc=Frank.Li@nxp.com \
    --cc=bhelgaas@google.com \
    --cc=cassel@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=fancer.lancer@gmail.com \
    --cc=geert+renesas@glider.be \
    --cc=jingoohan1@gmail.com \
    --cc=krzk+dt@kernel.org \
    --cc=kwilczynski@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=lpieralisi@kernel.org \
    --cc=magnus.damm@gmail.com \
    --cc=mani@kernel.org \
    --cc=marek.vasut+renesas@mailbox.org \
    --cc=p.zabel@pengutronix.de \
    --cc=robh@kernel.org \
    --cc=wilfred.mallawa@wdc.com \
    --cc=yoshihiro.shimoda.uh@renesas.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