forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-02-20 e636c8d336489bf3eed5878299e6cc045bbad077
kernel/drivers/clk/socfpga/clk-pll-s10.c
....@@ -4,6 +4,7 @@
44 */
55 #include <linux/slab.h>
66 #include <linux/clk-provider.h>
7
+#include <linux/io.h>
78
89 #include "stratix10-clk.h"
910 #include "clk.h"
....@@ -17,14 +18,39 @@
1718 #define SOCFPGA_PLL_RESET_MASK 0x2
1819 #define SOCFPGA_PLL_REFDIV_MASK 0x00003F00
1920 #define SOCFPGA_PLL_REFDIV_SHIFT 8
21
+#define SOCFPGA_PLL_AREFDIV_MASK 0x00000F00
22
+#define SOCFPGA_PLL_DREFDIV_MASK 0x00003000
23
+#define SOCFPGA_PLL_DREFDIV_SHIFT 12
2024 #define SOCFPGA_PLL_MDIV_MASK 0xFF000000
2125 #define SOCFPGA_PLL_MDIV_SHIFT 24
26
+#define SOCFPGA_AGILEX_PLL_MDIV_MASK 0x000003FF
2227 #define SWCTRLBTCLKSEL_MASK 0x200
2328 #define SWCTRLBTCLKSEL_SHIFT 9
2429
2530 #define SOCFPGA_BOOT_CLK "boot_clk"
2631
2732 #define to_socfpga_clk(p) container_of(p, struct socfpga_pll, hw.hw)
33
+
34
+static unsigned long agilex_clk_pll_recalc_rate(struct clk_hw *hwclk,
35
+ unsigned long parent_rate)
36
+{
37
+ struct socfpga_pll *socfpgaclk = to_socfpga_clk(hwclk);
38
+ unsigned long arefdiv, reg, mdiv;
39
+ unsigned long long vco_freq;
40
+
41
+ /* read VCO1 reg for numerator and denominator */
42
+ reg = readl(socfpgaclk->hw.reg);
43
+ arefdiv = (reg & SOCFPGA_PLL_AREFDIV_MASK) >> SOCFPGA_PLL_REFDIV_SHIFT;
44
+
45
+ vco_freq = (unsigned long long)parent_rate / arefdiv;
46
+
47
+ /* Read mdiv and fdiv from the fdbck register */
48
+ reg = readl(socfpgaclk->hw.reg + 0x24);
49
+ mdiv = reg & SOCFPGA_AGILEX_PLL_MDIV_MASK;
50
+
51
+ vco_freq = (unsigned long long)vco_freq * mdiv;
52
+ return (unsigned long)vco_freq;
53
+}
2854
2955 static unsigned long clk_pll_recalc_rate(struct clk_hw *hwclk,
3056 unsigned long parent_rate)
....@@ -97,31 +123,37 @@
97123 return 0;
98124 }
99125
100
-static struct clk_ops clk_pll_ops = {
126
+static const struct clk_ops agilex_clk_pll_ops = {
127
+ .recalc_rate = agilex_clk_pll_recalc_rate,
128
+ .get_parent = clk_pll_get_parent,
129
+ .prepare = clk_pll_prepare,
130
+};
131
+
132
+static const struct clk_ops clk_pll_ops = {
101133 .recalc_rate = clk_pll_recalc_rate,
102134 .get_parent = clk_pll_get_parent,
103135 .prepare = clk_pll_prepare,
104136 };
105137
106
-static struct clk_ops clk_boot_ops = {
138
+static const struct clk_ops clk_boot_ops = {
107139 .recalc_rate = clk_boot_clk_recalc_rate,
108140 .get_parent = clk_boot_get_parent,
109141 .prepare = clk_pll_prepare,
110142 };
111143
112
-struct clk *s10_register_pll(const char *name, const char * const *parent_names,
113
- u8 num_parents, unsigned long flags,
114
- void __iomem *reg, unsigned long offset)
144
+struct clk *s10_register_pll(const struct stratix10_pll_clock *clks,
145
+ void __iomem *reg)
115146 {
116147 struct clk *clk;
117148 struct socfpga_pll *pll_clk;
118
- struct clk_init_data init = {};
149
+ struct clk_init_data init;
150
+ const char *name = clks->name;
119151
120152 pll_clk = kzalloc(sizeof(*pll_clk), GFP_KERNEL);
121153 if (WARN_ON(!pll_clk))
122154 return NULL;
123155
124
- pll_clk->hw.reg = reg + offset;
156
+ pll_clk->hw.reg = reg + clks->offset;
125157
126158 if (streq(name, SOCFPGA_BOOT_CLK))
127159 init.ops = &clk_boot_ops;
....@@ -129,15 +161,51 @@
129161 init.ops = &clk_pll_ops;
130162
131163 init.name = name;
132
- init.flags = flags;
164
+ init.flags = clks->flags;
133165
134
- init.num_parents = num_parents;
135
- init.parent_names = parent_names;
166
+ init.num_parents = clks->num_parents;
167
+ init.parent_names = NULL;
168
+ init.parent_data = clks->parent_data;
136169 pll_clk->hw.hw.init = &init;
137170
138171 pll_clk->hw.bit_idx = SOCFPGA_PLL_POWER;
139
- clk_pll_ops.enable = clk_gate_ops.enable;
140
- clk_pll_ops.disable = clk_gate_ops.disable;
172
+
173
+ clk = clk_register(NULL, &pll_clk->hw.hw);
174
+ if (WARN_ON(IS_ERR(clk))) {
175
+ kfree(pll_clk);
176
+ return NULL;
177
+ }
178
+ return clk;
179
+}
180
+
181
+struct clk *agilex_register_pll(const struct stratix10_pll_clock *clks,
182
+ void __iomem *reg)
183
+{
184
+ struct clk *clk;
185
+ struct socfpga_pll *pll_clk;
186
+ struct clk_init_data init;
187
+ const char *name = clks->name;
188
+
189
+ pll_clk = kzalloc(sizeof(*pll_clk), GFP_KERNEL);
190
+ if (WARN_ON(!pll_clk))
191
+ return NULL;
192
+
193
+ pll_clk->hw.reg = reg + clks->offset;
194
+
195
+ if (streq(name, SOCFPGA_BOOT_CLK))
196
+ init.ops = &clk_boot_ops;
197
+ else
198
+ init.ops = &agilex_clk_pll_ops;
199
+
200
+ init.name = name;
201
+ init.flags = clks->flags;
202
+
203
+ init.num_parents = clks->num_parents;
204
+ init.parent_names = NULL;
205
+ init.parent_data = clks->parent_data;
206
+ pll_clk->hw.hw.init = &init;
207
+
208
+ pll_clk->hw.bit_idx = SOCFPGA_PLL_POWER;
141209
142210 clk = clk_register(NULL, &pll_clk->hw.hw);
143211 if (WARN_ON(IS_ERR(clk))) {