1 From 6a77cf3f5f95ec0058e1b4d1ada018748cb0b83b Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Thu, 15 Sep 2022 03:33:13 +0200
4 Subject: [PATCH 9/9] clk: qcom: krait-cc: rework mux reset logic and reset
7 Rework and clean mux reset logic.
8 Compact it to a for loop to handle both CPU and L2 in one place.
9 Move hardcoded aux_rate to define and add a new hfpll_rate value to
11 Change logic to now reset the hfpll to the lowest value of 600 Mhz and
12 then restoring the previous frequency. This permits to reset the hfpll if
13 the primary mux was set to source out of the secondary mux.
15 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
17 drivers/clk/qcom/krait-cc.c | 50 +++++++++++++++++--------------------
18 1 file changed, 23 insertions(+), 27 deletions(-)
20 diff --git a/drivers/clk/qcom/krait-cc.c b/drivers/clk/qcom/krait-cc.c
21 index 717eff44b6a4..90dee71e7c38 100644
22 --- a/drivers/clk/qcom/krait-cc.c
23 +++ b/drivers/clk/qcom/krait-cc.c
24 @@ -25,7 +25,9 @@ enum {
28 -#define QSB_RATE 2250000000
29 +#define QSB_RATE 225000000
30 +#define AUX_RATE 384000000
31 +#define HFPLL_RATE 600000000
33 static unsigned int sec_mux_map[] = {
35 @@ -317,7 +319,7 @@ static int krait_cc_probe(struct platform_device *pdev)
37 struct device *dev = &pdev->dev;
38 const struct of_device_id *id;
39 - unsigned long cur_rate, aux_rate, qsb_rate;
40 + unsigned long cur_rate, qsb_rate;
44 @@ -397,28 +399,29 @@ static int krait_cc_probe(struct platform_device *pdev)
45 * two different rates to force a HFPLL reinit under all
48 - cur_rate = clk_get_rate(clks[l2_mux]);
49 - aux_rate = 384000000;
50 - if (cur_rate < aux_rate) {
51 - dev_info(dev, "L2 @ Undefined rate. Forcing new rate.\n");
52 - cur_rate = aux_rate;
54 - clk_set_rate(clks[l2_mux], aux_rate);
55 - clk_set_rate(clks[l2_mux], 2);
56 - clk_set_rate(clks[l2_mux], cur_rate);
57 - dev_info(dev, "L2 @ %lu KHz\n", clk_get_rate(clks[l2_mux]) / 1000);
58 - for_each_possible_cpu(cpu) {
59 + for (cpu = 0; cpu < 5; cpu++) {
60 + const char *l2_s = "L2";
68 + snprintf(cpu_s, 5, "CPU%d", cpu);
70 cur_rate = clk_get_rate(clk);
71 - if (cur_rate < aux_rate) {
72 - dev_info(dev, "CPU%d @ Undefined rate. Forcing new rate.\n", cpu);
73 - cur_rate = aux_rate;
74 + if (cur_rate < AUX_RATE) {
75 + dev_info(dev, "%s @ Undefined rate. Forcing new rate.\n",
76 + cpu < 4 ? cpu_s : l2_s);
77 + cur_rate = AUX_RATE;
80 - clk_set_rate(clk, aux_rate);
81 - clk_set_rate(clk, 2);
82 + clk_set_rate(clk, AUX_RATE);
83 + clk_set_rate(clk, HFPLL_RATE);
84 clk_set_rate(clk, cur_rate);
85 - dev_info(dev, "CPU%d @ %lu KHz\n", cpu, clk_get_rate(clk) / 1000);
86 + dev_info(dev, "%s @ %lu KHz\n", cpu < 4 ? cpu_s : l2_s,
87 + clk_get_rate(clk) / 1000);
90 of_clk_add_provider(dev->of_node, krait_of_get, clks);