[PATCH 09/11] PCI: tegra194: Balance core monitor clock on failures
From: Manikanta Maddireddy
Date: Wed Sep 23 2026 - 03:30:45 EST
tegra_pcie_dw_host_init() enables core_clk_m, but failure paths that leave
after the host init callback can unconfigure the controller without
disabling that clock. The enable error is also only logged, so later
cleanup can try to disable a clock that was never enabled.
Track the monitor clock state, return enable failures, and use a common
helper on retry, remove, suspend, shutdown and host-init failure paths so
the clock is disabled exactly when it was enabled.
Fixes: a86ca8698c88 ("PCI: tegra194: Add core monitor clock support")
Signed-off-by: Manikanta Maddireddy <mmaddireddy@xxxxxxxxxx>
---
drivers/pci/controller/dwc/pcie-tegra194.c | 33 ++++++++++++++++++----
1 file changed, 27 insertions(+), 6 deletions(-)
diff --git a/drivers/pci/controller/dwc/pcie-tegra194.c b/drivers/pci/controller/dwc/pcie-tegra194.c
index 637779993c40..9b337dbada70 100644
--- a/drivers/pci/controller/dwc/pcie-tegra194.c
+++ b/drivers/pci/controller/dwc/pcie-tegra194.c
@@ -246,6 +246,7 @@ struct tegra_pcie_dw {
void __iomem *appl_base;
struct clk *core_clk;
struct clk *core_clk_m;
+ bool core_clk_m_enabled;
struct reset_control *core_apb_rst;
struct reset_control *core_rst;
struct dw_pcie pci;
@@ -855,6 +856,15 @@ static void tegra_pcie_enable_interrupts(struct dw_pcie_rp *pp)
tegra_pcie_enable_msi_interrupts(pp);
}
+static void tegra_pcie_disable_core_clk_m(struct tegra_pcie_dw *pcie)
+{
+ if (!pcie->core_clk_m_enabled)
+ return;
+
+ clk_disable_unprepare(pcie->core_clk_m);
+ pcie->core_clk_m_enabled = false;
+}
+
static void config_gen3_gen4_eq_presets(struct tegra_pcie_dw *pcie)
{
struct dw_pcie *pci = &pcie->pci;
@@ -914,6 +924,7 @@ static int tegra_pcie_dw_host_init(struct dw_pcie_rp *pp)
struct tegra_pcie_dw *pcie = to_tegra_pcie(pci);
u32 val;
u16 val_16;
+ int ret;
pp->bridge->ops = &tegra_pci_ops;
@@ -965,8 +976,12 @@ static int tegra_pcie_dw_host_init(struct dw_pcie_rp *pp)
}
clk_set_rate(pcie->core_clk, GEN4_CORE_CLK_FREQ);
- if (clk_prepare_enable(pcie->core_clk_m))
- dev_err(pci->dev, "Failed to enable core monitor clock\n");
+ ret = clk_prepare_enable(pcie->core_clk_m);
+ if (ret) {
+ dev_err(pci->dev, "Failed to enable core monitor clock: %d\n", ret);
+ return ret;
+ }
+ pcie->core_clk_m_enabled = true;
return 0;
}
@@ -1049,8 +1064,11 @@ static int tegra_pcie_dw_start_link(struct dw_pcie *pci)
* dw_pcie_host_init(). Disable the clock since below
* tegra_pcie_dw_host_init() will enable it again.
*/
- clk_disable_unprepare(pcie->core_clk_m);
- tegra_pcie_dw_host_init(pp);
+ tegra_pcie_disable_core_clk_m(pcie);
+ ret = tegra_pcie_dw_host_init(pp);
+ if (ret)
+ return ret;
+
dw_pcie_setup_rc(pp);
retry = false;
@@ -1565,6 +1583,7 @@ static int tegra_pcie_init_controller(struct tegra_pcie_dw *pcie)
return 0;
fail_host_init:
+ tegra_pcie_disable_core_clk_m(pcie);
tegra_pcie_unconfig_controller(pcie);
return ret;
}
@@ -1653,7 +1672,7 @@ static void tegra_pcie_dw_pme_turnoff(struct tegra_pcie_dw *pcie)
static void tegra_pcie_deinit_controller(struct tegra_pcie_dw *pcie)
{
- clk_disable_unprepare(pcie->core_clk_m);
+ tegra_pcie_disable_core_clk_m(pcie);
dw_pcie_host_deinit(&pcie->pci.pp);
tegra_pcie_dw_pme_turnoff(pcie);
tegra_pcie_unconfig_controller(pcie);
@@ -2450,7 +2469,7 @@ static int tegra_pcie_dw_suspend_noirq(struct device *dev)
if (!pcie->link_state)
return 0;
- clk_disable_unprepare(pcie->core_clk_m);
+ tegra_pcie_disable_core_clk_m(pcie);
tegra_pcie_dw_pme_turnoff(pcie);
tegra_pcie_unconfig_controller(pcie);
@@ -2487,6 +2506,7 @@ static int tegra_pcie_dw_resume_noirq(struct device *dev)
return 0;
fail_host_init:
+ tegra_pcie_disable_core_clk_m(pcie);
tegra_pcie_unconfig_controller(pcie);
return ret;
}
@@ -2528,6 +2548,7 @@ static void tegra_pcie_dw_shutdown(struct platform_device *pdev)
if (IS_ENABLED(CONFIG_PCI_MSI))
disable_irq(pcie->pci.pp.msi_irq[0]);
+ tegra_pcie_disable_core_clk_m(pcie);
tegra_pcie_dw_pme_turnoff(pcie);
tegra_pcie_unconfig_controller(pcie);
pm_runtime_put_sync(pcie->dev);
--
2.34.1