From 2b634a80b5ce92232f309fdd7d7864098ca7fb95 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Thu, 18 Sep 2025 18:36:00 +0200 Subject: [PATCH] pci: pcie-rcar-gen4: Shut down controller on link down and remove 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 --- drivers/pci/pci-rcar-gen4.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/pci/pci-rcar-gen4.c b/drivers/pci/pci-rcar-gen4.c index 1f41ce28b0b..e165271f58c 100644 --- a/drivers/pci/pci-rcar-gen4.c +++ b/drivers/pci/pci-rcar-gen4.c @@ -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, }; -- 2.47.3