ipq806x: 6.1: manually refresh kernel patches
[openwrt/staging/stintel.git] / target / linux / ipq806x / patches-6.1 / 122-04-clk-qcom-krait-cc-rework-mux-reset-logic-and-reset-h.patch
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
5 hfpll
6
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
10 reset hfpll settings.
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.
14
15 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
16 ---
17 drivers/clk/qcom/krait-cc.c | 50 +++++++++++++++++--------------------
18 1 file changed, 23 insertions(+), 27 deletions(-)
19
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 {
25 clks_max,
26 };
27
28 -#define QSB_RATE 2250000000
29 +#define QSB_RATE 225000000
30 +#define AUX_RATE 384000000
31 +#define HFPLL_RATE 600000000
32
33 static unsigned int sec_mux_map[] = {
34 2,
35 @@ -317,7 +319,7 @@ static int krait_cc_probe(struct platform_device *pdev)
36 {
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;
41 int cpu;
42 struct clk *clk;
43 struct clk **clks;
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
46 * circumstances.
47 */
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;
53 - }
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";
61 + char cpu_s[5];
62 +
63 clk = clks[cpu];
64 + if (!clk)
65 + continue;
66 +
67 + if (cpu < 4)
68 + snprintf(cpu_s, 5, "CPU%d", cpu);
69 +
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;
78 }
79
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);
88 }
89
90 of_clk_add_provider(dev->of_node, krait_of_get, clks);
91
92