base-files: reduce IPv6 ULA prefix generation to a single call
[openwrt/staging/stintel.git] / target / linux / ipq806x / patches-6.1 / 122-05-clk-qcom-clk-krait-generilize-div-functions.patch
1 From 908c361b3c3a139eb3e6a798cb620a6da7514d5c Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Fri, 23 Sep 2022 19:05:39 +0200
4 Subject: [PATCH 2/4] clk: qcom: clk-krait: generilize div functions
5
6 Generilize div functions and remove hardcode to a divisor of 2.
7 This is just a cleanup and permit to make it more clear the settings of
8 the devisor when used by the krait-cc driver.
9
10 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
11 ---
12 drivers/clk/qcom/clk-krait.c | 57 ++++++++++++++++++++----------------
13 drivers/clk/qcom/clk-krait.h | 11 ++++---
14 drivers/clk/qcom/krait-cc.c | 7 +++--
15 3 files changed, 42 insertions(+), 33 deletions(-)
16
17 --- a/drivers/clk/qcom/clk-krait.c
18 +++ b/drivers/clk/qcom/clk-krait.c
19 @@ -97,53 +97,58 @@ const struct clk_ops krait_mux_clk_ops =
20 EXPORT_SYMBOL_GPL(krait_mux_clk_ops);
21
22 /* The divider can divide by 2, 4, 6 and 8. But we only really need div-2. */
23 -static long krait_div2_round_rate(struct clk_hw *hw, unsigned long rate,
24 +static long krait_div_round_rate(struct clk_hw *hw, unsigned long rate,
25 unsigned long *parent_rate)
26 {
27 - *parent_rate = clk_hw_round_rate(clk_hw_get_parent(hw), rate * 2);
28 - return DIV_ROUND_UP(*parent_rate, 2);
29 + struct krait_div_clk *d = to_krait_div_clk(hw);
30 +
31 + *parent_rate = clk_hw_round_rate(clk_hw_get_parent(hw),
32 + rate * d->divisor);
33 +
34 + return DIV_ROUND_UP(*parent_rate, d->divisor);
35 }
36
37 -static int krait_div2_set_rate(struct clk_hw *hw, unsigned long rate,
38 +static int krait_div_set_rate(struct clk_hw *hw, unsigned long rate,
39 unsigned long parent_rate)
40 {
41 - struct krait_div2_clk *d = to_krait_div2_clk(hw);
42 + struct krait_div_clk *d = to_krait_div_clk(hw);
43 + u8 div_val = krait_div_to_val(d->divisor);
44 unsigned long flags;
45 - u32 val;
46 - u32 mask = BIT(d->width) - 1;
47 -
48 - if (d->lpl)
49 - mask = mask << (d->shift + LPL_SHIFT) | mask << d->shift;
50 - else
51 - mask <<= d->shift;
52 + u32 regval;
53
54 spin_lock_irqsave(&krait_clock_reg_lock, flags);
55 - val = krait_get_l2_indirect_reg(d->offset);
56 - val &= ~mask;
57 - krait_set_l2_indirect_reg(d->offset, val);
58 + regval = krait_get_l2_indirect_reg(d->offset);
59 +
60 + regval &= ~(d->mask << d->shift);
61 + regval |= (div_val & d->mask) << d->shift;
62 +
63 + if (d->lpl) {
64 + regval &= ~(d->mask << (d->shift + LPL_SHIFT));
65 + regval |= (div_val & d->mask) << (d->shift + LPL_SHIFT);
66 + }
67 +
68 + krait_set_l2_indirect_reg(d->offset, regval);
69 spin_unlock_irqrestore(&krait_clock_reg_lock, flags);
70
71 return 0;
72 }
73
74 static unsigned long
75 -krait_div2_recalc_rate(struct clk_hw *hw, unsigned long parent_rate)
76 +krait_div_recalc_rate(struct clk_hw *hw, unsigned long parent_rate)
77 {
78 - struct krait_div2_clk *d = to_krait_div2_clk(hw);
79 - u32 mask = BIT(d->width) - 1;
80 + struct krait_div_clk *d = to_krait_div_clk(hw);
81 u32 div;
82
83 div = krait_get_l2_indirect_reg(d->offset);
84 div >>= d->shift;
85 - div &= mask;
86 - div = (div + 1) * 2;
87 + div &= d->mask;
88
89 - return DIV_ROUND_UP(parent_rate, div);
90 + return DIV_ROUND_UP(parent_rate, krait_val_to_div(div));
91 }
92
93 -const struct clk_ops krait_div2_clk_ops = {
94 - .round_rate = krait_div2_round_rate,
95 - .set_rate = krait_div2_set_rate,
96 - .recalc_rate = krait_div2_recalc_rate,
97 +const struct clk_ops krait_div_clk_ops = {
98 + .round_rate = krait_div_round_rate,
99 + .set_rate = krait_div_set_rate,
100 + .recalc_rate = krait_div_recalc_rate,
101 };
102 -EXPORT_SYMBOL_GPL(krait_div2_clk_ops);
103 +EXPORT_SYMBOL_GPL(krait_div_clk_ops);
104 --- a/drivers/clk/qcom/clk-krait.h
105 +++ b/drivers/clk/qcom/clk-krait.h
106 @@ -25,17 +25,20 @@ struct krait_mux_clk {
107
108 extern const struct clk_ops krait_mux_clk_ops;
109
110 -struct krait_div2_clk {
111 +struct krait_div_clk {
112 u32 offset;
113 - u8 width;
114 + u32 mask;
115 + u8 divisor;
116 u32 shift;
117 bool lpl;
118
119 struct clk_hw hw;
120 };
121
122 -#define to_krait_div2_clk(_hw) container_of(_hw, struct krait_div2_clk, hw)
123 +#define to_krait_div_clk(_hw) container_of(_hw, struct krait_div_clk, hw)
124 +#define krait_div_to_val(_div) ((_div) / 2) - 1
125 +#define krait_val_to_div(_val) ((_val) + 1) * 2
126
127 -extern const struct clk_ops krait_div2_clk_ops;
128 +extern const struct clk_ops krait_div_clk_ops;
129
130 #endif
131 --- a/drivers/clk/qcom/krait-cc.c
132 +++ b/drivers/clk/qcom/krait-cc.c
133 @@ -86,11 +86,11 @@ static int krait_notifier_register(struc
134 static struct clk_hw *
135 krait_add_div(struct device *dev, int id, const char *s, unsigned int offset)
136 {
137 - struct krait_div2_clk *div;
138 + struct krait_div_clk *div;
139 static struct clk_parent_data p_data[1];
140 struct clk_init_data init = {
141 .num_parents = ARRAY_SIZE(p_data),
142 - .ops = &krait_div2_clk_ops,
143 + .ops = &krait_div_clk_ops,
144 .flags = CLK_SET_RATE_PARENT,
145 };
146 struct clk_hw *clk;
147 @@ -101,7 +101,8 @@ krait_add_div(struct device *dev, int id
148 if (!div)
149 return ERR_PTR(-ENOMEM);
150
151 - div->width = 2;
152 + div->mask = 0x3;
153 + div->divisor = 2;
154 div->shift = 6;
155 div->lpl = id >= 0;
156 div->offset = offset;