From bdb901f2aeaf8342d2c5109ba66728cbf985e093 Mon Sep 17 00:00:00 2001 From: Dmitry Baryshkov Date: Wed, 18 Jan 2023 07:19:49 +0200 Subject: [PATCH] debugcc: split measurement function Split measurement function into clock rate calculation (measure_default()) and the wrapper that prepares muxes and then disables them. This fixes the issue that muxes will not be disabled for the clocks that are not turned off (because measure function will return early for disabled clocks). Signed-off-by: Dmitry Baryshkov --- debugcc.c | 65 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 25 deletions(-) diff --git a/debugcc.c b/debugcc.c index 7f4bd57..b12d62a 100644 --- a/debugcc.c +++ b/debugcc.c @@ -145,13 +145,46 @@ static bool leaf_enabled(struct debug_mux *mux, struct debug_mux *leaf) return !val; } -static void measure(const struct measure_clk *clk) +static unsigned long measure_default(const struct measure_clk *clk) { unsigned long raw_count_short; unsigned long raw_count_full; struct debug_mux *gcc = clk->primary; unsigned long xo_div4; + xo_div4 = readl(gcc->base + gcc->xo_div4_reg); + writel(xo_div4 | 1, gcc->base + gcc->xo_div4_reg); + + raw_count_short = measure_ticks(gcc, 0x1000); + raw_count_full = measure_ticks(gcc, 0x10000); + + writel(xo_div4, gcc->base + gcc->xo_div4_reg); + + if (raw_count_full == raw_count_short) { + return 0; + } + + raw_count_full = ((raw_count_full * 10) + 15) * 4800000; + raw_count_full = raw_count_full / ((0x10000 * 10) + 35); + + if (clk->leaf && clk->leaf->div_val) + raw_count_full *= clk->leaf->div_val; + + if (clk->primary->div_val) + raw_count_full *= clk->primary->div_val; + + if (clk->fixed_div) + raw_count_full *= clk->fixed_div; + + + return raw_count_full; +} + +static void measure(const struct measure_clk *clk) +{ + unsigned long clk_rate; + struct debug_mux *gcc = clk->primary; + if (!leaf_enabled(gcc, clk->leaf)) { printf("%50s: skipping\n", clk->name); return; @@ -162,37 +195,19 @@ static void measure(const struct measure_clk *clk) mux_prepare_enable(clk->primary, clk->mux); - xo_div4 = readl(gcc->base + gcc->xo_div4_reg); - writel(xo_div4 | 1, gcc->base + gcc->xo_div4_reg); - - raw_count_short = measure_ticks(gcc, 0x1000); - raw_count_full = measure_ticks(gcc, 0x10000); - - writel(xo_div4, gcc->base + gcc->xo_div4_reg); - - if (raw_count_full == raw_count_short) { - printf("%50s: off\n", clk->name); - return; - } - - raw_count_full = ((raw_count_full * 10) + 15) * 4800000; - raw_count_full = raw_count_full / ((0x10000 * 10) + 35); + clk_rate = measure_default(clk); mux_disable(clk->primary); if (clk->leaf) mux_disable(clk->leaf); - if (clk->leaf && clk->leaf->div_val) - raw_count_full *= clk->leaf->div_val; + if (clk_rate == 0) { + printf("%50s: off\n", clk->name); + return; + } - if (clk->primary->div_val) - raw_count_full *= clk->primary->div_val; - - if (clk->fixed_div) - raw_count_full *= clk->fixed_div; - - printf("%50s: %fMHz (%ldHz)\n", clk->name, raw_count_full / 1000000.0, raw_count_full); + printf("%50s: %fMHz (%ldHz)\n", clk->name, clk_rate / 1000000.0, clk_rate); } static const struct debugcc_platform *find_platform(const char *name)