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+rene...@mailbox.org> --- Cc: Nobuhiro Iwamatsu <iwama...@nigauri.org> Cc: Tom Rini <tr...@konsulko.com> Cc: u-boot@lists.denx.de --- 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 41f0d958447..c02f8d6a12e 100644 --- a/drivers/pci/pci-rcar-gen4.c +++ b/drivers/pci/pci-rcar-gen4.c @@ -472,6 +472,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; } @@ -488,6 +492,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 * @@ -561,5 +585,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.51.0