pci: pcie-rcar-gen4: Shut down controller on link down and remove
authorMarek Vasut <marek.vasut+renesas@mailbox.org>
Thu, 18 Sep 2025 16:36:00 +0000 (18:36 +0200)
committerMarek Vasut <marek.vasut+renesas@mailbox.org>
Fri, 17 Oct 2025 19:53:52 +0000 (21:53 +0200)
In case the link is down, or the controller driver is removed before
booting the next stage, shut down the PCIe link, put both the remote
PCIe device and the controller into reset, and disable clock. This
way, the hardware is not left active when not in use.

Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
drivers/pci/pci-rcar-gen4.c

index 1f41ce2..e165271 100644 (file)
@@ -477,6 +477,10 @@ static int rcar_gen4_pcie_probe(struct udevice *dev)
 
        if (!rcar_gen4_pcie_link_up(rcar)) {
                printf("PCIE-%d: Link down\n", dev_seq(dev));
+               rcar_gen4_pcie_ltssm_control(rcar, false);
+               dm_gpio_set_value(&rcar->pe_rst, 1);
+               reset_assert(&rcar->pwr_rst);
+               clk_disable_unprepare(rcar->ref_clk);
                return -ENODEV;
        }
 
@@ -493,6 +497,26 @@ static int rcar_gen4_pcie_probe(struct udevice *dev)
        return 0;
 }
 
+/**
+ * rcar_gen4_pcie_remove() - Stop the PCIe bus active link
+ * @dev: A pointer to the device being operated on
+ *
+ * Stop an active link on the PCIe bus and deconfigure the controller.
+ *
+ * Return: 0 on success, else -ENODEV
+ */
+static int rcar_gen4_pcie_remove(struct udevice *dev)
+{
+       struct rcar_gen4_pcie *rcar = dev_get_priv(dev);
+
+       rcar_gen4_pcie_ltssm_control(rcar, false);
+       dm_gpio_set_value(&rcar->pe_rst, 1);
+       reset_assert(&rcar->pwr_rst);
+       clk_disable_unprepare(rcar->ref_clk);
+
+       return 0;
+}
+
 /**
  * rcar_gen4_pcie_of_to_plat() - Translate from DT to device state
  *
@@ -566,5 +590,7 @@ U_BOOT_DRIVER(rcar_gen4_pcie) = {
        .ops            = &rcar_gen4_pcie_ops,
        .of_to_plat     = rcar_gen4_pcie_of_to_plat,
        .probe          = rcar_gen4_pcie_probe,
+       .remove         = rcar_gen4_pcie_remove,
        .priv_auto      = sizeof(struct rcar_gen4_pcie),
+       .flags          = DM_FLAG_ACTIVE_DMA,
 };