aboutsummaryrefslogtreecommitdiff
path: root/drivers/clk
diff options
context:
space:
mode:
authorChristian Marangi <ansuelsmth@gmail.com>2024-06-28 19:40:46 +0200
committerTom Rini <trini@konsulko.com>2024-08-01 15:32:18 -0600
commited908c486827536a36aa236bb622a90408603e57 (patch)
tree2c5d114b84661ef6f0328b5b7a6992397d42e2d2 /drivers/clk
parent8937bb265a7f2251c1bd999784a4ef10e9c6080d (diff)
downloadu-boot-ed908c486827536a36aa236bb622a90408603e57.zip
u-boot-ed908c486827536a36aa236bb622a90408603e57.tar.gz
u-boot-ed908c486827536a36aa236bb622a90408603e57.tar.bz2
clk: mediatek: return XTAL rate directly for gates with XTAL parent
There is currently a massive bug that makes any gate clk that have CLK_XTAL as parent to return the wrong clock. Following the code, with CLK_XTAL defined as TOPCKGEN parent, the topckgen get_rate is called. The clk ID (0) is parsed and only in some corner case (scenario where fixed clock are not defined) the correct XTAL rate will be returned as get_factor or get_mux is called (that have correct handling for CLK_XTAL). With fixed clock defined, the rate that will be returned will always be the FIRST ELEMENT of the fixed clock table instead of the hardcoded XTAL rate. To handle this, add additional logic and if the flag is set to PARENT_XTAL for the gate, return the XTAL rate directly. We assume the clk_tree to have xtal_rate defined with clk gates that have XTAL as parents. Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
Diffstat (limited to 'drivers/clk')
-rw-r--r--drivers/clk/mediatek/clk-mtk.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c
index 4303300..3977f38 100644
--- a/drivers/clk/mediatek/clk-mtk.c
+++ b/drivers/clk/mediatek/clk-mtk.c
@@ -544,6 +544,13 @@ static ulong mtk_clk_gate_get_rate(struct clk *clk)
struct mtk_cg_priv *priv = dev_get_priv(clk->dev);
const struct mtk_gate *gate = &priv->gates[clk->id];
+ /*
+ * Assume xtal_rate to be declared if some gates have
+ * XTAL as parent
+ */
+ if (gate->flags & CLK_PARENT_XTAL)
+ return priv->tree->xtal_rate;
+
return mtk_clk_find_parent_rate(clk, gate->parent, priv->parent);
}