U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] clk: spacemit: k1: Use generic CCF enable/disable callbacks
@ 2026-11-24  7:38 Junhui Liu
  2026-11-24 10:36 ` Yixun Lan
  0 siblings, 1 reply; 2+ messages in thread
From: Junhui Liu @ 2026-11-24  7:38 UTC (permalink / raw)
  To: u-boot; +Cc: Lukasz Majewski, Yixun Lan, Tom Rini, Junhui Liu, Anand Moon

The custom enable/disable callbacks look up the requested clock in the
provider's clock table, handle its parent and call the gate operations
directly. If the ID is not found, they still use the caller's struct clk
as a hardware clock. The gate operations then interpret it as part of a
struct ccu_mix and access invalid register mapping data, which can cause
a load access fault.

These callbacks provide no K1-specific sequencing. CCF already handles
clock lookup, parents and reference counts, and dispatches hardware
operations through the registered clock's callbacks.

Use ccf_clk_enable() and ccf_clk_disable() to look up the registered
clock by ID and delegate to clk_enable() and clk_disable(). Return an
error for an unregistered ID instead of accessing an invalid hardware
clock object.

Fixes: 3aa2882a3e1 ("clk: spacemit: Add support for K1 SoC")
Signed-off-by: Junhui Liu <junhui.liu@pigmoral.tech>
---
I found this while testing SPL pinctrl support on a K1 board with
Anand's GPIO/pinctrl SPL support series [1]. CLK_AIB and CLK_AIB_BUS,
which the pinctrl controller requires, are not registered in SPL.
After retaining the SD pin configuration nodes in the SPL device tree
and attempting to boot from SD, enabling these missing clocks caused
SPL to crash.

The custom callbacks crashed without indicating what operation had
failed:

  Trying to boot from MMC2
  Unhandled exception: Load access fault
  EPC: 00000000c080a378 RA: 00000000c080a4f6 TVAL: 0000006b0000306e

With the generic CCF callbacks, the same test returns an error instead
of crashing and reports:

  Trying to boot from MMC2
  Enable system-controller@d4015000 failed
  spacemit_pinctrl pinctrl@d401e000: Fail to enable bulk clks

This makes the clock enable failure visible. The missing SPL AIB clocks
need to be added separately. This patch only fixes the callbacks.

[1] https://lore.kernel.org/u-boot/20261123193714.5096-1-linux.amoon@gmail.com/
---
 drivers/clk/spacemit/clk-k1.c | 58 ++-----------------------------------------
 1 file changed, 2 insertions(+), 56 deletions(-)

diff --git a/drivers/clk/spacemit/clk-k1.c b/drivers/clk/spacemit/clk-k1.c
index 20b8595aa3c..ae2bdcbd18a 100644
--- a/drivers/clk/spacemit/clk-k1.c
+++ b/drivers/clk/spacemit/clk-k1.c
@@ -1501,66 +1501,12 @@ static struct clk *k1_ccu_apmu_clks[] = {
 };
 #endif
 
-static int clk_k1_enable(struct clk *clk)
-{
-	const struct spacemit_ccu_data *data;
-	struct clk *c;
-	struct clk *pclk;
-	int ret, i;
-
-	data = (struct spacemit_ccu_data *)dev_get_driver_data(clk->dev);
-	for (i = 0; i < data->num; i++) {
-		if (clk->id == data->clks[i]->id) {
-			c = data->clks[i];
-			break;
-		}
-	}
-	if (i == data->num)
-		c = clk;
-
-	pclk = clk_get_parent(c);
-	if (!IS_ERR_OR_NULL(pclk)) {
-		ret = ccf_clk_enable(pclk);
-		if (ret)
-			return ret;
-	}
-	ret = ccu_gate_enable(c);
-	return ret;
-}
-
-static int clk_k1_disable(struct clk *clk)
-{
-	const struct spacemit_ccu_data *data;
-	struct clk *c;
-	struct clk *pclk;
-	int ret, i;
-
-	data = (struct spacemit_ccu_data *)dev_get_driver_data(clk->dev);
-	for (i = 0; i < data->num; i++) {
-		if (clk->id == data->clks[i]->id) {
-			c = data->clks[i];
-			break;
-		}
-	}
-	if (i == data->num)
-		c = clk;
-
-	pclk = clk_get_parent(c);
-	if (!IS_ERR_OR_NULL(pclk)) {
-		ret = ccf_clk_disable(pclk);
-		if (ret)
-			return ret;
-	}
-	ret = ccu_gate_disable(c);
-	return ret;
-}
-
 #define K1_CLK_OPS(name)				\
 static const struct clk_ops k1_##name##_clk_ops = {	\
 		.set_rate = ccf_clk_set_rate,		\
 		.get_rate = ccf_clk_get_rate,		\
-		.enable = clk_k1_enable,		\
-		.disable = clk_k1_disable,		\
+		.enable = ccf_clk_enable,		\
+		.disable = ccf_clk_disable,		\
 		.set_parent = ccf_clk_set_parent,	\
 		.of_xlate = k1_##name##_clk_of_xlate,	\
 }

---
base-commit: ee1b3477e3af6af1ae9b8f98bc84d2cc6f32a3a6
change-id: 20261124-k1-clk-fix-f918f7b26001

Best regards,
--  
Junhui Liu <junhui.liu@pigmoral.tech>


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-24 10:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24  7:38 [PATCH] clk: spacemit: k1: Use generic CCF enable/disable callbacks Junhui Liu
2026-11-24 10:36 ` Yixun Lan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox