[v3,01/26] clk: ccf: enable the critical clocks when they are registered

Message ID 20261202102716.572884-2-dario.binacchi@amarulasolutions.com
State New
Headers
Series Support display on the BSH SMM S2/PRO boards |

Commit Message

Dario Binacchi Dec. 2, 2026, 10:26 a.m. UTC
CLK_IS_CRITICAL only prevents clk_disable() from gating a clock. Since
nobody enables a critical clock, its parents don't account for it, and
a parent shared with other clocks is disabled as soon as its last
non-critical user goes away, e.g. on reparenting. On the i.MX8MN this
turns SYS_PLL2 off while the display clocks are set up, and the system
hangs.

Enable the critical clocks as soon as they get an ID, as Linux does at
registration, so that their whole parent chain is accounted for.

Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
---

(no changes since v2)

Changes in v2:
- Add patch, replacing "clk: imx8mn: Mark IMX8MN_SYS_PLL2 and
  IMX8MN_SYS_PLL3 as enabled" with a generic solution

 drivers/clk/clk.c            | 15 +++++++++++++++
 include/linux/clk-provider.h | 12 ++++++++++--
 2 files changed, 25 insertions(+), 2 deletions(-)
  

Patch

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index b8c2e8d531b9..1e735c8fb2b4 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -13,6 +13,21 @@ 
 #include <dm/uclass.h>
 #include <dm/lists.h>
 #include <dm/device-internal.h>
+#include <linux/clk-provider.h>
+
+/* Let the parents of a critical clock account for it, as Linux does */
+void clk_enable_critical(struct clk *clk)
+{
+	int ret;
+
+	if (!(clk->flags & CLK_IS_CRITICAL))
+		return;
+
+	ret = clk_enable(clk);
+	if (ret)
+		log_warning("%s: failed to enable critical clock %s (%d)\n",
+			    __func__, clk->dev->name, ret);
+}
 
 int clk_register(struct clk *clk, const char *drv_name,
 		 const char *name, const char *parent_name)
diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
index 366f2d968a33..c09f56b2b57d 100644
--- a/include/linux/clk-provider.h
+++ b/include/linux/clk-provider.h
@@ -15,17 +15,25 @@ 
 
 struct udevice;
 
+void clk_enable_critical(struct clk *clk);
+
 /* update clock ID for the dev = clock provider, compatible with CLK_AUTO_ID */
 static inline void dev_clk_dm(const struct udevice *dev, ulong id, struct clk *clk)
 {
-	if (!IS_ERR(clk))
+	if (!IS_ERR(clk)) {
 		clk->id = CLK_ID(dev, id);
+		if (CONFIG_IS_ENABLED(CLK_CCF))
+			clk_enable_critical(clk);
+	}
 }
 
 static inline void clk_dm(ulong id, struct clk *clk)
 {
-	if (!IS_ERR(clk))
+	if (!IS_ERR(clk)) {
 		clk->id = CLK_ID(clk->dev, id);
+		if (CONFIG_IS_ENABLED(CLK_CCF))
+			clk_enable_critical(clk);
+	}
 }
 
 /*